GmmPartitionData implements AutoCloseable { static void estimateLikelihoodClusters(GmmPartitionData data, Vector[] initMeans) { for (int i = 0; i < data.size(); i++) { int closestClusterId = -1; double minSquaredDist = Double.MAX_VALUE; Vector x = data.getX(i); for (int c = 0; c < initMeans.length; c++) { data.setPcxi(c, i, 0.0); double distance = initMeans[c].getDistanceSquared(x); if (distance < minSquaredDist) { closestClusterId = c; minSquaredDist = distance; } } data.setPcxi(closestClusterId, i, 1.); } } 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 testEstimateLikelihoodClusters() { GmmPartitionData.estimateLikelihoodClusters(data, new Vector[] { VectorUtils.of(1.0, 0.5), VectorUtils.of(0.0, 0.5) }); assertEquals(1.0, data.pcxi(0, 0), 1e-4); assertEquals(0.0, data.pcxi(1, 0), 1e-4); assertEquals(0.0, data.pcxi(0, 1), 1e-4); assertEquals(1.0, data.pcxi(1, 1), 1e-4); assertEquals(1.0, data.pcxi(0, 2), 1e-4); assertEquals(0.0, data.pcxi(1, 2), 1e-4); }