GDBTrainer extends DatasetTrainer<ModelsComposition, Double> { public GDBTrainer withCheckConvergenceStgyFactory(ConvergenceCheckerFactory factory) { this.checkConvergenceStgyFactory = factory; return this; } GDBTrainer(double gradStepSize, Integer cntOfIterations, Loss loss); @Override ModelsComposition fitWithInitializedDeployingContext(DatasetBuilder<K, V> datasetBuilder,
                                                  Preprocessor<K, V> preprocessor); @Override boolean isUpdateable(ModelsComposition mdl); @Override GDBTrainer withEnvironmentBuilder(LearningEnvironmentBuilder envBuilder); GDBTrainer withCheckConvergenceStgyFactory(ConvergenceCheckerFactory factory);  }
@Test public void testFitRegression() { int size = 100; double[] xs = new double[size]; double[] ys = new double[size]; double from = -5.0; double to = 5.0; double step = Math.abs(from - to) / size; Map<Integer, double[]> learningSample = new HashMap<>(); for (int i = 0; i < size; i++) { xs[i] = from + step * i; ys[i] = 2 * xs[i]; learningSample.put(i, new double[] {xs[i], ys[i]}); } GDBTrainer trainer = new GDBRegressionOnTreesTrainer(1.0, 400, 3, 0.0) .withUsingIdx(true); IgniteModel<Vector, Double> mdl = trainer.fit( learningSample, 1, new DoubleArrayVectorizer<Integer>().labeled(Vectorizer.LabelCoordinate.LAST) ); double mse = 0.0; for (int j = 0; j < size; j++) { double x = xs[j]; double y = ys[j]; double p = mdl.predict(VectorUtils.of(x)); mse += Math.pow(y - p, 2); } mse /= size; assertEquals(0.0, mse, 0.0001); ModelsComposition composition = (ModelsComposition)mdl; assertTrue(!composition.toString().isEmpty()); assertTrue(!composition.toString(true).isEmpty()); assertTrue(!composition.toString(false).isEmpty()); composition.getModels().forEach(m -> assertTrue(m instanceof DecisionTreeConditionalNode)); assertEquals(400, composition.getModels().size()); assertTrue(composition.getPredictionsAggregator() instanceof WeightedPredictionsAggregator); trainer = trainer.withCheckConvergenceStgyFactory(new MeanAbsValueConvergenceCheckerFactory(0.1)); assertTrue(trainer.fit(learningSample, 1, new DoubleArrayVectorizer<Integer>().labeled(1)).getModels().size() < 2000); }
@Test public void testUpdate() { int sampleSize = 100; double[] xs = new double[sampleSize]; double[] ys = new double[sampleSize]; for (int i = 0; i < sampleSize; i++) { xs[i] = i; ys[i] = ((int)(xs[i] / 10.0) % 2) == 0 ? -1.0 : 1.0; } Map<Integer, double[]> learningSample = new HashMap<>(); for (int i = 0; i < sampleSize; i++) learningSample.put(i, new double[] {xs[i], ys[i]}); IgniteBiFunction<Integer, double[], Vector> fExtr = (k, v) -> VectorUtils.of(v[0]); IgniteBiFunction<Integer, double[], Double> lExtr = (k, v) -> v[1]; GDBTrainer classifTrainer = new GDBBinaryClassifierOnTreesTrainer(0.3, 500, 3, 0.0) .withUsingIdx(true) .withCheckConvergenceStgyFactory(new MeanAbsValueConvergenceCheckerFactory(0.3)); GDBTrainer regressTrainer = new GDBRegressionOnTreesTrainer(0.3, 500, 3, 0.0) .withUsingIdx(true) .withCheckConvergenceStgyFactory(new MeanAbsValueConvergenceCheckerFactory(0.3)); }