/** * Returns the covariance matrix of the values that have been added. * * @return the covariance matrix */ public RealMatrix getCovariance() { return covarianceImpl.getResult(); }
/** * Returns an array whose i<sup>th</sup> entry is the standard deviation of the * i<sup>th</sup> entries of the arrays that have been added using * {@link #addValue(double[])} * * @return the array of component standard deviations */ public double[] getStandardDeviation() { double[] stdDev = new double[k]; if (getN() < 1) { Arrays.fill(stdDev, Double.NaN); } else if (getN() < 2) { Arrays.fill(stdDev, 0.0); } else { RealMatrix matrix = covarianceImpl.getResult(); for (int i = 0; i < k; ++i) { stdDev[i] = FastMath.sqrt(matrix.getEntry(i, i)); } } return stdDev; }
/** * Returns the covariance matrix of the values that have been added. * * @return the covariance matrix */ public RealMatrix getCovariance() { return covarianceImpl.getResult(); }
public Gaussian fit(List<double[]> data) { k = data.get(0).length; int n = data.size(); VectorialCovariance covCounter = new VectorialCovariance(k, true); double[] sumCounter = new double[k]; for(double[] curDatum : data) { for (int i = 0; i < k; i++) { sumCounter[i] += curDatum[i]; } covCounter.increment(curDatum); } for (int i = 0; i < k; i++) { sumCounter[i] /= n; } mean = sumCounter; cov = covCounter.getResult(); initialize(); return this; }
/** * Returns an array whose i<sup>th</sup> entry is the standard deviation of the * i<sup>th</sup> entries of the arrays that have been added using * {@link #addValue(double[])} * * @return the array of component standard deviations */ public double[] getStandardDeviation() { double[] stdDev = new double[k]; if (getN() < 1) { Arrays.fill(stdDev, Double.NaN); } else if (getN() < 2) { Arrays.fill(stdDev, 0.0); } else { RealMatrix matrix = covarianceImpl.getResult(); for (int i = 0; i < k; ++i) { stdDev[i] = FastMath.sqrt(matrix.getEntry(i, i)); } } return stdDev; }