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 unusedOrOverlappingClusterTest() throws Exception {
          MacroBaseConf conf = new MacroBaseConf()
                  .set(MacroBaseConf.RANDOM_SEED, 4)
                  .set(MacroBaseConf.TRANSFORM_TYPE, "MEAN_FIELD_GMM")
                  .set(GMMConf.NUM_MIXTURES, 4)
                  .set(MacroBaseConf.DATA_LOADER_TYPE, "CSV_LOADER")
                  .set(MacroBaseConf.CSV_COMPRESSION, CSVIngester.Compression.GZIP)
                  .set(MacroBaseConf.CSV_INPUT_FILE, "src/test/resources/data/2gaussians-500points.csv.gz")
                  .set(MacroBaseConf.METRICS, "XX, YY")
                  .set(MacroBaseConf.ATTRIBUTES, "");
          List<Datum> data = Drainer.drainIngest(conf);
          assertEquals(500, data.size());
  
          FiniteGMM finiteGMM = new FiniteGMM(conf);
          List<RealVector> calculatedMeans = null;
          double[] calculatedWeights = null;
  
          int numClustersIdentified = 0;
          // Sometimes there is a weird convergence into one cluster when trying to fit more than 2 clusters.
          while (numClustersIdentified < 2) {
              finiteGMM.train(data);
  
              calculatedMeans = finiteGMM.getClusterCenters();
              calculatedWeights = finiteGMM.getPriorAdjustedClusterProportions();
  
              numClustersIdentified = 0;
              for (double weight : calculatedWeights) {
                  if (weight > 0.1) {
                      numClustersIdentified += 1;
                  }
              }
          }
  
          double[][] clusterMeans = {
                  {1, 1},
                  {10, 3},
          };
          List<RealVector> vectorClusterMeans = new ArrayList<>(2);
          for (int k = 0; k < 2; k++) {
              vectorClusterMeans.add(new ArrayRealVector(clusterMeans[k]));
          }
  
          double[] clusterWeights = {
                  200,
                  300,
          };
          double[] identifiedWeights = {0, 0};
          for (int i = 0; i < 4; i++) {
              for (int j = 0; j < 2; j++) {
                  if (calculatedMeans.get(i).getDistance(vectorClusterMeans.get(j)) < 1) {
                      identifiedWeights[j] += calculatedWeights[i];
                      log.debug("adding {} to cluster {}", calculatedWeights[i], vectorClusterMeans.get(j));
                      break;
                  }
              }
          }
          assertEquals(identifiedWeights[0] * 500, clusterWeights[0], 1);
          assertEquals(identifiedWeights[1] * 500, clusterWeights[1], 1);
      }
test_case.class_method_signature: FiniteGMMTest.unusedOrOverlappingClusterTest()
test_case.full_signature: @Test /** * Tests Gaussian Mixture Model on a three not so well separated clusters. */ public void unusedOrOverlappingClusterTest()
test_case.identifier: unusedOrOverlappingClusterTest
test_case.invocations: set set set set set set set set drainIngest assertEquals size train getClusterCenters getPriorAdjustedClusterProportions add getDistance get get debug get assertEquals assertEquals
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 unusedOrOverlappingClusterTest()
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()