public static double[] getDirection(List<double[]> supports, List<Double> weights) { Vector ret = null; for (int i = 0; i < supports.size(); i++) { double[] sup = supports.get(i); double weight = weights.get(i); DenseVector scale = new DenseVector(sup).scale(weight); if(ret == null){ ret = scale; } else{ ret.add(scale); } } double[] retdata = new DenseVector(ret).getData(); return retdata; }
/** * Generates the estimator based on the given observations and weight vector. * Equal weights are assumed if the weight vector is null. */ @Override public void estimate(double[][] observations, double[] weights) { if (weights == null) { weights = new double[observations.length]; for (int i = 0; i < weights.length; i++) { weights[i] = 1.0; } } DenseVector weightVector = new DenseVector(weights); weightVector = weightVector.scale(1.0 / weightVector.norm(Vector.Norm.One)); mean = weightedMean(observations, weightVector); Matrix cov = weightedCovariance(observations, weightVector, mean); // Compute inverse of covariance matrix DenseCholesky chol = new DenseCholesky(observations[0].length, true).factor((UpperSPDDenseMatrix)cov); covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(observations[0].length))); double logDeterminant = 0; for (int i = 0; i < observations[0].length; i++) { logDeterminant += Math.log(chol.getU().get(i, i)); } logDeterminant *= 2; lnconstant = -(Log2PI * observations[0].length + logDeterminant) * 0.5; }
/** * Generates the estimator based on the given observations and weight vector. * Equal weights are assumed if the weight vector is null. */ @Override public void estimate(double[][] observations, double[] weights) { if (weights == null) { weights = new double[observations.length]; for (int i = 0; i < weights.length; i++) { weights[i] = 1.0; } } DenseVector weightVector = new DenseVector(weights); weightVector = weightVector.scale(1.0 / weightVector.norm(Vector.Norm.One)); mean = weightedMean(observations, weightVector); Matrix cov = weightedCovariance(observations, weightVector, mean); // Compute inverse of covariance matrix DenseCholesky chol = new DenseCholesky(observations[0].length, true).factor((UpperSPDDenseMatrix)cov); covarianceInverse = new UpperSPDDenseMatrix(chol.solve(Matrices.identity(observations[0].length))); double logDeterminant = 0; for (int i = 0; i < observations[0].length; i++) { logDeterminant += Math.log(chol.getU().get(i, i)); } logDeterminant *= 2; lnconstant = -(Log2PI * observations[0].length + logDeterminant) * 0.5; }
if (observations[i].length > 0) { DenseVector weightVector = new DenseVector(weights[i]); weightVector = weightVector.scale(1.0 / weightVector.norm(Vector.Norm.One)); groupMean[i] = weightedMean(observations[i], weightVector); groupCovariance[i] = weightedCovariance(observations[i], weightVector, groupMean[i]);
if (observations[i].length > 0) { DenseVector weightVector = new DenseVector(weights[i]); weightVector = weightVector.scale(1.0 / weightVector.norm(Vector.Norm.One)); groupMean[i] = weightedMean(observations[i], weightVector); groupCovariance[i] = weightedCovariance(observations[i], weightVector, groupMean[i]);