The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



ClassScatterMatrices


Unit: SDL_math2
Class: none
Declaration: function ClassScatterMatrices ((InData: TDouble2DArray; ClassVec: TIntArray; var NClasses: integer; var ClCnt: TIntArray; var ClMeans, ClVars, SBetwCl, SWithinCl: TDouble2DArray): integer;

The function ClassScatterMatrices calculates the between-class and within-class scatter matrices. The parameter InData contains the data to be analyzed (rows are objects, columns are variables) and the parameter ClassVec contains the corresponding class numbers.

On return, the variable parameter NClasses contains the number of found classes. The variable arrays ClCnt, ClMeans and ClVars contain the number of members of each class, the class means and the class variances, respectively. The first index of the arrays ClMeans and ClVars designates the corresponding variable, the second index addresses the class number (zero-based indices!). For example, the element ClVars[3,0] contains the variance of the fourth variable for the first class.

The between-class and within-class scatter matrices are returned in the variable parameters SBetwCl and SWithinCl.

The scatter matrices Sb and Sw are calculated according to the following equations. Please note that the scatter matrices are not scaled to the number of data points (which is sometimes the case in other implementations):


with
C ... number of classes
Nc ... number of data points per class
m ... overall mean
mc ... mean of the class c
xn ... data points
sc ... first index of the class c (assuming the dataset is ordered according to the class numbers)
tc ... last index of the class c

The function returns the following error codes:

 0 ... everything is OK
-1 ... lengths of InData and ClassVec do not match
-2 ... the class vector contains invalid class numbers
-3 ... the class vector does not contain contiguous class numbers (from 1 to NClasses)


Last Update: 2023-Feb-06