GmmPartitionData implements AutoCloseable { static double updatePcxi(GmmPartitionData data, Vector clusterProbs, List<MultivariateGaussianDistribution> components) { GmmModel model = new GmmModel(clusterProbs, components); double maxProb = Double.NEGATIVE_INFINITY; for (int i = 0; i < data.size(); i++) { Vector x = data.getX(i); double xProb = model.prob(x); if (xProb > maxProb) maxProb = xProb; double normalizer = 0.0; for (int c = 0; c < clusterProbs.size(); c++) normalizer += components.get(c).prob(x) * clusterProbs.get(c); for (int c = 0; c < clusterProbs.size(); c++) data.pcxi[i][c] = (components.get(c).prob(x) * clusterProbs.get(c)) / normalizer; } return maxProb; } GmmPartitionData(List<LabeledVector<Double>> xs, double[][] pcxi); Vector getX(int i); double pcxi(int cluster, int i); void setPcxi(int cluster, int i, double value); List<LabeledVector<Double>> getAllXs(); @Override void close(); int size();  }
@Test public void testUpdatePcxi() { GmmPartitionData.updatePcxi( data, VectorUtils.of(0.3, 0.7), Arrays.asList( new MultivariateGaussianDistribution(VectorUtils.of(1.0, 0.5), new DenseMatrix(new double[] {0.5, 0., 0., 1.}, 2)), new MultivariateGaussianDistribution(VectorUtils.of(0.0, 0.5), new DenseMatrix(new double[] {1.0, 0., 0., 1.}, 2)) ) ); assertEquals(0.49, data.pcxi(0, 0), 1e-2); assertEquals(0.50, data.pcxi(1, 0), 1e-2); assertEquals(0.18, data.pcxi(0, 1), 1e-2); assertEquals(0.81, data.pcxi(1, 1), 1e-2); assertEquals(0.49, data.pcxi(0, 2), 1e-2); assertEquals(0.50, data.pcxi(1, 2), 1e-2); }