test_class.declarator: PRECISION = 1e-2
test_class.modifier: private static final
test_class.original_string: private static final double PRECISION = 1e-2;
test_class.type: double
test_class.var_name: PRECISION
test_class.declarator: LABEL_1 = 1.
test_class.modifier: private static final
test_class.original_string: private static final double LABEL_1 = 1.;
test_class.type: double
test_class.var_name: LABEL_1
test_class.declarator: LABEL_2 = 2.
test_class.modifier: private static final
test_class.original_string: private static final double LABEL_2 = 2.;
test_class.type: double
test_class.var_name: LABEL_2
test_class.declarator: data = new HashMap<>()
test_class.modifier: private static final
test_class.original_string: private static final Map<Integer, double[]> data = new HashMap<>();
test_class.type: Map<Integer, double[]>
test_class.var_name: data
test_class.declarator: singleLabeldata1 = new HashMap<>()
test_class.modifier: private static final
test_class.original_string: private static final Map<Integer, double[]> singleLabeldata1 = new HashMap<>();
test_class.type: Map<Integer, double[]>
test_class.var_name: singleLabeldata1
test_class.declarator: singleLabeldata2 = new HashMap<>()
test_class.modifier: private static final
test_class.original_string: private static final Map<Integer, double[]> singleLabeldata2 = new HashMap<>();
test_class.type: Map<Integer, double[]>
test_class.var_name: singleLabeldata2
test_class.declarator: trainer
test_class.modifier: private
test_class.original_string: private GaussianNaiveBayesTrainer trainer;
test_class.type: GaussianNaiveBayesTrainer
test_class.var_name: trainer
test_class.file: modules/ml/src/test/java/org/apache/ignite/ml/naivebayes/gaussian/GaussianNaiveBayesTrainerTest.java
test_class.identifier: GaussianNaiveBayesTrainerTest
test_class.superclass: extends TrainerTest
test_case.body: @Test
      public void testUpdatigModel() {
          Vectorizer<Integer, double[], Integer, Double> vectorizer = new DoubleArrayVectorizer<Integer>().labeled(Vectorizer.LabelCoordinate.LAST);
          GaussianNaiveBayesModel model = trainer.fit(
              new LocalDatasetBuilder<>(singleLabeldata1, parts),
              vectorizer
          );
  
          GaussianNaiveBayesModel updatedModel = trainer.updateModel(model,
              new LocalDatasetBuilder<>(singleLabeldata2, parts),
              vectorizer
          );
  
          Assert.assertEquals(3. / data.size(), updatedModel.getClassProbabilities()[0], PRECISION);
          Assert.assertEquals(2. / data.size(), updatedModel.getClassProbabilities()[1], PRECISION);
      }
test_case.class_method_signature: GaussianNaiveBayesTrainerTest.testUpdatigModel()
test_case.full_signature: @Test public void testUpdatigModel()
test_case.identifier: testUpdatigModel
test_case.invocations: labeled fit updateModel assertEquals size getClassProbabilities assertEquals size getClassProbabilities
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testUpdatigModel()
focal_class.declarator: priorProbabilities
focal_class.modifier: private
focal_class.original_string: private double[] priorProbabilities;
focal_class.type: double[]
focal_class.var_name: priorProbabilities
focal_class.declarator: equiprobableClasses
focal_class.modifier: private
focal_class.original_string: private boolean equiprobableClasses;
focal_class.type: boolean
focal_class.var_name: equiprobableClasses
focal_class.file: modules/ml/src/main/java/org/apache/ignite/ml/naivebayes/gaussian/GaussianNaiveBayesTrainer.java
focal_class.identifier: GaussianNaiveBayesTrainer
focal_class.class_method_signature: GaussianNaiveBayesTrainer.fitWithInitializedDeployingContext(DatasetBuilder<K, V> datasetBuilder,
                                                          Preprocessor<K, V> extractor)
focal_class.full_signature: @Override public GaussianNaiveBayesModel fitWithInitializedDeployingContext(DatasetBuilder<K, V> datasetBuilder,
                                                          Preprocessor<K, V> extractor)
focal_class.identifier: fitWithInitializedDeployingContext
focal_class.modifiers: @Override public
focal_class.parameters: (DatasetBuilder<K, V> datasetBuilder,
                                                          Preprocessor<K, V> extractor)
focal_class.return: GaussianNaiveBayesModel
focal_class.signature: GaussianNaiveBayesModel fitWithInitializedDeployingContext(DatasetBuilder<K, V> datasetBuilder,
                                                          Preprocessor<K, V> extractor)
focal_class.class_method_signature: GaussianNaiveBayesTrainer.isUpdateable(GaussianNaiveBayesModel mdl)
focal_class.full_signature: @Override public boolean isUpdateable(GaussianNaiveBayesModel mdl)
focal_class.identifier: isUpdateable
focal_class.modifiers: @Override public
focal_class.parameters: (GaussianNaiveBayesModel mdl)
focal_class.return: boolean
focal_class.signature: boolean isUpdateable(GaussianNaiveBayesModel mdl)
focal_class.class_method_signature: GaussianNaiveBayesTrainer.withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder)
focal_class.full_signature: @Override public GaussianNaiveBayesTrainer withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder)
focal_class.identifier: withEnvironmentBuilder
focal_class.modifiers: @Override public
focal_class.parameters: (LearningEnvironmentBuilder envBuilder)
focal_class.return: GaussianNaiveBayesTrainer
focal_class.signature: GaussianNaiveBayesTrainer withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder)
focal_class.class_method_signature: GaussianNaiveBayesTrainer.updateModel(GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)
focal_class.full_signature: @Override protected GaussianNaiveBayesModel updateModel(GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)
focal_class.identifier: updateModel
focal_class.modifiers: @Override protected
focal_class.parameters: (GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)
focal_class.return: GaussianNaiveBayesModel
focal_class.signature: GaussianNaiveBayesModel updateModel(GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)
focal_class.class_method_signature: GaussianNaiveBayesTrainer.withEquiprobableClasses()
focal_class.full_signature: public GaussianNaiveBayesTrainer withEquiprobableClasses()
focal_class.identifier: withEquiprobableClasses
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: GaussianNaiveBayesTrainer
focal_class.signature: GaussianNaiveBayesTrainer withEquiprobableClasses()
focal_class.class_method_signature: GaussianNaiveBayesTrainer.setPriorProbabilities(double[] priorProbabilities)
focal_class.full_signature: public GaussianNaiveBayesTrainer setPriorProbabilities(double[] priorProbabilities)
focal_class.identifier: setPriorProbabilities
focal_class.modifiers: public
focal_class.parameters: (double[] priorProbabilities)
focal_class.return: GaussianNaiveBayesTrainer
focal_class.signature: GaussianNaiveBayesTrainer setPriorProbabilities(double[] priorProbabilities)
focal_class.class_method_signature: GaussianNaiveBayesTrainer.resetSettings()
focal_class.full_signature: public GaussianNaiveBayesTrainer resetSettings()
focal_class.identifier: resetSettings
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: GaussianNaiveBayesTrainer
focal_class.signature: GaussianNaiveBayesTrainer resetSettings()
focal_class.superclass: extends SingleLabelDatasetTrainer<GaussianNaiveBayesModel>
focal_method.body: @Override protected <K, V> GaussianNaiveBayesModel updateModel(GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor) {
          assert datasetBuilder != null;
  
          try (Dataset<EmptyContext, GaussianNaiveBayesSumsHolder> dataset = datasetBuilder.build(
              envBuilder,
              (env, upstream, upstreamSize) -> new EmptyContext(),
              (env, upstream, upstreamSize, ctx) -> {
  
                  GaussianNaiveBayesSumsHolder res = new GaussianNaiveBayesSumsHolder();
                  while (upstream.hasNext()) {
                      UpstreamEntry<K, V> entity = upstream.next();
  
                      LabeledVector lv = extractor.apply(entity.getKey(), entity.getValue());
                      Vector features = lv.features();
                      Double label = (Double) lv.label();
  
                      double[] toMeans;
                      double[] sqSum;
  
                      if (!res.featureSumsPerLbl.containsKey(label)) {
                          toMeans = new double[features.size()];
                          Arrays.fill(toMeans, 0.);
                          res.featureSumsPerLbl.put(label, toMeans);
                      }
                      if (!res.featureSquaredSumsPerLbl.containsKey(label)) {
                          sqSum = new double[features.size()];
                          res.featureSquaredSumsPerLbl.put(label, sqSum);
                      }
                      if (!res.featureCountersPerLbl.containsKey(label))
                          res.featureCountersPerLbl.put(label, 0);
  
                      res.featureCountersPerLbl.put(label, res.featureCountersPerLbl.get(label) + 1);
  
                      toMeans = res.featureSumsPerLbl.get(label);
                      sqSum = res.featureSquaredSumsPerLbl.get(label);
                      for (int j = 0; j < features.size(); j++) {
                          double x = features.get(j);
                          toMeans[j] += x;
                          sqSum[j] += x * x;
                      }
                  }
                  return res;
              }, learningEnvironment()
          )) {
              GaussianNaiveBayesSumsHolder sumsHolder = dataset.compute(t -> t, (a, b) -> {
                  if (a == null)
                      return b == null ? new GaussianNaiveBayesSumsHolder() : b;
                  if (b == null)
                      return a;
                  return a.merge(b);
              });
              if (mdl != null && mdl.getSumsHolder() != null)
                  sumsHolder = sumsHolder.merge(mdl.getSumsHolder());
  
              List<Double> sortedLabels = new ArrayList<>(sumsHolder.featureCountersPerLbl.keySet());
              sortedLabels.sort(Double::compareTo);
              assert !sortedLabels.isEmpty() : "The dataset should contain at least one feature";
  
              int labelCount = sortedLabels.size();
              int featureCount = sumsHolder.featureSumsPerLbl.get(sortedLabels.get(0)).length;
  
              double[][] means = new double[labelCount][featureCount];
              double[][] variances = new double[labelCount][featureCount];
              double[] classProbabilities = new double[labelCount];
              double[] labels = new double[labelCount];
  
              long datasetSize = sumsHolder.featureCountersPerLbl.values().stream().mapToInt(i -> i).sum();
  
              int lbl = 0;
              for (Double label : sortedLabels) {
                  int count = sumsHolder.featureCountersPerLbl.get(label);
                  double[] sum = sumsHolder.featureSumsPerLbl.get(label);
                  double[] sqSum = sumsHolder.featureSquaredSumsPerLbl.get(label);
  
                  for (int i = 0; i < featureCount; i++) {
                      means[lbl][i] = sum[i] / count;
                      variances[lbl][i] = (sqSum[i] - sum[i] * sum[i] / count) / count;
                  }
  
                  if (equiprobableClasses)
                      classProbabilities[lbl] = 1. / labelCount;
  
                  else if (priorProbabilities != null) {
                      assert classProbabilities.length == priorProbabilities.length;
                      classProbabilities[lbl] = priorProbabilities[lbl];
                  }
                  else
                      classProbabilities[lbl] = (double)count / datasetSize;
  
                  labels[lbl] = label;
                  ++lbl;
              }
  
              return new GaussianNaiveBayesModel(means, variances, classProbabilities, labels, sumsHolder);
          }
          catch (Exception e) {
              throw new RuntimeException(e);
          }
  
      }
focal_method.class_method_signature: GaussianNaiveBayesTrainer.updateModel(GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)
focal_method.full_signature: @Override protected GaussianNaiveBayesModel updateModel(GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)
focal_method.identifier: updateModel
focal_method.invocations: build hasNext next apply getKey getValue features label containsKey size fill put containsKey size put containsKey put put get get get size get learningEnvironment compute merge getSumsHolder merge getSumsHolder keySet sort isEmpty size get get sum mapToInt stream values get get get
focal_method.modifiers: @Override protected
focal_method.parameters: (GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)
focal_method.return: GaussianNaiveBayesModel
focal_method.signature: GaussianNaiveBayesModel updateModel(GaussianNaiveBayesModel mdl,
                                                                     DatasetBuilder<K, V> datasetBuilder, Preprocessor<K, V> extractor)