public static void covarianceMatrix(Vec mean,DataSet dataSet,Matrix covariance){
  double sumOfWeights=0.0, sumOfSquaredWeights=0.0;
  for (int i=0; i < dataSet.getSampleSize(); i++) {
    DataPoint dp=dataSet.getDataPoint(i);
    sumOfWeights+=dp.getWeight();
    sumOfSquaredWeights+=Math.pow(dp.getWeight(),2);
  }
  covarianceMatrix(mean,dataSet,covariance,sumOfWeights,sumOfSquaredWeights);
}

public static void covarianceMatrix ( Vec mean , DataSet dataSet , Matrix covariance ) { double sumOfWeights = 0.0 , sumOfSquaredWeights = 0.0 ; for ( int i = 0 ; i < dataSet . getSampleSize ( ) ; i ++ ) { DataPoint dp = dataSet . getDataPoint ( i ) ; sumOfWeights += dp . getWeight ( ) ; sumOfSquaredWeights += Math . pow ( dp . getWeight ( ) , 2 ) ; } covarianceMatrix ( mean , dataSet , covariance , sumOfWeights , sumOfSquaredWeights ) ; }
computes the weighted covariance matrix of the given data set .
