public double [ ] getVariances ( ) { double N = this . size ( ) ; double [ ] LS = new double [ this . getNrOfDimensions ( ) ] ; double [ ] SS = new double [ this . getNrOfDimensions ( ) ] ; double [ ] tmpFeatures ; double [ ] variances = new double [ this . getNrOfDimensions ( ) ] ; for ( DataObject dataObject : dataList ) { tmpFeatures = dataObject . getFeatures ( ) ; for ( int j = 0 ; j < tmpFeatures . length ; j ++ ) { LS [ j ] += tmpFeatures [ j ] ; SS [ j ] += tmpFeatures [ j ] * tmpFeatures [ j ] ; } } // sigmaSquared[i] = (SS[i] / N) - ((LS[i] * LS [i]) / (N * N)); for ( int i = 0 ; i < LS . length ; i ++ ) { variances [ i ] = ( SS [ i ] / N - ( ( LS [ i ] / N ) * ( LS [ i ] / N ) ) ) ; } return variances ; }
Calculates the variance of this data set for each dimension