test_class.declarator: log = LoggerFactory.getLogger(FiniteGMMTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger log = LoggerFactory.getLogger(FiniteGMMTest.class);
test_class.type: Logger
test_class.var_name: log
test_class.file: contrib/src/test/java/macrobase/analysis/stats/mixture/FiniteGMMTest.java
test_class.identifier: FiniteGMMTest
test_case.body: @Test
      /**
       * Tests Gaussian Mixture Model on a three not so well separated clusters.
       */
      public void bivariateOkSeparatedNormalTest() throws Exception {
          MacroBaseConf conf = new MacroBaseConf()
                  .set(MacroBaseConf.RANDOM_SEED, 4)
                  .set(MacroBaseConf.TRANSFORM_TYPE, "MEAN_FIELD_GMM")
                  .set(GMMConf.NUM_MIXTURES, 3)
                  .set(MacroBaseConf.DATA_LOADER_TYPE, "CSV_LOADER")
                  .set(MacroBaseConf.CSV_COMPRESSION, CSVIngester.Compression.GZIP)
                  .set(MacroBaseConf.CSV_INPUT_FILE, "src/test/resources/data/3gaussians-7000points.csv.gz")
                  .set(MacroBaseConf.METRICS, "XX, YY")
                  .set(MacroBaseConf.ATTRIBUTES, "");
          List<Datum> data = Drainer.drainIngest(conf);
          assertEquals(7000, data.size());
  
          double[][] clusterMeans = {
                  {1.5, 2},
                  {2, 0},
                  {4.5, 1},
          };
          List<RealVector> vectorClusterMeans = new ArrayList<>(3);
          for (int k = 0; k < 3; k++) {
              vectorClusterMeans.add(new ArrayRealVector(clusterMeans[k]));
          }
          double[][][] clusterCovariances = {
                  {{0.5, 0.4}, {0.4, 0.5}},
                  {{0.3, 0}, {0, 0.6}},
                  {{0.9, 0.2}, {0.2, 0.3}},
          };
  
          FiniteGMM finiteGMM = new FiniteGMM(conf);
          finiteGMM.train(data);
  
          List<RealVector> calculatedMeans = finiteGMM.getClusterCenters();
          List<RealMatrix> calculatedCovariances = finiteGMM.getClusterCovariances();
  
          for (int i = 0; i < 3; i++) {
              boolean identified = false;
              for (int j = 0; j < 3; j++) {
                  if (calculatedMeans.get(i).getDistance(vectorClusterMeans.get(j)) < 0.1) {
                      for (int p = 0; p < 2; p++) {
                          for (int q = 0; q < 2; q++) {
                              assertEquals(clusterCovariances[j][p][q], calculatedCovariances.get(i).getEntry(p, q), 0.1);
                          }
                      }
                      identified = true;
                      break;
                  }
              }
              assertEquals("a cluster was not identified", true, identified);
          }
  
          double[][] boundaries = {
                  {0, 6.01},
                  {-2, 4.01},
          };
          List<Datum> scoredData = DiagnosticsUtils.createGridFixedIncrement(boundaries, 0.05);
  
          JsonUtils.dumpAsJson(finiteGMM.getClusterCovariances(), "FiniteGMMTest-bivariateOkSeparatedNormalTest-covariances.json");
          JsonUtils.dumpAsJson(finiteGMM.getClusterCenters(), "FiniteGMMTest-bivariateOkSeparatedNormalTest-means.json");
          JsonUtils.dumpAsJson(finiteGMM.getPriorAdjustedClusterProportions(), "FiniteGMMTest-bivariateOkSeparatedNormalTest-weights.json");
  
          conf.set(GMMConf.SCORE_DUMP_FILE_CONFIG_PARAM, "3gaussians-7k-grid.json");
          ScoreDumper dumper = new ScoreDumper(conf);
          dumper.dumpScores(finiteGMM, scoredData);
  
          conf.set(GMMConf.SCORE_DUMP_FILE_CONFIG_PARAM, "3gaussians-7k-data.json");
          dumper = new ScoreDumper(conf);
          dumper.dumpScores(finiteGMM, data);
      }
test_case.class_method_signature: FiniteGMMTest.bivariateOkSeparatedNormalTest()
test_case.full_signature: @Test /** * Tests Gaussian Mixture Model on a three not so well separated clusters. */ public void bivariateOkSeparatedNormalTest()
test_case.identifier: bivariateOkSeparatedNormalTest
test_case.invocations: set set set set set set set set drainIngest assertEquals size add train getClusterCenters getClusterCovariances getDistance get get assertEquals getEntry get assertEquals createGridFixedIncrement dumpAsJson getClusterCovariances dumpAsJson getClusterCenters dumpAsJson getPriorAdjustedClusterProportions set dumpScores set dumpScores
test_case.modifiers: @Test /** * Tests Gaussian Mixture Model on a three not so well separated clusters. */ public
test_case.parameters: ()
test_case.return: void
test_case.signature: void bivariateOkSeparatedNormalTest()
focal_class.declarator: log = LoggerFactory.getLogger(FiniteGMM.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(FiniteGMM.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: K
focal_class.modifier: protected
focal_class.original_string: protected int K;
focal_class.type: int
focal_class.var_name: K
focal_class.declarator: mixingComponents
focal_class.modifier: protected
focal_class.original_string: protected MultiComponents mixingComponents;
focal_class.type: MultiComponents
focal_class.var_name: mixingComponents
focal_class.file: contrib/src/main/java/macrobase/analysis/stats/mixture/FiniteGMM.java
focal_class.identifier: FiniteGMM
focal_class.class_method_signature: FiniteGMM.FiniteGMM(MacroBaseConf conf)
focal_class.full_signature: public  FiniteGMM(MacroBaseConf conf)
focal_class.identifier: FiniteGMM
focal_class.modifiers: public
focal_class.parameters: (MacroBaseConf conf)
focal_class.signature:  FiniteGMM(MacroBaseConf conf)
focal_class.class_method_signature: FiniteGMM.trainTest(List<Datum> trainData, List<Datum> testData)
focal_class.full_signature: @Override public void trainTest(List<Datum> trainData, List<Datum> testData)
focal_class.identifier: trainTest
focal_class.modifiers: @Override public
focal_class.parameters: (List<Datum> trainData, List<Datum> testData)
focal_class.return: void
focal_class.signature: void trainTest(List<Datum> trainData, List<Datum> testData)
focal_class.class_method_signature: FiniteGMM.getClusterProportions()
focal_class.full_signature: @Override public double[] getClusterProportions()
focal_class.identifier: getClusterProportions
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: double[]
focal_class.signature: double[] getClusterProportions()
focal_class.class_method_signature: FiniteGMM.getNormClusterContrib()
focal_class.full_signature: @Override protected double[] getNormClusterContrib()
focal_class.identifier: getNormClusterContrib
focal_class.modifiers: @Override protected
focal_class.parameters: ()
focal_class.return: double[]
focal_class.signature: double[] getNormClusterContrib()
focal_class.class_method_signature: FiniteGMM.getPriorAdjustedClusterProportions()
focal_class.full_signature: public double[] getPriorAdjustedClusterProportions()
focal_class.identifier: getPriorAdjustedClusterProportions
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: double[]
focal_class.signature: double[] getPriorAdjustedClusterProportions()
focal_class.class_method_signature: FiniteGMM.getClusterProbabilities(Datum d)
focal_class.full_signature: @Override public double[] getClusterProbabilities(Datum d)
focal_class.identifier: getClusterProbabilities
focal_class.modifiers: @Override public
focal_class.parameters: (Datum d)
focal_class.return: double[]
focal_class.signature: double[] getClusterProbabilities(Datum d)
focal_class.superclass: extends VarGMM
focal_method.body: public double[] getPriorAdjustedClusterProportions() {
          double[] mixingCoeffs = mixingComponents.getCoeffs();
          double sum = - mixingComponents.getPrior(); // to adjust for prior.
          for (double coeff : mixingCoeffs) {
              sum += coeff;
          }
          double[] proportions = new double[K];
          for (int i=0; i<K; i++) {
              proportions[i] = (mixingCoeffs[i] - mixingComponents.getPrior()) / sum;
          }
          return proportions;
      }
focal_method.class_method_signature: FiniteGMM.getPriorAdjustedClusterProportions()
focal_method.full_signature: public double[] getPriorAdjustedClusterProportions()
focal_method.identifier: getPriorAdjustedClusterProportions
focal_method.invocations: getCoeffs getPrior getPrior
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: double[]
focal_method.signature: double[] getPriorAdjustedClusterProportions()