IGNITE-8981: [ML] Parallel optimizations for BaggingTrainer
authorAlexey Platonov <aplatonovv@gmail.com>
Tue, 24 Jul 2018 12:45:09 +0000 (15:45 +0300)
committerYury Babak <ybabak@gridgain.com>
Tue, 24 Jul 2018 12:45:10 +0000 (15:45 +0300)
this closes #4350

173 files changed:
examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackGAExample.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/knapsack/KnapsackTerminateCriteria.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java
examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java
examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNClassificationExample.java
examples/src/main/java/org/apache/ignite/examples/ml/knn/KNNRegressionExample.java
examples/src/main/java/org/apache/ignite/examples/ml/nn/MLPTrainerExample.java
examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/BinarizationExample.java
examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/ImputingExample.java
examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/ImputingExampleWithMostFrequentValues.java
examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/MinMaxScalerExample.java
examples/src/main/java/org/apache/ignite/examples/ml/preprocessing/NormalizationExample.java
examples/src/main/java/org/apache/ignite/examples/ml/regression/linear/LinearRegressionLSQRTrainerWithMinMaxScalerExample.java
examples/src/main/java/org/apache/ignite/examples/ml/regression/logistic/multiclass/LogRegressionMultiClassClassificationExample.java
examples/src/main/java/org/apache/ignite/examples/ml/svm/multiclass/SVMMultiClassClassificationExample.java
examples/src/main/java/org/apache/ignite/examples/ml/tree/randomforest/RandomForestRegressionExample.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_1_Read_and_Learn.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_2_Imputing.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_3_Categorial.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_4_Add_age_fare.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_5_Scaling.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_6_KNN.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_7_Split_train_test.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_8_CV.java
examples/src/main/java/org/apache/ignite/examples/ml/tutorial/Step_9_Go_to_LogReg.java
modules/ml/src/main/java/org/apache/ignite/ml/Model.java
modules/ml/src/main/java/org/apache/ignite/ml/clustering/kmeans/KMeansModel.java
modules/ml/src/main/java/org/apache/ignite/ml/clustering/kmeans/KMeansModelFormat.java
modules/ml/src/main/java/org/apache/ignite/ml/clustering/kmeans/KMeansTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/BaggingModelTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/ModelOnFeaturesSubspace.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/ModelsComposition.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/boosting/GDBBinaryClassifierTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/boosting/GDBRegressionTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/boosting/GDBTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/predictionsaggregator/PredictionsAggregator.java
modules/ml/src/main/java/org/apache/ignite/ml/composition/predictionsaggregator/WeightedPredictionsAggregator.java
modules/ml/src/main/java/org/apache/ignite/ml/dataset/DatasetFactory.java
modules/ml/src/main/java/org/apache/ignite/ml/dataset/primitive/builder/data/SimpleDatasetDataBuilder.java
modules/ml/src/main/java/org/apache/ignite/ml/dataset/primitive/builder/data/SimpleLabeledDatasetDataBuilder.java
modules/ml/src/main/java/org/apache/ignite/ml/environment/LearningEnvironment.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/LearningEnvironmentBuilder.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/ConsoleLogger.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/CustomMLLogger.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/MLLogger.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/NoOpLogger.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/package-info.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/package-info.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/DefaultParallelismStrategy.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/NoParallelismStrategy.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/ParallelismStrategy.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/Promise.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/package-info.java [new file with mode: 0644]
modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverJob.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverTask.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessJob.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessTask.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/GAGrid.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/Gene.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/MutateTask.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/TruncateSelectionJob.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/TruncateSelectionTask.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/functions/GAGridFunction.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/parameter/GAConfiguration.java
modules/ml/src/main/java/org/apache/ignite/ml/genetic/utils/GAGridUtils.java
modules/ml/src/main/java/org/apache/ignite/ml/knn/KNNUtils.java
modules/ml/src/main/java/org/apache/ignite/ml/knn/classification/KNNClassificationModel.java
modules/ml/src/main/java/org/apache/ignite/ml/knn/classification/KNNClassificationTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/knn/regression/KNNRegressionModel.java
modules/ml/src/main/java/org/apache/ignite/ml/knn/regression/KNNRegressionTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java
modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
modules/ml/src/main/java/org/apache/ignite/ml/math/distances/DistanceMeasure.java
modules/ml/src/main/java/org/apache/ignite/ml/math/distances/EuclideanDistance.java
modules/ml/src/main/java/org/apache/ignite/ml/math/distances/HammingDistance.java
modules/ml/src/main/java/org/apache/ignite/ml/math/distances/ManhattanDistance.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/matrix/AbstractMatrix.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/matrix/impl/DenseMatrix.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/matrix/impl/SparseMatrix.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/matrix/impl/ViewMatrix.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/matrix/storage/DenseMatrixStorage.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/matrix/storage/SparseMatrixStorage.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/AbstractVector.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/Vector.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/impl/DelegatingVector.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/impl/DenseVector.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/impl/SparseVector.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/impl/VectorView.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/impl/VectorizedViewMatrix.java
modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/storage/VectorizedViewMatrixStorage.java
modules/ml/src/main/java/org/apache/ignite/ml/math/util/MatrixUtil.java
modules/ml/src/main/java/org/apache/ignite/ml/nn/MLPTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/nn/MultilayerPerceptron.java
modules/ml/src/main/java/org/apache/ignite/ml/nn/ReplicatedVectorMatrix.java
modules/ml/src/main/java/org/apache/ignite/ml/optimization/LossFunctions.java
modules/ml/src/main/java/org/apache/ignite/ml/optimization/SmoothParametrized.java
modules/ml/src/main/java/org/apache/ignite/ml/optimization/updatecalculators/NesterovUpdateCalculator.java
modules/ml/src/main/java/org/apache/ignite/ml/optimization/updatecalculators/ParameterUpdateCalculator.java
modules/ml/src/main/java/org/apache/ignite/ml/optimization/updatecalculators/RPropUpdateCalculator.java
modules/ml/src/main/java/org/apache/ignite/ml/optimization/updatecalculators/SimpleGDUpdateCalculator.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/binarization/BinarizationPreprocessor.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/binarization/BinarizationTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/encoding/stringencoder/StringEncoderPreprocessor.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/encoding/stringencoder/StringEncoderTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/imputing/ImputerPreprocessor.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/imputing/ImputerTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/minmaxscaling/MinMaxScalerPreprocessor.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/minmaxscaling/MinMaxScalerTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/normalization/NormalizationPreprocessor.java
modules/ml/src/main/java/org/apache/ignite/ml/preprocessing/normalization/NormalizationTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/linear/FeatureExtractorWrapper.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/linear/LinearRegressionLSQRTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/linear/LinearRegressionModel.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/linear/LinearRegressionSGDTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/logistic/binomial/LogisticRegressionModel.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/logistic/binomial/LogisticRegressionSGDTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/logistic/multiclass/LogRegressionMultiClassModel.java
modules/ml/src/main/java/org/apache/ignite/ml/regressions/logistic/multiclass/LogRegressionMultiClassTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/selection/cv/CrossValidation.java
modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/cursor/CacheBasedLabelPairCursor.java
modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/cursor/LocalLabelPairCursor.java
modules/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/Evaluator.java
modules/ml/src/main/java/org/apache/ignite/ml/structures/LabeledDataset.java
modules/ml/src/main/java/org/apache/ignite/ml/structures/partition/LabeledDatasetPartitionDataBuilderOnHeap.java
modules/ml/src/main/java/org/apache/ignite/ml/structures/preprocessing/LabeledDatasetLoader.java
modules/ml/src/main/java/org/apache/ignite/ml/svm/SVMLinearBinaryClassificationModel.java
modules/ml/src/main/java/org/apache/ignite/ml/svm/SVMLinearBinaryClassificationTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/svm/SVMLinearMultiClassClassificationModel.java
modules/ml/src/main/java/org/apache/ignite/ml/svm/SVMLinearMultiClassClassificationTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/trainers/DatasetTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/trainers/MultiLabelDatasetTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/trainers/SingleLabelDatasetTrainer.java
modules/ml/src/main/java/org/apache/ignite/ml/tree/DecisionTree.java
modules/ml/src/main/java/org/apache/ignite/ml/tree/DecisionTreeConditionalNode.java
modules/ml/src/main/java/org/apache/ignite/ml/tree/DecisionTreeLeafNode.java
modules/ml/src/main/java/org/apache/ignite/ml/tree/data/DecisionTreeDataBuilder.java
modules/ml/src/main/java/org/apache/ignite/ml/util/ModelTrace.java [new file with mode: 0644]
modules/ml/src/test/java/org/apache/ignite/ml/LocalModelsTest.java
modules/ml/src/test/java/org/apache/ignite/ml/TestUtils.java
modules/ml/src/test/java/org/apache/ignite/ml/clustering/KMeansModelTest.java
modules/ml/src/test/java/org/apache/ignite/ml/clustering/KMeansTrainerTest.java
modules/ml/src/test/java/org/apache/ignite/ml/genetic/GAGridCalculateFitnessTest.java
modules/ml/src/test/java/org/apache/ignite/ml/genetic/GAGridInitializePopulationTest.java
modules/ml/src/test/java/org/apache/ignite/ml/knn/KNNClassificationTest.java
modules/ml/src/test/java/org/apache/ignite/ml/knn/KNNRegressionTest.java
modules/ml/src/test/java/org/apache/ignite/ml/knn/LabeledDatasetTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/BlasTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/MathImplLocalTestSuite.java
modules/ml/src/test/java/org/apache/ignite/ml/math/TracerTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/matrix/MatrixBaseStorageTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/matrix/MatrixStorageFixtures.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/AbstractVectorTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/DelegatingVectorConstructorTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/MatrixVectorViewTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/VectorAttributesTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/VectorBaseStorageTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/VectorImplementationsFixtures.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/VectorImplementationsTest.java
modules/ml/src/test/java/org/apache/ignite/ml/math/primitives/vector/VectorToMatrixTest.java
modules/ml/src/test/java/org/apache/ignite/ml/nn/MLPTest.java
modules/ml/src/test/java/org/apache/ignite/ml/nn/MLPTrainerIntegrationTest.java
modules/ml/src/test/java/org/apache/ignite/ml/nn/MLPTrainerTest.java
modules/ml/src/test/java/org/apache/ignite/ml/nn/performance/MLPTrainerMnistIntegrationTest.java
modules/ml/src/test/java/org/apache/ignite/ml/nn/performance/MLPTrainerMnistTest.java
modules/ml/src/test/java/org/apache/ignite/ml/regressions/linear/LinearRegressionModelTest.java
modules/ml/src/test/java/org/apache/ignite/ml/regressions/logistic/LogisticRegressionModelTest.java
modules/ml/src/test/java/org/apache/ignite/ml/svm/SVMModelTest.java

index 829fc4e..1e80d6d 100644 (file)
@@ -19,11 +19,9 @@ package org.apache.ignite.examples.ml.genetic.change;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.Ignition;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.GAGrid;
 import org.apache.ignite.ml.genetic.Gene;
index bb4a369..2080ac3 100644 (file)
 package org.apache.ignite.examples.ml.genetic.change;
 
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteLogger;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.parameter.ITerminateCriteria;
index 9e0eb7a..839471a 100644 (file)
@@ -19,10 +19,8 @@ package org.apache.ignite.examples.ml.genetic.helloworld;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.GAGrid;
 import org.apache.ignite.ml.genetic.Gene;
index e7ec131..41809d4 100644 (file)
 package org.apache.ignite.examples.ml.genetic.helloworld;
 
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteLogger;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.parameter.ITerminateCriteria;
index 21b9c01..7578226 100644 (file)
@@ -19,10 +19,8 @@ package org.apache.ignite.examples.ml.genetic.knapsack;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
-
 import org.apache.ignite.ml.genetic.GAGrid;
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
index b5f52f7..bfd50f0 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.ignite.examples.ml.genetic.movie;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.IFitnessFunction;
 
index c52238b..a0b368a 100644 (file)
@@ -20,10 +20,8 @@ package org.apache.ignite.examples.ml.genetic.movie;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.GAGrid;
 import org.apache.ignite.ml.genetic.Gene;
index ac56cca..43804b7 100644 (file)
 package org.apache.ignite.examples.ml.genetic.movie;
 
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteLogger;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.parameter.ITerminateCriteria;
index 85e2bec..d12fc1d 100644 (file)
@@ -30,8 +30,8 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.ml.knn.classification.KNNClassificationModel;
 import org.apache.ignite.ml.knn.classification.KNNClassificationTrainer;
 import org.apache.ignite.ml.knn.classification.KNNStrategy;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.distances.EuclideanDistance;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.thread.IgniteThread;
 
index 597efe4..d1e5055 100644 (file)
@@ -31,8 +31,8 @@ import org.apache.ignite.ml.knn.classification.KNNClassificationTrainer;
 import org.apache.ignite.ml.knn.classification.KNNStrategy;
 import org.apache.ignite.ml.knn.regression.KNNRegressionModel;
 import org.apache.ignite.ml.knn.regression.KNNRegressionTrainer;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.distances.ManhattanDistance;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.thread.IgniteThread;
 
index 68d793f..7873b12 100644 (file)
@@ -24,8 +24,8 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.ExampleNodeStartup;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.nn.Activators;
 import org.apache.ignite.ml.nn.MLPTrainer;
 import org.apache.ignite.ml.nn.MultilayerPerceptron;
index 9f2fc8a..4c873d9 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.ml.dataset.model.Person;
 import org.apache.ignite.ml.dataset.DatasetFactory;
 import org.apache.ignite.ml.dataset.primitive.SimpleDataset;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.binarization.BinarizationTrainer;
 
 /**
index 239e3a7..3ea52d8 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.ml.dataset.model.Person;
 import org.apache.ignite.ml.dataset.DatasetFactory;
 import org.apache.ignite.ml.dataset.primitive.SimpleDataset;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 
 /**
index 3348ce0..10344bc 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.ml.dataset.model.Person;
 import org.apache.ignite.ml.dataset.DatasetFactory;
 import org.apache.ignite.ml.dataset.primitive.SimpleDataset;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.preprocessing.imputing.ImputingStrategy;
 
index 37920cf..3f3b0d6 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.ml.dataset.model.Person;
 import org.apache.ignite.ml.dataset.DatasetFactory;
 import org.apache.ignite.ml.dataset.primitive.SimpleDataset;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
 
 /**
index e58154a..b8581d0 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.examples.ml.dataset.model.Person;
 import org.apache.ignite.ml.dataset.DatasetFactory;
 import org.apache.ignite.ml.dataset.primitive.SimpleDataset;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.normalization.NormalizationTrainer;
 
 /**
index fca86b6..03c82ef 100644 (file)
@@ -27,9 +27,9 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerPreprocessor;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
 import org.apache.ignite.ml.regressions.linear.LinearRegressionLSQRTrainer;
index 362e9b7..351f1c6 100644 (file)
@@ -27,9 +27,9 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.nn.UpdatesStrategy;
 import org.apache.ignite.ml.optimization.updatecalculators.SimpleGDParameterUpdate;
index b835a5f..b9e24c0 100644 (file)
@@ -27,9 +27,9 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
 import org.apache.ignite.ml.svm.SVMLinearMultiClassClassificationModel;
index 4704268..c803354 100644 (file)
@@ -28,6 +28,10 @@ import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.ml.composition.ModelsComposition;
+import org.apache.ignite.ml.environment.LearningEnvironment;
+import org.apache.ignite.ml.environment.logging.ConsoleLogger;
+import org.apache.ignite.ml.environment.logging.MLLogger;
+import org.apache.ignite.ml.environment.parallelism.ParallelismStrategy;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.tree.randomforest.RandomForestRegressionTrainer;
 import org.apache.ignite.ml.tree.randomforest.RandomForestTrainer;
@@ -35,11 +39,12 @@ import org.apache.ignite.thread.IgniteThread;
 
 /**
  * Example represents a solution for the task of price predictions for houses in Boston based on RandomForest
- * implementation for regression. It shows an initialization of {@link RandomForestTrainer},
- * +initialization of Ignite Cache, learning step and evaluation of model quality in terms of
- * Mean Squared Error (MSE) and Mean Absolute Error (MAE).
+ * implementation for regression. It shows an initialization of {@link RandomForestTrainer}, +initialization of Ignite
+ * Cache, learning step and evaluation of model quality in terms of Mean Squared Error (MSE) and Mean Absolute Error
+ * (MAE).
  *
  * Dataset url: https://archive.ics.uci.edu/ml/machine-learning-databases/housing/
+ *
  * @see RandomForestRegressionTrainer
  */
 public class RandomForestRegressionExample {
@@ -54,10 +59,15 @@ public class RandomForestRegressionExample {
             System.out.println(">>> Ignite grid started.");
 
             IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(),
-                    RandomForestRegressionExample.class.getSimpleName(), () -> {
+                RandomForestRegressionExample.class.getSimpleName(), () -> {
                 IgniteCache<Integer, double[]> dataCache = getTestCache(ignite);
 
                 RandomForestRegressionTrainer trainer = new RandomForestRegressionTrainer(13, 4, 101, 0.3, 2, 0);
+                trainer.setEnvironment(LearningEnvironment.builder()
+                    .withParallelismStrategy(ParallelismStrategy.Type.ON_DEFAULT_POOL)
+                    .withLoggingFactory(ConsoleLogger.factory(MLLogger.VerboseLevel.LOW))
+                    .build()
+                );
 
                 ModelsComposition randomForest = trainer.fit(ignite, dataCache,
                         (k, v) -> VectorUtils.of(Arrays.copyOfRange(v, 0, v.length - 1)),
index 3910edb..460ca67 100644 (file)
@@ -21,9 +21,9 @@ import java.io.FileNotFoundException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
 import org.apache.ignite.ml.selection.scoring.metric.Accuracy;
 import org.apache.ignite.ml.tree.DecisionTreeClassificationTrainer;
index 52dc434..8127a51 100644 (file)
@@ -21,9 +21,9 @@ import java.io.FileNotFoundException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
 import org.apache.ignite.ml.selection.scoring.metric.Accuracy;
index 7eb3d3b..ee2ef8b 100644 (file)
@@ -21,8 +21,8 @@ import java.io.FileNotFoundException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.encoding.stringencoder.StringEncoderTrainer;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
index 67615dd..c3bf389 100644 (file)
@@ -21,8 +21,8 @@ import java.io.FileNotFoundException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.encoding.stringencoder.StringEncoderTrainer;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.selection.scoring.evaluator.Evaluator;
index 88a38ef..549ab77 100644 (file)
@@ -21,8 +21,8 @@ import java.io.FileNotFoundException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.encoding.stringencoder.StringEncoderTrainer;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
index 42a531b..5308287 100644 (file)
@@ -24,8 +24,8 @@ import org.apache.ignite.Ignition;
 import org.apache.ignite.ml.knn.classification.KNNClassificationModel;
 import org.apache.ignite.ml.knn.classification.KNNClassificationTrainer;
 import org.apache.ignite.ml.knn.classification.KNNStrategy;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.encoding.stringencoder.StringEncoderTrainer;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
index 3a882e0..c8fad61 100644 (file)
@@ -21,8 +21,8 @@ import java.io.FileNotFoundException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.encoding.stringencoder.StringEncoderTrainer;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
index 077d8c8..981e119 100644 (file)
@@ -22,8 +22,8 @@ import java.util.Arrays;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.encoding.stringencoder.StringEncoderTrainer;
 import org.apache.ignite.ml.preprocessing.imputing.ImputerTrainer;
 import org.apache.ignite.ml.preprocessing.minmaxscaling.MinMaxScalerTrainer;
index 701039a..88b642b 100644 (file)
@@ -22,8 +22,8 @@ import java.util.Arrays;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.nn.UpdatesStrategy;
 import org.apache.ignite.ml.optimization.updatecalculators.SimpleGDParameterUpdate;
 import org.apache.ignite.ml.optimization.updatecalculators.SimpleGDUpdateCalculator;
index 41b10b9..a042666 100644 (file)
@@ -32,4 +32,11 @@ public interface Model<T, V> extends IgniteFunction<T, V> {
     public default <X, W> Model<T, X> combine(Model<T, W> other, BiFunction<V, W, X> combiner) {
         return v -> combiner.apply(apply(v), other.apply(v));
     }
+
+    /**
+     * @param pretty Use pretty mode.
+     */
+    default public String toString(boolean pretty) {
+        return getClass().getSimpleName();
+    }
 }
index 6c09f9d..bdfa1b6 100644 (file)
 package org.apache.ignite.ml.clustering.kmeans;
 
 import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
 import org.apache.ignite.ml.Exportable;
 import org.apache.ignite.ml.Exporter;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.Tracer;
 import org.apache.ignite.ml.math.distances.DistanceMeasure;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.util.ModelTrace;
 
 /**
  * This class encapsulates result of clusterization by KMeans algorithm.
@@ -109,4 +113,20 @@ public class KMeansModel implements ClusterizationModel<Vector, Integer>, Export
         return distanceMeasure.equals(that.distanceMeasure) && Arrays.deepEquals(centers, that.centers);
     }
 
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        String measureName = distanceMeasure.getClass().getSimpleName();
+        List<String> centersList = Arrays.stream(centers).map(x -> Tracer.asAscii(x, "%.4f", false))
+            .collect(Collectors.toList());
+
+        return ModelTrace.builder("KMeansModel", pretty)
+            .addField("distance measure", measureName)
+            .addField("centroids", centersList)
+            .toString();
+    }
 }
index a0f6cc7..549b9fe 100644 (file)
@@ -21,8 +21,8 @@ import java.io.Serializable;
 import java.util.Arrays;
 import org.apache.ignite.ml.Exportable;
 import org.apache.ignite.ml.Exporter;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.distances.DistanceMeasure;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * K-means model representation.
index b26ff68..7dbc78a 100644 (file)
@@ -28,11 +28,11 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.distances.DistanceMeasure;
 import org.apache.ignite.ml.math.distances.EuclideanDistance;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.util.MapUtil;
 import org.apache.ignite.ml.structures.LabeledDataset;
@@ -43,7 +43,7 @@ import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
 /**
  * The trainer for KMeans algorithm.
  */
-public class KMeansTrainer implements SingleLabelDatasetTrainer<KMeansModel> {
+public class KMeansTrainer extends SingleLabelDatasetTrainer<KMeansModel> {
     /** Amount of clusters. */
     private int k = 2;
 
index d73bd4e..f439789 100644 (file)
@@ -22,25 +22,28 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import org.apache.ignite.ml.Model;
 import org.apache.ignite.ml.composition.predictionsaggregator.PredictionsAggregator;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
+import org.apache.ignite.ml.environment.logging.MLLogger;
+import org.apache.ignite.ml.environment.parallelism.Promise;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.functions.IgniteSupplier;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.selection.split.mapper.SHA256UniformMapper;
 import org.apache.ignite.ml.trainers.DatasetTrainer;
 import org.apache.ignite.ml.util.Utils;
 import org.jetbrains.annotations.NotNull;
 
 /**
- * Abstract trainer implementing bagging logic.
- * In each learning iteration the algorithm trains one model on subset of learning sample and
- * subspace of features space. Each model is produced from same model-class [e.g. Decision Trees].
+ * Abstract trainer implementing bagging logic. In each learning iteration the algorithm trains one model on subset of
+ * learning sample and subspace of features space. Each model is produced from same model-class [e.g. Decision Trees].
  */
-public abstract class BaggingModelTrainer implements DatasetTrainer<ModelsComposition, Double> {
+public abstract class BaggingModelTrainer extends DatasetTrainer<ModelsComposition, Double> {
     /**
      * Predictions aggregator.
      */
@@ -89,11 +92,23 @@ public abstract class BaggingModelTrainer implements DatasetTrainer<ModelsCompos
         IgniteBiFunction<K, V, Vector> featureExtractor,
         IgniteBiFunction<K, V, Double> lbExtractor) {
 
-        List<ModelOnFeaturesSubspace> learnedModels = new ArrayList<>();
-        for (int i = 0; i < ensembleSize; i++)
-            learnedModels.add(learnModel(datasetBuilder, featureExtractor, lbExtractor));
+        MLLogger log = environment.logger(getClass());
+        log.log(MLLogger.VerboseLevel.LOW, "Start learning");
+
+        Long startTs = System.currentTimeMillis();
+
+        List<IgniteSupplier<ModelOnFeaturesSubspace>> tasks = new ArrayList<>();
+        for(int i = 0; i < ensembleSize; i++)
+            tasks.add(() -> learnModel(datasetBuilder, featureExtractor, lbExtractor));
+
+        List<Model<Vector, Double>> models = environment.parallelismStrategy().submit(tasks)
+            .stream().map(Promise::unsafeGet)
+            .collect(Collectors.toList());
 
-        return new ModelsComposition(learnedModels, predictionsAggregator);
+        double learningTime = (double)(System.currentTimeMillis() - startTs) / 1000.0;
+        log.log(MLLogger.VerboseLevel.LOW, "The training time was %.2fs", learningTime);
+        log.log(MLLogger.VerboseLevel.LOW, "Learning finished");
+        return new ModelsComposition(models, predictionsAggregator);
     }
 
     /**
@@ -114,10 +129,13 @@ public abstract class BaggingModelTrainer implements DatasetTrainer<ModelsCompos
         Map<Integer, Integer> featuresMapping = createFeaturesMapping(featureExtractorSeed, featureVectorSize);
 
         //TODO: IGNITE-8867 Need to implement bootstrapping algorithm
+        Long startTs = System.currentTimeMillis();
         Model<Vector, Double> mdl = buildDatasetTrainerForModel().fit(
             datasetBuilder.withFilter((features, answer) -> sampleFilter.map(features, answer) < samplePartSizePerMdl),
             wrapFeatureExtractor(featureExtractor, featuresMapping),
             lbExtractor);
+        double learningTime = (double)(System.currentTimeMillis() - startTs) / 1000.0;
+        environment.logger(getClass()).log(MLLogger.VerboseLevel.HIGH, "One model training time was %.2fs", learningTime);
 
         return new ModelOnFeaturesSubspace(featuresMapping, mdl);
     }
index 5877afa..5ef1de5 100644 (file)
@@ -19,9 +19,11 @@ package org.apache.ignite.ml.composition;
 
 import java.util.Collections;
 import java.util.Map;
+import java.util.stream.Collectors;
 import org.apache.ignite.ml.Model;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
+import org.apache.ignite.ml.util.ModelTrace;
 
 /**
  * Model trained on a features subspace with mapping from original features space to subspace.
@@ -72,4 +74,21 @@ public class ModelOnFeaturesSubspace implements Model<Vector, Double> {
     public Model<Vector, Double> getMdl() {
         return mdl;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        String mappingStr = featuresMapping.entrySet().stream()
+            .map(e -> String.format("%d -> %d", e.getKey(), e.getValue()))
+            .collect(Collectors.joining(", ", "{", "}"));
+
+        return ModelTrace.builder("ModelOnFeatureSubspace", pretty)
+            .addField("features mapping", mappingStr)
+            .addField("model", mdl.toString(false))
+            .toString();
+    }
 }
index 661c941..e14fa6d 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import org.apache.ignite.ml.Model;
 import org.apache.ignite.ml.composition.predictionsaggregator.PredictionsAggregator;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.util.ModelTrace;
 
 /**
  * Model consisting of several models and prediction aggregation strategy.
@@ -75,4 +76,17 @@ public class ModelsComposition implements Model<Vector, Double> {
     public List<Model<Vector, Double>> getModels() {
         return models;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return ModelTrace.builder("Models composition", pretty)
+            .addField("aggregator", predictionsAggregator.toString(pretty))
+            .addField("models", models)
+            .toString();
+    }
 }
index 25ae237..53a6219 100644 (file)
@@ -25,10 +25,10 @@ import java.util.stream.Collectors;
 import org.apache.ignite.internal.util.typedef.internal.A;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.primitive.builder.context.EmptyContextBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
 import org.apache.ignite.ml.math.functions.IgniteTriFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledVector;
 import org.apache.ignite.ml.structures.partition.LabeledDatasetPartitionDataBuilderOnHeap;
index 2c8caba..201586e 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.ignite.ml.composition.boosting;
 
 import org.apache.ignite.ml.dataset.DatasetBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Trainer for regressor using Gradient Boosting.
index 8bdb9b8..6726892 100644 (file)
@@ -28,10 +28,11 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.primitive.builder.context.EmptyContextBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
+import org.apache.ignite.ml.environment.logging.MLLogger;
 import org.apache.ignite.ml.knn.regression.KNNRegressionTrainer;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteTriFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.regressions.linear.LinearRegressionLSQRTrainer;
 import org.apache.ignite.ml.regressions.linear.LinearRegressionSGDTrainer;
 import org.apache.ignite.ml.trainers.DatasetTrainer;
@@ -42,26 +43,25 @@ import org.apache.ignite.ml.tree.randomforest.RandomForestRegressionTrainer;
 import org.jetbrains.annotations.NotNull;
 
 /**
- * Abstract Gradient Boosting trainer.
- * It implements gradient descent in functional space using user-selected regressor in child class.
- * Each learning iteration the trainer evaluate gradient of error-function and fit regression model
- * to it. After learning step the model is used in models composition of regressions with weight
- * equal to gradient descent step.
+ * Abstract Gradient Boosting trainer. It implements gradient descent in functional space using user-selected regressor
+ * in child class. Each learning iteration the trainer evaluate gradient of error-function and fit regression model to
+ * it. After learning step the model is used in models composition of regressions with weight equal to gradient descent
+ * step.
  *
- * These classes can be used as regressor trainers:
- * {@link DecisionTreeRegressionTrainer}, {@link KNNRegressionTrainer},
- * {@link LinearRegressionLSQRTrainer}, {@link RandomForestRegressionTrainer},
- * {@link LinearRegressionSGDTrainer}.
+ * These classes can be used as regressor trainers: {@link DecisionTreeRegressionTrainer}, {@link KNNRegressionTrainer},
+ * {@link LinearRegressionLSQRTrainer}, {@link RandomForestRegressionTrainer}, {@link LinearRegressionSGDTrainer}.
  *
  * But in practice Decision Trees is most used regressors (see: {@link DecisionTreeRegressionTrainer}).
  */
-abstract class GDBTrainer implements DatasetTrainer<Model<Vector, Double>, Double> {
+abstract class GDBTrainer extends DatasetTrainer<Model<Vector, Double>, Double> {
     /** Gradient step. */
     private final double gradientStep;
     /** Count of iterations. */
     private final int cntOfIterations;
-    /** Gradient of loss function. First argument is sample size, second argument is valid answer,
-     * third argument is current model prediction. */
+    /**
+     * Gradient of loss function. First argument is sample size, second argument is valid answer, third argument is
+     * current model prediction.
+     */
     private final IgniteTriFunction<Long, Double, Double, Double> lossGradient;
 
     /**
@@ -69,9 +69,11 @@ abstract class GDBTrainer implements DatasetTrainer<Model<Vector, Double>, Doubl
      *
      * @param gradStepSize Grad step size.
      * @param cntOfIterations Count of learning iterations.
-     * @param lossGradient Gradient of loss function. First argument is sample size, second argument is valid answer third argument is current model prediction.
+     * @param lossGradient Gradient of loss function. First argument is sample size, second argument is valid answer
+     * third argument is current model prediction.
      */
-    public GDBTrainer(double gradStepSize, Integer cntOfIterations, IgniteTriFunction<Long, Double, Double, Double> lossGradient) {
+    public GDBTrainer(double gradStepSize, Integer cntOfIterations,
+        IgniteTriFunction<Long, Double, Double, Double> lossGradient) {
         gradientStep = gradStepSize;
         this.cntOfIterations = cntOfIterations;
         this.lossGradient = lossGradient;
@@ -94,6 +96,7 @@ abstract class GDBTrainer implements DatasetTrainer<Model<Vector, Double>, Doubl
         Arrays.fill(compositionWeights, gradientStep);
         WeightedPredictionsAggregator resAggregator = new WeightedPredictionsAggregator(compositionWeights, mean);
 
+        long learningStartTs = System.currentTimeMillis();
         for (int i = 0; i < cntOfIterations; i++) {
             double[] weights = Arrays.copyOf(compositionWeights, i);
             WeightedPredictionsAggregator aggregator = new WeightedPredictionsAggregator(weights, mean);
@@ -105,8 +108,13 @@ abstract class GDBTrainer implements DatasetTrainer<Model<Vector, Double>, Doubl
                 return -lossGradient.apply(sampleSize, realAnswer, mdlAnswer);
             };
 
+            long startTs = System.currentTimeMillis();
             models.add(buildBaseModelTrainer().fit(datasetBuilder, featureExtractor, lbExtractorWrap));
+            double learningTime = (double)(System.currentTimeMillis() - startTs) / 1000.0;
+            environment.logger(getClass()).log(MLLogger.VerboseLevel.LOW, "One model training time was %.2fs", learningTime);
         }
+        double learningTime = (double)(System.currentTimeMillis() - learningStartTs) / 1000.0;
+        environment.logger(getClass()).log(MLLogger.VerboseLevel.LOW, "The training time was %.2fs", learningTime);
 
         return new ModelsComposition(models, resAggregator) {
             @Override public Double apply(Vector features) {
@@ -122,7 +130,7 @@ abstract class GDBTrainer implements DatasetTrainer<Model<Vector, Double>, Doubl
      * @param featureExtractor Feature extractor.
      * @param lExtractor Labels extractor.
      */
-    protected abstract  <V, K> void learnLabels(DatasetBuilder<K, V> builder,
+    protected abstract <V, K> void learnLabels(DatasetBuilder<K, V> builder,
         IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, Double> lExtractor);
 
     /**
index 86b1e96..d996a2a 100644 (file)
@@ -23,4 +23,12 @@ import org.apache.ignite.ml.math.functions.IgniteFunction;
  * Predictions aggregator interface.
  */
 public interface PredictionsAggregator extends IgniteFunction<double[], Double> {
+    /**
+     * Represents aggregator as String.
+     *
+     * @param pretty Use pretty mode.
+     */
+    public default String toString(boolean pretty) {
+        return getClass().getSimpleName();
+    }
 }
index f6bbe9c..c37fdf7 100644 (file)
@@ -62,4 +62,28 @@ public class WeightedPredictionsAggregator implements PredictionsAggregator {
 
         return res;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        String clsName = getClass().getSimpleName();
+        if(!pretty)
+            return clsName;
+
+        StringBuilder builder = new StringBuilder(clsName).append(" [");
+        for(int i = 0; i < weights.length; i++) {
+            final String SIGN = weights[i] > 0 ? " + " : " - ";
+            builder
+                .append(i > 0 || weights[i] < 0 ? SIGN : "")
+                .append(String.format("%.4f", Math.abs(weights[i])))
+                .append("*x").append(i);
+        }
+
+        return builder.append(bias > 0 ? " + " : " - ").append(String.format("%.4f", bias))
+            .append("]").toString();
+    }
 }
index 75ac6d3..ffd3136 100644 (file)
@@ -31,8 +31,8 @@ import org.apache.ignite.ml.dataset.primitive.builder.data.SimpleLabeledDatasetD
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
 import org.apache.ignite.ml.dataset.primitive.data.SimpleDatasetData;
 import org.apache.ignite.ml.dataset.primitive.data.SimpleLabeledDatasetData;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Factory providing a client facing API that allows to construct basic and the most frequently used types of dataset.
index e2f98c2..cf5bc7a 100644 (file)
@@ -22,8 +22,8 @@ import java.util.Iterator;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.UpstreamEntry;
 import org.apache.ignite.ml.dataset.primitive.data.SimpleDatasetData;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * A partition {@code data} builder that makes {@link SimpleDatasetData}.
index 1bfd949..6286255 100644 (file)
@@ -22,8 +22,8 @@ import java.util.Iterator;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.UpstreamEntry;
 import org.apache.ignite.ml.dataset.primitive.data.SimpleLabeledDatasetData;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * A partition {@code data} builder that makes {@link SimpleLabeledDatasetData}.
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/LearningEnvironment.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/LearningEnvironment.java
new file mode 100644 (file)
index 0000000..2b94a2f
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment;
+
+import org.apache.ignite.ml.environment.logging.MLLogger;
+import org.apache.ignite.ml.environment.parallelism.ParallelismStrategy;
+
+/**
+ * Specifies a set of utility-objects helpful at runtime but optional for learning algorithm
+ * (like thread pool for parallel learning in bagging model or logger).
+ */
+public interface LearningEnvironment {
+    /** Default environment */
+    public static final LearningEnvironment DEFAULT = builder().build();
+
+    /**
+     * Returns Parallelism Strategy instance.
+     */
+    public ParallelismStrategy parallelismStrategy();
+
+    /**
+     * Returns an instance of logger.
+     */
+    public MLLogger logger();
+
+    /**
+     * Returns an instance of logger for specific class.
+     *
+     * @param forClass Logging class context.
+     */
+    public <T> MLLogger logger(Class<T> forClass);
+
+    /**
+     * Creates an instance of LearningEnvironmentBuilder.
+     */
+    public static LearningEnvironmentBuilder builder() {
+        return new LearningEnvironmentBuilder();
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/LearningEnvironmentBuilder.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/LearningEnvironmentBuilder.java
new file mode 100644 (file)
index 0000000..be56ccc
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment;
+
+import org.apache.ignite.ml.environment.logging.MLLogger;
+import org.apache.ignite.ml.environment.logging.NoOpLogger;
+import org.apache.ignite.ml.environment.parallelism.DefaultParallelismStrategy;
+import org.apache.ignite.ml.environment.parallelism.NoParallelismStrategy;
+import org.apache.ignite.ml.environment.parallelism.ParallelismStrategy;
+
+/**
+ * Builder for LearningEnvironment.
+ */
+public class LearningEnvironmentBuilder {
+    /** Parallelism strategy. */
+    private ParallelismStrategy parallelismStgy;
+    /** Logging factory. */
+    private MLLogger.Factory loggingFactory;
+
+    /**
+     * Creates an instance of LearningEnvironmentBuilder.
+     */
+    LearningEnvironmentBuilder() {
+        parallelismStgy = NoParallelismStrategy.INSTANCE;
+        loggingFactory = NoOpLogger.factory();
+    }
+
+    /**
+     * Specifies Parallelism Strategy for LearningEnvironment.
+     *
+     * @param stgy Parallelism Strategy.
+     */
+    public <T> LearningEnvironmentBuilder withParallelismStrategy(ParallelismStrategy stgy) {
+        this.parallelismStgy = stgy;
+
+        return this;
+    }
+
+    /**
+     * Specifies Parallelism Strategy for LearningEnvironment.
+     *
+     * @param stgyType Parallelism Strategy Type.
+     */
+    public LearningEnvironmentBuilder withParallelismStrategy(ParallelismStrategy.Type stgyType) {
+        switch (stgyType) {
+            case NO_PARALLELISM:
+                this.parallelismStgy = NoParallelismStrategy.INSTANCE;
+            case ON_DEFAULT_POOL:
+                this.parallelismStgy = new DefaultParallelismStrategy();
+        }
+        return this;
+    }
+
+
+    /**
+     * Specifies Logging factory for LearningEnvironment.
+     *
+     * @param loggingFactory Logging Factory.
+     */
+    public LearningEnvironmentBuilder withLoggingFactory(MLLogger.Factory loggingFactory) {
+        this.loggingFactory = loggingFactory;
+        return this;
+    }
+
+    /**
+     * Create an instance of LearningEnvironment.
+     */
+    public LearningEnvironment build() {
+        return new LearningEnvironmentImpl(parallelismStgy, loggingFactory);
+    }
+
+    /**
+     * Default LearningEnvironment implementation.
+     */
+    private class LearningEnvironmentImpl implements LearningEnvironment {
+        /** Parallelism strategy. */
+        private final ParallelismStrategy parallelismStgy;
+        /** Logging factory. */
+        private final MLLogger.Factory loggingFactory;
+
+        /**
+         * Creates an instance of LearningEnvironmentImpl.
+         *
+         * @param parallelismStgy Parallelism strategy.
+         * @param loggingFactory Logging factory.
+         */
+        private LearningEnvironmentImpl(ParallelismStrategy parallelismStgy,
+            MLLogger.Factory loggingFactory) {
+            this.parallelismStgy = parallelismStgy;
+            this.loggingFactory = loggingFactory;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ParallelismStrategy parallelismStrategy() {
+            return parallelismStgy;
+        }
+
+        /** {@inheritDoc} */
+        @Override public MLLogger logger() {
+            return loggingFactory.create(getClass());
+        }
+
+        /** {@inheritDoc} */
+        @Override public <T> MLLogger logger(Class<T> clazz) {
+            return loggingFactory.create(clazz);
+        }
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/ConsoleLogger.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/ConsoleLogger.java
new file mode 100644 (file)
index 0000000..7efa29c
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.logging;
+
+import org.apache.ignite.ml.Model;
+import org.apache.ignite.ml.math.Tracer;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+
+/**
+ * Simple logger printing to STD-out.
+ */
+public class ConsoleLogger implements MLLogger {
+    /** Maximum Verbose level. */
+    private final VerboseLevel maxVerboseLevel;
+    /** Class name. */
+    private final String className;
+
+    /**
+     * Creates an instance of ConsoleLogger.
+     *
+     * @param maxVerboseLevel Max verbose level.
+     * @param clsName Class name.
+     */
+    private ConsoleLogger(VerboseLevel maxVerboseLevel, String clsName) {
+        this.className = clsName;
+        this.maxVerboseLevel = maxVerboseLevel;
+    }
+
+    /**
+     * Returns an instance of ConsoleLogger factory.
+     *
+     * @param maxVerboseLevel Max verbose level.
+     */
+    public static Factory factory(VerboseLevel maxVerboseLevel) {
+        return new Factory(maxVerboseLevel);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector log(Vector vector) {
+        Tracer.showAscii(vector);
+        return vector;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> Model<K, V> log(VerboseLevel verboseLevel, Model<K, V> mdl) {
+        print(verboseLevel, mdl.toString(true));
+        return mdl;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void log(VerboseLevel verboseLevel, String fmtStr, Object... params) {
+        print(verboseLevel, String.format(fmtStr, params));
+    }
+
+    /**
+     * Prints log line to STD-out.
+     *
+     * @param verboseLevel Verbose level.
+     * @param line Line.
+     */
+    private void print(VerboseLevel verboseLevel, String line) {
+        if (this.maxVerboseLevel.compareTo(verboseLevel) >= 0)
+            System.out.println(String.format("%s [%s] %s", className, verboseLevel.name(), line));
+    }
+
+    /**
+     * ConsoleLogger factory.
+     */
+    private static class Factory implements MLLogger.Factory {
+        /** Max Verbose level. */
+        private final VerboseLevel maxVerboseLevel;
+
+        /**
+         * Creates an instance of ConsoleLogger factory.
+         *
+         * @param maxVerboseLevel Max verbose level.
+         */
+        private Factory(VerboseLevel maxVerboseLevel) {
+            this.maxVerboseLevel = maxVerboseLevel;
+        }
+
+        /** {@inheritDoc} */
+        @Override public <T> MLLogger create(Class<T> targetCls) {
+            return new ConsoleLogger(maxVerboseLevel, targetCls.getName());
+        }
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/CustomMLLogger.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/CustomMLLogger.java
new file mode 100644 (file)
index 0000000..65bc4cb
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.logging;
+
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.ml.Model;
+import org.apache.ignite.ml.math.Tracer;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+
+/**
+ * MLLogger implementation based on IgniteLogger.
+ */
+public class CustomMLLogger implements MLLogger {
+    /** Ignite logger instance. */
+    private final IgniteLogger logger;
+
+    /**
+     * Creates an instance of CustomMLLogger.
+     *
+     * @param logger Basic Logger.
+     */
+    private CustomMLLogger(IgniteLogger logger) {
+        this.logger = logger;
+    }
+
+    /**
+     * Returns factory for OnIgniteLogger instantiating.
+     *
+     * @param rootLogger Root logger.
+     */
+    public static Factory factory(IgniteLogger rootLogger) {
+        return new Factory(rootLogger);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector log(Vector vector) {
+        Tracer.showAscii(vector, logger);
+        return vector;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> Model<K, V> log(VerboseLevel verboseLevel, Model<K, V> mdl) {
+        log(verboseLevel, mdl.toString(true));
+        return mdl;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void log(VerboseLevel verboseLevel, String fmtStr, Object... params) {
+        log(verboseLevel, String.format(fmtStr, params));
+    }
+
+    /**
+     * Log line.
+     *
+     * @param verboseLevel Verbose level.
+     * @param line Line.
+     */
+    private void log(VerboseLevel verboseLevel, String line) {
+        switch (verboseLevel) {
+            case LOW:
+                logger.info(line);
+                break;
+            case HIGH:
+                logger.debug(line);
+                break;
+        }
+    }
+
+    /**
+     * CustomMLLogger factory.
+     */
+    private static class Factory implements MLLogger.Factory {
+        /** Root logger. */
+        private IgniteLogger rootLogger;
+
+        /**
+         * Creates an instance of factory.
+         *
+         * @param rootLogger Root logger.
+         */
+        public Factory(IgniteLogger rootLogger) {
+            this.rootLogger = rootLogger;
+        }
+
+        /** {@inheritDoc} */
+        @Override public <T> MLLogger create(Class<T> targetCls) {
+            return new CustomMLLogger(rootLogger.getLogger(targetCls));
+        }
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/MLLogger.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/MLLogger.java
new file mode 100644 (file)
index 0000000..872b947
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.logging;
+
+import org.apache.ignite.ml.Model;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+
+/**
+ * Helper for ML-specific objects logging.
+ */
+public interface MLLogger {
+    /**
+     * Logging verbose level.
+     */
+    enum VerboseLevel {
+        OFF, LOW, HIGH
+    }
+
+    /**
+     * Log vector.
+     *
+     * @param vector Vector.
+     */
+    public Vector log(Vector vector);
+
+    /**
+     * Log model according to toString method.
+     *
+     * @param verboseLevel Verbose level.
+     * @param mdl Model.
+     */
+    public <K, V> Model<K,V> log(VerboseLevel verboseLevel, Model<K, V> mdl);
+
+    /**
+     * Log line with formatting.
+     *
+     * @param verboseLevel Verbose level.
+     * @param fmtStr Format string.
+     * @param params Params.
+     */
+    public void log(VerboseLevel verboseLevel, String fmtStr, Object... params);
+
+    /**
+     * MLLogger factory interface.
+     */
+    public static interface Factory {
+        /**
+         * Creates an instance of MLLogger for target class.
+         *
+         * @param targetCls For class.
+         */
+        public <T> MLLogger create(Class<T> targetCls);
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/NoOpLogger.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/NoOpLogger.java
new file mode 100644 (file)
index 0000000..67b48f5
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.logging;
+
+import org.apache.ignite.ml.Model;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+
+/**
+ * MLLogger implementation skipping all logs.
+ */
+public class NoOpLogger implements MLLogger {
+    /** Factory. */
+    private static final Factory FACTORY = new Factory();
+
+    /**
+     * Returns NoOpLogger factory.
+     */
+    public static Factory factory() {
+        return FACTORY;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Vector log(Vector vector) {
+        return vector;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> Model<K, V> log(VerboseLevel verboseLevel, Model<K, V> mdl) {
+        return mdl;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void log(VerboseLevel verboseLevel, String fmtStr, Object... params) {
+
+    }
+
+    /**
+     * NoOpLogger factory.
+     */
+    private static class Factory implements MLLogger.Factory {
+        /** NoOpLogger instance. */
+        private final static NoOpLogger NO_OP_LOGGER = new NoOpLogger();
+
+        /** {@inheritDoc} */
+        @Override public <T> MLLogger create(Class<T> targetCls) {
+            return NO_OP_LOGGER;
+        }
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/logging/package-info.java
new file mode 100644 (file)
index 0000000..303f006
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Package contains several logging strategy realisations.
+ */
+package org.apache.ignite.ml.environment.logging;
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/package-info.java
new file mode 100644 (file)
index 0000000..0f58d13
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Package contains environment utils for ML algorithms.
+ */
+package org.apache.ignite.ml.environment;
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/DefaultParallelismStrategy.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/DefaultParallelismStrategy.java
new file mode 100644 (file)
index 0000000..ce2ca50
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.parallelism;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.ml.math.functions.IgniteSupplier;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * All task should be processed by default thread pool.
+ */
+public class DefaultParallelismStrategy implements ParallelismStrategy {
+    /** Strategy Pool. */
+    private ExecutorService pool = Executors.newWorkStealingPool(4);
+
+    /** {@inheritDoc} */
+    @Override public <T> Promise<T> submit(IgniteSupplier<T> task) {
+        return new FutureWrapper<>(pool.submit(task::get));
+    }
+
+    /**
+     * Wrapper for future class.
+     *
+     * @param <T>
+     */
+    public static class FutureWrapper<T> implements Promise<T> {
+        private final Future<T> f;
+
+        /**
+         * Create an instance of FutureWrapper.
+         *
+         * @param f Future.
+         */
+        public FutureWrapper(Future<T> f) {
+            this.f = f;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean cancel(boolean mayInterruptIfRunning) {
+            return f.cancel(mayInterruptIfRunning);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isCancelled() {
+            return f.isCancelled();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isDone() {
+            return f.isDone();
+        }
+
+        /** {@inheritDoc} */
+        @Override public T get() throws InterruptedException, ExecutionException {
+            return f.get();
+        }
+
+        /** {@inheritDoc} */
+        @Override public T get(long timeout,
+            @NotNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
+
+            return f.get(timeout, unit);
+        }
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/NoParallelismStrategy.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/NoParallelismStrategy.java
new file mode 100644 (file)
index 0000000..5f605a7
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.parallelism;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.ml.math.functions.IgniteSupplier;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * All tasks should be processed in one thread.
+ */
+public class NoParallelismStrategy implements ParallelismStrategy {
+    /** Instance. */
+    public static final ParallelismStrategy INSTANCE = new NoParallelismStrategy();
+
+    /** */
+    private NoParallelismStrategy() {
+
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T>  Promise<T> submit(IgniteSupplier<T> task) {
+        return new Stub<>(task.get());
+    }
+
+    /**
+     * Stub for Future interface implementation.
+     *
+     * @param <T> Type of result.
+     */
+    public static class Stub<T> implements Promise<T> {
+        private T result;
+
+        /**
+         * Create an instance of Stub
+         *
+         * @param result Execution result.
+         */
+        public Stub(T result) {
+            this.result = result;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean cancel(boolean mayInterruptIfRunning) {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isCancelled() {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isDone() {
+            return true;
+        }
+
+        /** {@inheritDoc} */
+        @Override public T get() throws InterruptedException, ExecutionException {
+            return result;
+        }
+
+        /** {@inheritDoc} */
+        @Override public T get(long timeout,
+            @NotNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
+
+            return result;
+        }
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/ParallelismStrategy.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/ParallelismStrategy.java
new file mode 100644 (file)
index 0000000..cdf2d50
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.parallelism;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.ml.math.functions.IgniteSupplier;
+
+/**
+ * Specifies the behaviour of processes in ML-algorithms that can may be parallelized such as parallel learning in
+ * bagging, learning submodels for One-vs-All model, Cross-Validation etc.
+ */
+public interface ParallelismStrategy {
+    public enum Type {
+        NO_PARALLELISM,
+        ON_DEFAULT_POOL
+    }
+
+    /**
+     * Submit task.
+     *
+     * @param task Task.
+     */
+    public <T> Promise<T> submit(IgniteSupplier<T> task);
+
+    public default <T> List<Promise<T>> submit(List<IgniteSupplier<T>> tasks) {
+        List<Promise<T>> results = new ArrayList<>();
+        for(IgniteSupplier<T> task : tasks)
+            results.add(submit(task));
+        return results;
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/Promise.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/Promise.java
new file mode 100644 (file)
index 0000000..dec3f43
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.environment.parallelism;
+
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+/**
+ * Future interface extension for lambda-friendly interface.
+ *
+ * @param <T> Type of result.
+ */
+public interface Promise<T> extends Future<T> {
+    /**
+     * Await result of Future and return it.
+     * Wrap exceptions from Future to RuntimeException.
+     */
+    public default T unsafeGet() {
+        try {
+            return get();
+        } catch (InterruptedException | ExecutionException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Wrap result of Future to Optional-object.
+     * If Future throws an exception then it returns Optional.empty.
+     */
+    public default Optional<T> getOpt() {
+        try {
+            return Optional.of(get());
+        } catch (InterruptedException | ExecutionException e) {
+            return Optional.empty();
+        }
+    }
+}
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/package-info.java b/modules/ml/src/main/java/org/apache/ignite/ml/environment/parallelism/package-info.java
new file mode 100644 (file)
index 0000000..22fe9af
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Package contains realisations of parallelism strategies for multi-thread algorithms.
+ */
+package org.apache.ignite.ml.environment.parallelism;
index d262efe..2f213b5 100644 (file)
@@ -19,18 +19,16 @@ package org.apache.ignite.ml.genetic;
 
 import java.util.Arrays;
 import java.util.Random;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
 import org.apache.ignite.resources.IgniteInstanceResource;
 import org.apache.ignite.resources.LoggerResource;
 import org.apache.ignite.transactions.Transaction;
 
-import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
-
 /**
  * Responsible for performing 'crossover' genetic operation for 2 X 'parent' chromosomes.
  *
index 02d90be..9daa57a 100644 (file)
@@ -21,7 +21,6 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.cache.affinity.Affinity;
@@ -30,10 +29,9 @@ import org.apache.ignite.compute.ComputeJob;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.compute.ComputeJobResultPolicy;
 import org.apache.ignite.compute.ComputeTaskAdapter;
-import org.apache.ignite.resources.IgniteInstanceResource;
-
 import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
 import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+import org.apache.ignite.resources.IgniteInstanceResource;
 
 /**
  * Responsible for assigning 2 X 'parent' chromosomes to produce 2 X 'child' chromosomes.
index c11490a..0bde403 100644 (file)
@@ -19,18 +19,16 @@ package org.apache.ignite.ml.genetic;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
 import org.apache.ignite.resources.IgniteInstanceResource;
 import org.apache.ignite.resources.LoggerResource;
 import org.apache.ignite.transactions.Transaction;
 
-import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
-
 /**
  * Responsible for performing fitness evaluation on an individual chromosome
  */
index cfae767..66fd795 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.ignite.ml.genetic;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.cache.affinity.Affinity;
@@ -29,10 +28,9 @@ import org.apache.ignite.compute.ComputeJob;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.compute.ComputeJobResultPolicy;
 import org.apache.ignite.compute.ComputeTaskAdapter;
-import org.apache.ignite.resources.IgniteInstanceResource;
-
 import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
 import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+import org.apache.ignite.resources.IgniteInstanceResource;
 
 /**
  * Responsible for fitness operation
index 4133adf..92eab5e 100644 (file)
@@ -20,16 +20,13 @@ package org.apache.ignite.ml.genetic;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
-
 import javax.cache.Cache.Entry;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.SqlQuery;
-
 import org.apache.ignite.ml.genetic.cache.GeneCacheConfig;
 import org.apache.ignite.ml.genetic.cache.PopulationCacheConfig;
 import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
index f15d988..af1af3c 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.ignite.ml.genetic;
 
 import java.util.concurrent.atomic.AtomicLong;
-
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 
 /**
index 704cf00..9fd9147 100644 (file)
@@ -22,9 +22,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
-
 import javax.cache.Cache.Entry;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
@@ -36,10 +34,9 @@ import org.apache.ignite.compute.ComputeJob;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.compute.ComputeJobResultPolicy;
 import org.apache.ignite.compute.ComputeTaskAdapter;
-import org.apache.ignite.resources.IgniteInstanceResource;
-
 import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
 import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+import org.apache.ignite.resources.IgniteInstanceResource;
 
 /**
  * Responsible for applying mutation on respective chromosomes.  <br/>
index e657ca0..19f22c6 100644 (file)
@@ -22,11 +22,10 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
 import org.apache.ignite.resources.IgniteInstanceResource;
 import org.apache.ignite.transactions.Transaction;
 
-import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
-
 /**
  * Responsible for performing truncate selection
  */
index 09f17cb..00d00c1 100644 (file)
@@ -21,9 +21,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import javax.cache.Cache.Entry;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
@@ -35,8 +33,8 @@ import org.apache.ignite.compute.ComputeJob;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.compute.ComputeJobResultPolicy;
 import org.apache.ignite.compute.ComputeTaskAdapter;
-import org.apache.ignite.resources.IgniteInstanceResource;
 import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+import org.apache.ignite.resources.IgniteInstanceResource;
 
 /**
  * Responsible for performing truncate selection.
index 9911eea..2dddf4b 100644 (file)
@@ -20,15 +20,13 @@ package org.apache.ignite.ml.genetic.functions;
 import java.sql.SQLException;
 import java.sql.Types;
 import java.util.List;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
-import org.h2.tools.SimpleResultSet;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.utils.GAGridUtils;
+import org.h2.tools.SimpleResultSet;
 
 /**
  * Responsible for providing custom SQL functions to retrieve optimization results.
index ccacda6..619f56d 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.ignite.ml.genetic.parameter;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.IFitnessFunction;
 
index 76c292d..45056e1 100644 (file)
@@ -19,14 +19,11 @@ package org.apache.ignite.ml.genetic.utils;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.cache.Cache.Entry;
-
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlQuery;
-
 import org.apache.ignite.ml.genetic.Chromosome;
 import org.apache.ignite.ml.genetic.Gene;
 import org.apache.ignite.ml.genetic.cache.PopulationCacheConfig;
index 6c27ab7..b5a0cdb 100644 (file)
@@ -21,8 +21,8 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledVector;
 import org.apache.ignite.ml.structures.partition.LabeledDatasetPartitionDataBuilderOnHeap;
index 22b6832..c2c1c43 100644 (file)
@@ -33,11 +33,12 @@ import org.apache.ignite.ml.Exporter;
 import org.apache.ignite.ml.Model;
 import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.distances.DistanceMeasure;
 import org.apache.ignite.ml.math.distances.EuclideanDistance;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledVector;
+import org.apache.ignite.ml.util.ModelTrace;
 import org.jetbrains.annotations.NotNull;
 
 /**
@@ -270,4 +271,18 @@ public class KNNClassificationModel implements Model<Vector, Double>, Exportable
 
         return k == that.k && distanceMeasure.equals(that.distanceMeasure) && stgy.equals(that.stgy);
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return ModelTrace.builder("KNNClassificationModel", pretty)
+            .addField("k", String.valueOf(k))
+            .addField("measure", distanceMeasure.getClass().getSimpleName())
+            .addField("strategy", stgy.name())
+            .toString();
+    }
 }
index 99b70ab..e0a81f9 100644 (file)
@@ -19,14 +19,14 @@ package org.apache.ignite.ml.knn.classification;
 
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.knn.KNNUtils;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
 
 /**
  * kNN algorithm trainer to solve multi-class classification task.
  */
-public class KNNClassificationTrainer implements SingleLabelDatasetTrainer<KNNClassificationModel> {
+public class KNNClassificationTrainer extends SingleLabelDatasetTrainer<KNNClassificationModel> {
     /**
      * Trains model based on the specified data.
      *
index 5db2a30..16dcd8a 100644 (file)
@@ -20,10 +20,11 @@ import java.util.List;
 import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
 import org.apache.ignite.ml.knn.classification.KNNClassificationModel;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledVector;
+import org.apache.ignite.ml.util.ModelTrace;
 
 /**
  * This class provides kNN Multiple Linear Regression or Locally [weighted] regression (Simple and Weighted versions).
@@ -86,4 +87,18 @@ public class KNNRegressionModel extends KNNClassificationModel {
             sum += neighbor.label();
         return sum / (double)k;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return ModelTrace.builder("KNNClassificationModel", pretty)
+            .addField("k", String.valueOf(k))
+            .addField("measure", distanceMeasure.getClass().getSimpleName())
+            .addField("strategy", stgy.name())
+            .toString();
+    }
 }
index 5f1b349..395ce61 100644 (file)
@@ -19,14 +19,14 @@ package org.apache.ignite.ml.knn.regression;
 
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.knn.KNNUtils;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
 
 /**
  * kNN algorithm trainer to solve regression task.
  */
-public class KNNRegressionTrainer implements SingleLabelDatasetTrainer<KNNRegressionModel> {
+public class KNNRegressionTrainer extends SingleLabelDatasetTrainer<KNNRegressionModel> {
     /**
      * Trains model based on the specified data.
      *
index 18aea1a..a22ec06 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ignite.ml.math.exceptions.NonSquareMatrixException;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.util.MatrixUtil;
 
 /**
index eacf0b8..d01b150 100644 (file)
@@ -117,7 +117,22 @@ public class Tracer {
     public static void showAscii(Vector vec, String fmt) {
         String cls = vec.getClass().getSimpleName();
 
-        System.out.println(String.format(LOCALE, "%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
+        System.out.println(asAscii(vec, fmt, true));
+    }
+
+    /**
+     * @param vec Vector to show as plain text.
+     * @param fmt Format string for vector elements.
+     * @param showMeta Show vector type and size.
+     */
+    public static String asAscii(Vector vec, String fmt, boolean showMeta) {
+        String cls = vec.getClass().getSimpleName();
+        String vectorStr = mkString(vec, fmt);
+
+        if(showMeta)
+            return String.format(LOCALE, "%s(%d) [%s]", cls, vec.size(), vectorStr);
+        else
+            return String.format(LOCALE, "[%s]", vectorStr);
     }
 
     /**
@@ -159,15 +174,26 @@ public class Tracer {
      * @param fmt Format string for matrix rows.
      */
     public static void showAscii(Matrix mtx, String fmt) {
+        System.out.println(asAscii(mtx, fmt));
+    }
+
+
+    /**
+     * @param mtx {@link Matrix} object to show as a plain text.
+     * @param fmt Format string for matrix rows.
+     */
+    public static String asAscii(Matrix mtx, String fmt) {
+        StringBuilder builder = new StringBuilder();
         String cls = mtx.getClass().getSimpleName();
 
         int rows = mtx.rowSize();
         int cols = mtx.columnSize();
 
-        System.out.println(String.format(LOCALE, "%s(%dx%d)", cls, rows, cols));
+        builder.append(String.format(LOCALE, "%s(%dx%d)\n", cls, rows, cols));
 
         for (int row = 0; row < rows; row++)
-            System.out.println(rowStr(mtx, row, fmt));
+            builder.append(rowStr(mtx, row, fmt)).append(row != rows - 1 ? "\n" : "");
+        return builder.toString();
     }
 
     /**
index 50324c1..88e9a41 100644 (file)
@@ -17,8 +17,8 @@
 package org.apache.ignite.ml.math.distances;
 
 import java.io.Externalizable;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * This class is based on the corresponding class from Apache Common Math lib.
index 935e19b..fa5c21c 100644 (file)
@@ -19,8 +19,8 @@ package org.apache.ignite.ml.math.distances;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.util.MatrixUtil;
 
 /**
index f08ff7b..ef50a69 100644 (file)
@@ -19,10 +19,10 @@ package org.apache.ignite.ml.math.distances;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.functions.Functions;
 import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.util.MatrixUtil;
 
 /**
index d298e3c..bd3df14 100644 (file)
@@ -19,8 +19,8 @@ package org.apache.ignite.ml.math.distances;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.util.MatrixUtil;
 
 /**
index bed32de..161b336 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Spliterator;
 import java.util.function.Consumer;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.ml.math.Blas;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.exceptions.ColumnIndexException;
 import org.apache.ignite.ml.math.exceptions.RowIndexException;
@@ -38,6 +37,7 @@ import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
 import org.apache.ignite.ml.math.functions.IgniteTriFunction;
 import org.apache.ignite.ml.math.functions.IntIntToDoubleFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;
 import org.apache.ignite.ml.math.util.MatrixUtil;
index e4792ee..6dce522 100644 (file)
 
 package org.apache.ignite.ml.math.primitives.matrix.impl;
 
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.primitives.matrix.AbstractMatrix;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.OrderedMatrix;
-import org.apache.ignite.ml.math.StorageConstants;
-import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.matrix.storage.DenseMatrixStorage;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.math.primitives.matrix.AbstractMatrix;
+import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 
 /**
  * Basic implementation for matrix.
index 119bb8d..0c4f500 100644 (file)
@@ -20,13 +20,13 @@ package org.apache.ignite.ml.math.primitives.matrix.impl;
 import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
 import it.unimi.dsi.fastutil.ints.IntIterator;
 import it.unimi.dsi.fastutil.ints.IntSet;
+import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.functions.IgniteTriFunction;
+import org.apache.ignite.ml.math.primitives.matrix.AbstractMatrix;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
-import org.apache.ignite.ml.math.StorageConstants;
 import org.apache.ignite.ml.math.primitives.matrix.storage.SparseMatrixStorage;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.math.functions.IgniteTriFunction;
-import org.apache.ignite.ml.math.primitives.matrix.AbstractMatrix;
 import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
 
 /**
index df769c7..592064c 100644 (file)
 package org.apache.ignite.ml.math.primitives.matrix.impl;
 
 import java.io.Externalizable;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
 import org.apache.ignite.ml.math.primitives.matrix.AbstractMatrix;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 import org.apache.ignite.ml.math.primitives.matrix.storage.ViewMatrixStorage;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Implements the rectangular view into the parent {@link Matrix}.
index dcdaf4f..d21d8c6 100644 (file)
@@ -22,9 +22,9 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Arrays;
 import org.apache.ignite.ml.math.Blas;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 import org.apache.ignite.ml.math.StorageConstants;
 import org.apache.ignite.ml.math.functions.IgniteIntIntToIntBiFunction;
+import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 import org.apache.ignite.ml.math.util.MatrixUtil;
 
 /**
index fb2f3d9..4a1355c 100644 (file)
@@ -26,9 +26,9 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.HashMap;
 import java.util.Map;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 import org.apache.ignite.ml.math.StorageConstants;
 import org.apache.ignite.ml.math.functions.IgniteTriFunction;
+import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 
 /**
  * Storage for sparse, local, on-heap matrix.
index 01b630e..343ebf1 100644 (file)
@@ -29,7 +29,6 @@ import java.util.Spliterator;
 import java.util.function.Consumer;
 import java.util.function.IntToDoubleFunction;
 import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.exceptions.IndexException;
 import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
@@ -37,6 +36,7 @@ import org.apache.ignite.ml.math.functions.Functions;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteIntDoubleToDoubleBiFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix;
 import org.apache.ignite.ml.math.primitives.vector.impl.VectorView;
 import org.jetbrains.annotations.NotNull;
index 41ce988..f544405 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Spliterator;
 import java.util.function.IntToDoubleFunction;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.ml.math.Destroyable;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.MetaAttributes;
 import org.apache.ignite.ml.math.StorageOpsMetrics;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
@@ -31,6 +30,7 @@ import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteIntDoubleToDoubleBiFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 
 /**
  * A vector interface.
@@ -513,6 +513,7 @@ public interface Vector extends MetaAttributes, Externalizable, StorageOpsMetric
 
     /**
      * Returns array of doubles corresponds to vector components.
+     *
      * @return Array of doubles.
      */
     public default double[] asArray() {
index b31f6fb..3a44373 100644 (file)
@@ -25,12 +25,12 @@ import java.util.Map;
 import java.util.Spliterator;
 import java.util.function.IntToDoubleFunction;
 import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.math.primitives.vector.VectorStorage;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteIntDoubleToDoubleBiFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.primitives.vector.VectorStorage;
 
 /**
  * Convenient class that can be used to add decorations to an existing vector. Subclasses
index 48b9212..bed39e3 100644 (file)
 package org.apache.ignite.ml.math.primitives.vector.impl;
 
 import java.util.Map;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.storage.DenseVectorStorage;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.AbstractVector;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorStorage;
-import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.ml.math.primitives.vector.AbstractVector;
+import org.apache.ignite.ml.math.primitives.vector.storage.DenseVectorStorage;
 
 /**
  * Basic implementation for vector.
index 8b3a274..673ad79 100644 (file)
@@ -22,11 +22,11 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Spliterator;
 import java.util.function.Consumer;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.AbstractVector;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.storage.SparseVectorStorage;
 
 /**
index 5342a22..c5d689e 100644 (file)
 package org.apache.ignite.ml.math.primitives.vector.impl;
 
 import java.io.Externalizable;
+import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.vector.AbstractVector;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorStorage;
-import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
-import org.apache.ignite.ml.math.primitives.vector.AbstractVector;
 import org.apache.ignite.ml.math.primitives.vector.storage.VectorViewStorage;
 
 /**
index 26f7b03..5990567 100644 (file)
@@ -20,10 +20,10 @@ package org.apache.ignite.ml.math.primitives.vector.impl;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.vector.AbstractVector;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.storage.VectorizedViewMatrixStorage;
 
 /**
index 919301f..970e30b 100644 (file)
@@ -20,9 +20,9 @@ package org.apache.ignite.ml.math.primitives.vector.storage;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import org.apache.ignite.ml.math.exceptions.IndexException;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.vector.VectorStorage;
-import org.apache.ignite.ml.math.exceptions.IndexException;
 
 /**
  * Row, column or diagonal vector-based view of the matrix
index 0fd3cc6..e4554e9 100644 (file)
@@ -19,14 +19,14 @@ package org.apache.ignite.ml.math.util;
 
 import java.util.List;
 import org.apache.ignite.internal.util.GridArgumentCheck;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.StorageConstants;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteTriFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
-import org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix;
+import org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 
 /**
index 6588059..6727ba9 100644 (file)
@@ -27,12 +27,12 @@ import org.apache.ignite.ml.dataset.primitive.builder.context.EmptyContextBuilde
 import org.apache.ignite.ml.dataset.primitive.builder.data.SimpleLabeledDatasetDataBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
 import org.apache.ignite.ml.dataset.primitive.data.SimpleLabeledDatasetData;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.nn.architecture.MLPArchitecture;
 import org.apache.ignite.ml.nn.initializers.RandomInitializer;
 import org.apache.ignite.ml.optimization.updatecalculators.ParameterUpdateCalculator;
@@ -44,7 +44,7 @@ import org.apache.ignite.ml.util.Utils;
  *
  * @param <P> Type of model update used in this trainer.
  */
-public class MLPTrainer<P extends Serializable> implements MultiLabelDatasetTrainer<MultilayerPerceptron> {
+public class MLPTrainer<P extends Serializable> extends MultiLabelDatasetTrainer<MultilayerPerceptron> {
     /** Multilayer perceptron architecture supplier that defines layers and activators. */
     private final IgniteFunction<Dataset<EmptyContext, SimpleLabeledDatasetData>, MLPArchitecture> archSupplier;
 
index a2c2c6e..639bb44 100644 (file)
@@ -24,12 +24,13 @@ import java.util.List;
 import java.util.Random;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.ml.Model;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.Tracer;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableDoubleToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.nn.architecture.MLPArchitecture;
 import org.apache.ignite.ml.nn.architecture.TransformationLayerArchitecture;
@@ -560,4 +561,28 @@ public class MultilayerPerceptron implements Model<Matrix, Matrix>, SmoothParame
 
         return diff;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        StringBuilder builder = new StringBuilder("MultilayerPerceptron [\n");
+        if(below != null)
+            builder.append("below = \n").append(below.toString(pretty)).append("\n\n");
+        builder.append("layers = [").append(pretty ? "\n" : "");
+        for(int i = 0; i < layers.size(); i++) {
+            MLPLayer layer = layers.get(i);
+            builder.append("\tlayer").append(i).append(" = [\n");
+            if(layer.biases != null)
+                builder.append("\t\tbias = ").append(Tracer.asAscii(layer.biases, "%.4f", false)).append("\n");
+            String matrix = Tracer.asAscii(layer.weights, "%.4f").replaceAll("\n", "\n\t\t\t");
+            builder.append("\t\tweights = [\n\t\t\t").append(matrix).append("\n\t\t]");
+            builder.append("\n\t]\n");
+        }
+        builder.append("]");
+        return builder.toString();
+    }
 }
index 533bc74..2aa0437 100644 (file)
@@ -23,9 +23,6 @@ import java.io.ObjectOutput;
 import java.util.Map;
 import java.util.Spliterator;
 import org.apache.ignite.lang.IgniteUuid;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.functions.IgniteBiConsumer;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
@@ -33,7 +30,10 @@ import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
 import org.apache.ignite.ml.math.functions.IgniteTriFunction;
 import org.apache.ignite.ml.math.functions.IntIntToDoubleFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Convenient way to create matrix of replicated columns or rows from vector.
index d328d63..741337e 100644 (file)
@@ -17,9 +17,9 @@
 
 package org.apache.ignite.ml.optimization;
 
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Class containing popular loss functions.
index 0611215..5eb8722 100644 (file)
 package org.apache.ignite.ml.optimization;
 
 import org.apache.ignite.ml.Model;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Interface for models which are smooth functions of their parameters.
index 0868d69..eb5c310 100644 (file)
 
 package org.apache.ignite.ml.optimization.updatecalculators;
 
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.optimization.SmoothParametrized;
 
 /**
index 430483a..6e6a085 100644 (file)
 package org.apache.ignite.ml.optimization.updatecalculators;
 
 import java.io.Serializable;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Interface for classes encapsulating parameters updateCache logic.
index 3a79641..17c4815 100644 (file)
 
 package org.apache.ignite.ml.optimization.updatecalculators;
 
+import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
+import org.apache.ignite.ml.math.functions.IgniteFunction;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
-import org.apache.ignite.ml.math.functions.IgniteFunction;
 import org.apache.ignite.ml.math.util.MatrixUtil;
 import org.apache.ignite.ml.optimization.SmoothParametrized;
 
index dd23911..ede85c6 100644 (file)
 
 package org.apache.ignite.ml.optimization.updatecalculators;
 
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.optimization.SmoothParametrized;
 
 /**
index e6fb0ed..8300820 100644 (file)
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.ml.preprocessing.binarization;
 
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Preprocessing function that makes binarization.
index c84b32f..26541e0 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.ignite.ml.preprocessing.binarization;
 
 import org.apache.ignite.ml.dataset.DatasetBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.PreprocessingTrainer;
 
 /**
index 46bc748..a1c5b77 100644 (file)
@@ -19,10 +19,10 @@ package org.apache.ignite.ml.preprocessing.encoding.stringencoder;
 
 import java.util.Map;
 import java.util.Set;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.exceptions.preprocessing.UnknownStringValue;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 
 /**
  * Preprocessing function that makes String encoding.
index 97cc7f8..ec16af4 100644 (file)
@@ -27,8 +27,8 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.UpstreamEntry;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.PreprocessingTrainer;
 import org.jetbrains.annotations.NotNull;
 
index 858eff4..3200d23 100644 (file)
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.ml.preprocessing.imputing;
 
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Preprocessing function that makes imputing.
index 001ef99..090b0a4 100644 (file)
@@ -25,9 +25,9 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.UpstreamEntry;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.preprocessing.PreprocessingTrainer;
 
 /**
index 7c27306..87e369f 100644 (file)
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.ml.preprocessing.minmaxscaling;
 
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Preprocessing function that makes minmaxscaling. From mathematical point of view it's the following function which
index d927fe6..6a39236 100644 (file)
@@ -21,8 +21,8 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.UpstreamEntry;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.PreprocessingTrainer;
 
 /**
index 422ed8d..0cd0a90 100644 (file)
 
 package org.apache.ignite.ml.preprocessing.normalization;
 
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.Functions;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Preprocessing function that makes normalization.
index d48bbc6..b2dc6ed 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.ignite.ml.preprocessing.normalization;
 
 import org.apache.ignite.ml.dataset.DatasetBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.preprocessing.PreprocessingTrainer;
 
 /**
index 1114131..8c3cd8b 100644 (file)
@@ -18,9 +18,9 @@
 package org.apache.ignite.ml.regressions.linear;
 
 import java.util.Arrays;
+import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 
 /**
  * Feature extractor wrapper that adds additional column filled by 1.
index 0e9941f..8197779 100644 (file)
@@ -20,12 +20,12 @@ package org.apache.ignite.ml.regressions.linear;
 import java.util.Arrays;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.primitive.builder.data.SimpleLabeledDatasetDataBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
-import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.isolve.lsqr.AbstractLSQR;
 import org.apache.ignite.ml.math.isolve.lsqr.LSQROnHeap;
 import org.apache.ignite.ml.math.isolve.lsqr.LSQRResult;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
 
 /**
@@ -33,7 +33,7 @@ import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
  *
  * @see AbstractLSQR
  */
-public class LinearRegressionLSQRTrainer implements SingleLabelDatasetTrainer<LinearRegressionModel> {
+public class LinearRegressionLSQRTrainer extends SingleLabelDatasetTrainer<LinearRegressionModel> {
     /** {@inheritDoc} */
     @Override public <K, V> LinearRegressionModel fit(DatasetBuilder<K, V> datasetBuilder,
         IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, Double> lbExtractor) {
index 43c5b54..4d9d28e 100644 (file)
@@ -99,9 +99,14 @@ public class LinearRegressionModel implements Model<Vector, Double>, Exportable<
             return builder.toString();
         }
 
-        return "LinearRegressionModel{" +
+        return "LinearRegressionModel [" +
             "weights=" + weights +
             ", intercept=" + intercept +
-            '}';
+            ']';
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return toString();
     }
 }
index e033a98..2237c95 100644 (file)
@@ -23,9 +23,9 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
 import org.apache.ignite.ml.dataset.primitive.data.SimpleLabeledDatasetData;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.nn.Activators;
 import org.apache.ignite.ml.nn.MLPTrainer;
@@ -38,7 +38,7 @@ import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
 /**
  * Trainer of the linear regression model based on stochastic gradient descent algorithm.
  */
-public class LinearRegressionSGDTrainer<P extends Serializable> implements SingleLabelDatasetTrainer<LinearRegressionModel> {
+public class LinearRegressionSGDTrainer<P extends Serializable> extends SingleLabelDatasetTrainer<LinearRegressionModel> {
     /** Update strategy. */
     private final UpdatesStrategy<? super MultilayerPerceptron, P> updatesStgy;
 
index a5938a2..f206532 100644 (file)
@@ -192,9 +192,14 @@ public class LogisticRegressionModel implements Model<Vector, Double>, Exportabl
             return builder.toString();
         }
 
-        return "LogisticRegressionModel{" +
+        return "LogisticRegressionModel [" +
             "weights=" + weights +
             ", intercept=" + intercept +
-            '}';
+            ']';
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return toString();
     }
 }
index 8ec9a7b..840a18d 100644 (file)
@@ -23,9 +23,9 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
 import org.apache.ignite.ml.dataset.primitive.data.SimpleLabeledDatasetData;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
 import org.apache.ignite.ml.math.functions.IgniteFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.nn.Activators;
 import org.apache.ignite.ml.nn.MLPTrainer;
@@ -38,7 +38,7 @@ import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
 /**
  * Trainer of the logistic regression model based on stochastic gradient descent algorithm.
  */
-public class LogisticRegressionSGDTrainer<P extends Serializable> implements SingleLabelDatasetTrainer<LogisticRegressionModel> {
+public class LogisticRegressionSGDTrainer<P extends Serializable> extends SingleLabelDatasetTrainer<LogisticRegressionModel> {
     /** Update strategy. */
     private final UpdatesStrategy<? super MultilayerPerceptron, P> updatesStgy;
 
index 7e48a21..56d2d29 100644 (file)
@@ -89,6 +89,11 @@ public class LogRegressionMultiClassModel implements Model<Vector, Double>, Expo
         return wholeStr.toString();
     }
 
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return toString();
+    }
+
     /**
      * Adds a specific Log Regression binary classifier to the bunch of same classifiers.
      *
index 2d18107..1ed938a 100644 (file)
@@ -29,8 +29,8 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.nn.MultilayerPerceptron;
 import org.apache.ignite.ml.nn.UpdatesStrategy;
 import org.apache.ignite.ml.regressions.logistic.binomial.LogisticRegressionSGDTrainer;
@@ -42,7 +42,7 @@ import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
  * All common parameters are shared with bunch of binary classification trainers.
  */
 public class LogRegressionMultiClassTrainer<P extends Serializable>
-    implements SingleLabelDatasetTrainer<LogRegressionMultiClassModel> {
+    extends SingleLabelDatasetTrainer<LogRegressionMultiClassModel> {
     /** Update strategy. */
     private UpdatesStrategy<? super MultilayerPerceptron, P> updatesStgy;
 
index e2fbf89..f417fab 100644 (file)
@@ -27,8 +27,8 @@ import org.apache.ignite.ml.Model;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.impl.cache.CacheBasedDatasetBuilder;
 import org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.selection.scoring.cursor.CacheBasedLabelPairCursor;
 import org.apache.ignite.ml.selection.scoring.cursor.LabelPairCursor;
 import org.apache.ignite.ml.selection.scoring.cursor.LocalLabelPairCursor;
index ec8db14..037cf45 100644 (file)
@@ -24,8 +24,8 @@ import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.lang.IgniteBiPredicate;
 import org.apache.ignite.ml.Model;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.selection.scoring.LabelPair;
 import org.jetbrains.annotations.NotNull;
 
index e77608f..f135450 100644 (file)
@@ -22,8 +22,8 @@ import java.util.Map;
 import java.util.NoSuchElementException;
 import org.apache.ignite.lang.IgniteBiPredicate;
 import org.apache.ignite.ml.Model;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.selection.scoring.LabelPair;
 import org.jetbrains.annotations.NotNull;
 
index 9620897..4535831 100644 (file)
@@ -20,8 +20,8 @@ package org.apache.ignite.ml.selection.scoring.evaluator;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.lang.IgniteBiPredicate;
 import org.apache.ignite.ml.Model;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.selection.scoring.cursor.CacheBasedLabelPairCursor;
 import org.apache.ignite.ml.selection.scoring.cursor.LabelPairCursor;
 import org.apache.ignite.ml.selection.scoring.metric.Accuracy;
index 2968850..2440587 100644 (file)
 
 package org.apache.ignite.ml.structures;
 
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.exceptions.NoDataException;
 import org.apache.ignite.ml.math.exceptions.knn.NoLabelVectorException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 
 /**
index a7fae03..b4e552b 100644 (file)
@@ -21,8 +21,8 @@ import java.io.Serializable;
 import java.util.Iterator;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.UpstreamEntry;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledVector;
 
index 60ae0f8..5c20d9c 100644 (file)
@@ -23,11 +23,11 @@ import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Stream;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.exceptions.NoDataException;
 import org.apache.ignite.ml.math.exceptions.knn.EmptyFileException;
 import org.apache.ignite.ml.math.exceptions.knn.FileParsingException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledVector;
 import org.jetbrains.annotations.NotNull;
index f0cdbea..4771e4a 100644 (file)
@@ -181,9 +181,14 @@ public class SVMLinearBinaryClassificationModel implements Model<Vector, Double>
             return builder.toString();
         }
 
-        return "SVMModel{" +
+        return "SVMModel [" +
             "weights=" + weights +
             ", intercept=" + intercept +
-            '}';
+            ']';
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return toString();
     }
 }
index 53bb99f..1ae896f 100644 (file)
@@ -22,8 +22,8 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledVector;
@@ -37,7 +37,7 @@ import org.jetbrains.annotations.NotNull;
  * and +1 labels for two classes and makes binary classification. </p> The paper about this algorithm could be found
  * here https://arxiv.org/abs/1409.1458.
  */
-public class SVMLinearBinaryClassificationTrainer implements SingleLabelDatasetTrainer<SVMLinearBinaryClassificationModel> {
+public class SVMLinearBinaryClassificationTrainer extends SingleLabelDatasetTrainer<SVMLinearBinaryClassificationModel> {
     /** Amount of outer SDCA algorithm iterations. */
     private int amountOfIterations = 200;
 
index 3765110..4b04824 100644 (file)
@@ -88,6 +88,11 @@ public class SVMLinearMultiClassClassificationModel implements Model<Vector, Dou
         return wholeStr.toString();
     }
 
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return toString();
+    }
+
     /**
      * Adds a specific SVM binary classifier to the bunch of same classifiers.
      *
index b571d0f..7069c4d 100644 (file)
@@ -28,8 +28,8 @@ import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.partition.LabelPartitionDataBuilderOnHeap;
 import org.apache.ignite.ml.structures.partition.LabelPartitionDataOnHeap;
 import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
@@ -41,7 +41,7 @@ import org.apache.ignite.ml.trainers.SingleLabelDatasetTrainer;
  * All common parameters are shared with bunch of binary classification trainers.
  */
 public class SVMLinearMultiClassClassificationTrainer
-    implements SingleLabelDatasetTrainer<SVMLinearMultiClassClassificationModel> {
+    extends SingleLabelDatasetTrainer<SVMLinearMultiClassClassificationModel> {
     /** Amount of outer SDCA algorithm iterations. */
     private int amountOfIterations = 20;
 
index 3fe0aa4..2f5d5d6 100644 (file)
@@ -25,8 +25,9 @@ import org.apache.ignite.ml.Model;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.impl.cache.CacheBasedDatasetBuilder;
 import org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.environment.LearningEnvironment;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * Interface for trainers. Trainer is just a function which produces model from the data.
@@ -34,7 +35,10 @@ import org.apache.ignite.ml.math.functions.IgniteBiFunction;
  * @param <M> Type of a produced model.
  * @param <L> Type of a label.
  */
-public interface DatasetTrainer<M extends Model, L> {
+public abstract class DatasetTrainer<M extends Model, L> {
+    /** Learning Environment. */
+    protected LearningEnvironment environment = LearningEnvironment.DEFAULT;
+
     /**
      * Trains model based on the specified data.
      *
@@ -45,7 +49,7 @@ public interface DatasetTrainer<M extends Model, L> {
      * @param <V> Type of a value in {@code upstream} data.
      * @return Model.
      */
-    public <K, V> M fit(DatasetBuilder<K, V> datasetBuilder, IgniteBiFunction<K, V, Vector> featureExtractor,
+    public abstract <K, V> M fit(DatasetBuilder<K, V> datasetBuilder, IgniteBiFunction<K, V, Vector> featureExtractor,
         IgniteBiFunction<K, V, L> lbExtractor);
 
     /**
@@ -59,7 +63,7 @@ public interface DatasetTrainer<M extends Model, L> {
      * @param <V> Type of a value in {@code upstream} data.
      * @return Model.
      */
-    public default <K, V> M fit(Ignite ignite, IgniteCache<K, V> cache,
+    public <K, V> M fit(Ignite ignite, IgniteCache<K, V> cache,
         IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, L> lbExtractor) {
         return fit(
             new CacheBasedDatasetBuilder<>(ignite, cache),
@@ -80,7 +84,7 @@ public interface DatasetTrainer<M extends Model, L> {
      * @param <V> Type of a value in {@code upstream} data.
      * @return Model.
      */
-    public default <K, V> M fit(Ignite ignite, IgniteCache<K, V> cache, IgniteBiPredicate<K, V> filter,
+    public <K, V> M fit(Ignite ignite, IgniteCache<K, V> cache, IgniteBiPredicate<K, V> filter,
         IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, L> lbExtractor) {
         return fit(
             new CacheBasedDatasetBuilder<>(ignite, cache, filter),
@@ -100,7 +104,7 @@ public interface DatasetTrainer<M extends Model, L> {
      * @param <V> Type of a value in {@code upstream} data.
      * @return Model.
      */
-    public default <K, V> M fit(Map<K, V> data, int parts, IgniteBiFunction<K, V, Vector> featureExtractor,
+    public <K, V> M fit(Map<K, V> data, int parts, IgniteBiFunction<K, V, Vector> featureExtractor,
         IgniteBiFunction<K, V, L> lbExtractor) {
         return fit(
             new LocalDatasetBuilder<>(data, parts),
@@ -121,7 +125,7 @@ public interface DatasetTrainer<M extends Model, L> {
      * @param <V> Type of a value in {@code upstream} data.
      * @return Model.
      */
-    public default <K, V> M fit(Map<K, V> data, IgniteBiPredicate<K, V> filter, int parts,
+    public <K, V> M fit(Map<K, V> data, IgniteBiPredicate<K, V> filter, int parts,
         IgniteBiFunction<K, V, Vector> featureExtractor,
         IgniteBiFunction<K, V, L> lbExtractor) {
         return fit(
@@ -130,4 +134,12 @@ public interface DatasetTrainer<M extends Model, L> {
             lbExtractor
         );
     }
+
+    /**
+     * Sets learning Environment
+     * @param environment Environment.
+     */
+    public void setEnvironment(LearningEnvironment environment) {
+        this.environment = environment;
+    }
 }
index 0c6518f..5ae7de8 100644 (file)
@@ -24,5 +24,5 @@ import org.apache.ignite.ml.Model;
  *
  * @param <M> Type of a produced model.
  */
-public interface MultiLabelDatasetTrainer<M extends Model> extends DatasetTrainer<M, double[]> {
+public abstract class MultiLabelDatasetTrainer<M extends Model> extends DatasetTrainer<M, double[]> {
 }
index eec8855..38dda93 100644 (file)
@@ -24,5 +24,5 @@ import org.apache.ignite.ml.Model;
  *
  * @param <M> Type of a produced model.
  */
-public interface SingleLabelDatasetTrainer<M extends Model> extends DatasetTrainer<M, Double> {
+public abstract class SingleLabelDatasetTrainer<M extends Model> extends DatasetTrainer<M, Double> {
 }
index 9a912f7..c94d2dd 100644 (file)
@@ -19,12 +19,13 @@ package org.apache.ignite.ml.tree;
 
 import java.io.Serializable;
 import java.util.Arrays;
+import java.util.Collections;
 import org.apache.ignite.ml.dataset.Dataset;
 import org.apache.ignite.ml.dataset.DatasetBuilder;
 import org.apache.ignite.ml.dataset.primitive.builder.context.EmptyContextBuilder;
 import org.apache.ignite.ml.dataset.primitive.context.EmptyContext;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.trainers.DatasetTrainer;
 import org.apache.ignite.ml.tree.data.DecisionTreeData;
 import org.apache.ignite.ml.tree.data.DecisionTreeDataBuilder;
@@ -39,7 +40,7 @@ import org.apache.ignite.ml.tree.leaf.DecisionTreeLeafBuilder;
  *
  * @param <T> Type of impurity measure.
  */
-public abstract class DecisionTree<T extends ImpurityMeasure<T>> implements DatasetTrainer<DecisionTreeNode, Double> {
+public abstract class DecisionTree<T extends ImpurityMeasure<T>> extends DatasetTrainer<DecisionTreeNode, Double> {
     /** Max tree deep. */
     private final int maxDeep;
 
@@ -60,7 +61,8 @@ public abstract class DecisionTree<T extends ImpurityMeasure<T>> implements Data
      * @param compressor Impurity function compressor.
      * @param decisionTreeLeafBuilder Decision tree leaf builder.
      */
-    DecisionTree(int maxDeep, double minImpurityDecrease, StepFunctionCompressor<T> compressor, DecisionTreeLeafBuilder decisionTreeLeafBuilder) {
+    DecisionTree(int maxDeep, double minImpurityDecrease, StepFunctionCompressor<T> compressor,
+        DecisionTreeLeafBuilder decisionTreeLeafBuilder) {
         this.maxDeep = maxDeep;
         this.minImpurityDecrease = minImpurityDecrease;
         this.compressor = compressor;
@@ -131,7 +133,8 @@ public abstract class DecisionTree<T extends ImpurityMeasure<T>> implements Data
      */
     private StepFunction<T>[] calculateImpurityForAllColumns(Dataset<EmptyContext, DecisionTreeData> dataset,
         TreeFilter filter, ImpurityMeasureCalculator<T> impurityCalc) {
-        return dataset.compute(
+
+        StepFunction<T>[] result = dataset.compute(
             part -> {
                 if (compressor != null)
                     return compressor.compress(impurityCalc.calculate(part.filter(filter)));
@@ -139,6 +142,8 @@ public abstract class DecisionTree<T extends ImpurityMeasure<T>> implements Data
                     return impurityCalc.calculate(part.filter(filter));
             }, this::reduce
         );
+
+        return result;
     }
 
     /**
@@ -250,4 +255,47 @@ public abstract class DecisionTree<T extends ImpurityMeasure<T>> implements Data
             this.threshold = threshold;
         }
     }
+
+    /**
+     * Represents DecisionTree as String.
+     *
+     * @param node Decision tree.
+     * @param pretty Use pretty mode.
+     */
+    public static String printTree(DecisionTreeNode node, boolean pretty) {
+        StringBuilder builder = new StringBuilder();
+        printTree(node, 0, builder, pretty, false);
+        return builder.toString();
+    }
+
+    /**
+     * Recursive realisation of DectisionTree to String converting.
+     *
+     * @param node Decision tree.
+     * @param depth Current depth.
+     * @param builder String builder.
+     * @param pretty Use pretty mode.
+     */
+    private static void printTree(DecisionTreeNode node, int depth, StringBuilder builder, boolean pretty, boolean isThen) {
+        builder.append(pretty ? String.join("", Collections.nCopies(depth, "\t")) : "");
+        if (node instanceof DecisionTreeLeafNode) {
+            DecisionTreeLeafNode leaf = (DecisionTreeLeafNode)node;
+            builder.append(String.format("%s return ", isThen ? "then" : "else"))
+                .append(String.format("%.4f", leaf.getVal()));
+        }
+        else if (node instanceof DecisionTreeConditionalNode) {
+            DecisionTreeConditionalNode condition = (DecisionTreeConditionalNode)node;
+            String prefix = depth == 0 ? "" : (isThen ? "then " : "else ");
+            builder.append(String.format("%sif (x", prefix))
+                .append(condition.getCol())
+                .append(" > ")
+                .append(String.format("%.4f", condition.getThreshold()))
+                .append(pretty ? ")\n" : ") ");
+            printTree(condition.getThenNode(), depth + 1, builder, pretty, true);
+            builder.append(pretty ? "\n" : " ");
+            printTree(condition.getElseNode(), depth + 1, builder, pretty, false);
+        }
+        else
+            throw new IllegalArgumentException();
+    }
 }
index 110c199..f598165 100644 (file)
@@ -77,4 +77,14 @@ public class DecisionTreeConditionalNode implements DecisionTreeNode {
     public DecisionTreeNode getElseNode() {
         return elseNode;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return DecisionTree.printTree(this, pretty);
+    }
 }
index 7194511..97cc3ee 100644 (file)
@@ -47,4 +47,14 @@ public class DecisionTreeLeafNode implements DecisionTreeNode {
     public double getVal() {
         return val;
     }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return toString(false);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString(boolean pretty) {
+        return DecisionTree.printTree(this, pretty);
+    }
 }
index 9f8f2f7..0ff2012 100644 (file)
@@ -21,8 +21,8 @@ import java.io.Serializable;
 import java.util.Iterator;
 import org.apache.ignite.ml.dataset.PartitionDataBuilder;
 import org.apache.ignite.ml.dataset.UpstreamEntry;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteBiFunction;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 
 /**
  * A partition {@code data} builder that makes {@link DecisionTreeData}.
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/util/ModelTrace.java b/modules/ml/src/main/java/org/apache/ignite/ml/util/ModelTrace.java
new file mode 100644 (file)
index 0000000..e6539d2
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Helper for model tracing.
+ */
+public class ModelTrace {
+    /** Model name. */
+    private final String mdlName;
+    /** Use pretty mode. */
+    private final boolean pretty;
+    /** Model fields. */
+    private List<IgniteBiTuple<String, Object>> mdlFields = new ArrayList<>();
+
+    /**
+     * Creates an instance of ModelTrace.
+     *
+     * @param mdlName Model name.
+     * @param pretty Pretty.
+     */
+    public static ModelTrace builder(String mdlName, boolean pretty) {
+        return new ModelTrace(mdlName, pretty);
+    }
+
+    /**
+     * Creates an instance of ModelTrace.
+     *
+     * @param mdlName Model name.
+     */
+    public static ModelTrace builder(String mdlName) {
+        return new ModelTrace(mdlName, false);
+    }
+
+    /**
+     * Creates an instance of ModelTrace.
+     *
+     * @param mdlName Model name.
+     * @param pretty Pretty.
+     */
+    private ModelTrace(String mdlName, boolean pretty) {
+        this.mdlName = mdlName;
+        this.pretty = pretty;
+    }
+
+    /**
+     * Add field.
+     *
+     * @param name Name.
+     * @param value Value.
+     */
+    public ModelTrace addField(String name, String value) {
+        mdlFields.add(new IgniteBiTuple<>(name, value));
+        return this;
+    }
+
+    /**
+     * Add field.
+     *
+     * @param name Name.
+     * @param values Values.
+     */
+    public ModelTrace addField(String name, List values) {
+        mdlFields.add(new IgniteBiTuple<>(name, values));
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        StringBuilder builder = new StringBuilder();
+
+        final String ending = pretty ? "\n" : "";
+        final String fields = mdlFields.stream()
+            .map(kv -> fieldToString(kv, pretty))
+            .collect(Collectors.joining(pretty ? ",\n" : ", "));
+
+        builder.append(mdlName)
+            .append(" [").append(ending)
+            .append(fields)
+            .append(ending).append("]");
+
+        return builder.toString();
+    }
+
+    /**
+     * Convert Field Name-Value pair to string.
+     *
+     * @param kv Field name and value.
+     * @param pretty Use pretty mode.
+     */
+    @NotNull private String fieldToString(IgniteBiTuple<String, Object> kv, boolean pretty) {
+        StringBuilder builder = new StringBuilder(pretty ? "\t" : "")
+            .append(kv.getKey()).append(" = [");
+        if (kv.getValue() instanceof List) {
+            List list = (List)kv.getValue();
+            builder
+                .append(pretty ? "\n" : "")
+                .append(list.stream()
+                    .map(x -> (pretty ? "\t\t" : "") + x)
+                    .collect(Collectors.joining(pretty ? ",\n" : ", ")))
+                .append(pretty ? "\n\t]" : "]");
+        }
+        else {
+            builder.append(kv.getValue().toString())
+                .append("]");
+        }
+        return builder.toString();
+    }
+}
index 43a80a9..3e3bab5 100644 (file)
@@ -31,8 +31,8 @@ import org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder;
 import org.apache.ignite.ml.knn.classification.KNNClassificationModel;
 import org.apache.ignite.ml.knn.classification.KNNModelFormat;
 import org.apache.ignite.ml.knn.classification.KNNStrategy;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.distances.EuclideanDistance;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.regressions.linear.LinearRegressionModel;
 import org.apache.ignite.ml.svm.SVMLinearBinaryClassificationModel;
index 64e3436..a4591fb 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.ignite.ml;
 
 import java.util.stream.IntStream;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.Precision;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.junit.Assert;
 
index 611b526..0d95d05 100644 (file)
@@ -18,9 +18,9 @@
 package org.apache.ignite.ml.clustering;
 
 import org.apache.ignite.ml.clustering.kmeans.KMeansModel;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.distances.DistanceMeasure;
 import org.apache.ignite.ml.math.distances.EuclideanDistance;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.junit.Assert;
 import org.junit.Test;
index 0bb4e01..8d2c341 100644 (file)
@@ -23,9 +23,9 @@ import java.util.Map;
 import org.apache.ignite.ml.clustering.kmeans.KMeansModel;
 import org.apache.ignite.ml.clustering.kmeans.KMeansTrainer;
 import org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder;
+import org.apache.ignite.ml.math.distances.EuclideanDistance;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.distances.EuclideanDistance;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.junit.Test;
 
index 979e1e4..d931260 100644 (file)
@@ -27,12 +27,11 @@ import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
 import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
 import org.junit.After;
-
-import static org.junit.Assert.*;
-
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+
 /**
  * Calculate Fitness Test
  */
index 28b0196..168b2e8 100644 (file)
@@ -27,12 +27,11 @@ import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
 import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
 import org.junit.After;
-
-import static org.junit.Assert.*;
-
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+
 /**
  * Initialize Gene and Chromosome Test
  */
index 569a887..ab1ecee 100644 (file)
@@ -25,9 +25,9 @@ import java.util.Map;
 import org.apache.ignite.ml.knn.classification.KNNClassificationModel;
 import org.apache.ignite.ml.knn.classification.KNNClassificationTrainer;
 import org.apache.ignite.ml.knn.classification.KNNStrategy;
+import org.apache.ignite.ml.math.distances.EuclideanDistance;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.distances.EuclideanDistance;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.junit.Test;
 import org.junit.runner.RunWith;
index d02d72a..586e6c8 100644 (file)
@@ -26,9 +26,9 @@ import org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder;
 import org.apache.ignite.ml.knn.classification.KNNStrategy;
 import org.apache.ignite.ml.knn.regression.KNNRegressionModel;
 import org.apache.ignite.ml.knn.regression.KNNRegressionTrainer;
+import org.apache.ignite.ml.math.distances.EuclideanDistance;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
-import org.apache.ignite.ml.math.distances.EuclideanDistance;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.junit.Assert;
 import org.junit.Test;
index 8ced650..a029e49 100644 (file)
@@ -22,11 +22,11 @@ import java.net.URISyntaxException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import org.apache.ignite.ml.math.ExternalizableTest;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.exceptions.NoDataException;
 import org.apache.ignite.ml.math.exceptions.knn.EmptyFileException;
 import org.apache.ignite.ml.math.exceptions.knn.FileParsingException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.structures.LabeledDataset;
 import org.apache.ignite.ml.structures.LabeledDatasetTestTrainPair;
 import org.apache.ignite.ml.structures.LabeledVector;
index a5e47a4..61bde69 100644 (file)
@@ -22,9 +22,9 @@ import java.util.function.BiPredicate;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.junit.Assert;
 import org.junit.Test;
 
index d917f61..b76a4c2 100644 (file)
 package org.apache.ignite.ml.math;
 
 import org.apache.ignite.ml.math.distances.DistanceTest;
+import org.apache.ignite.ml.math.isolve.lsqr.LSQROnHeapTest;
 import org.apache.ignite.ml.math.primitives.matrix.DenseMatrixConstructorTest;
+import org.apache.ignite.ml.math.primitives.matrix.MatrixArrayStorageTest;
 import org.apache.ignite.ml.math.primitives.matrix.MatrixAttributeTest;
+import org.apache.ignite.ml.math.primitives.matrix.MatrixStorageImplementationTest;
 import org.apache.ignite.ml.math.primitives.matrix.MatrixViewConstructorTest;
 import org.apache.ignite.ml.math.primitives.matrix.SparseMatrixConstructorTest;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixArrayStorageTest;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixStorageImplementationTest;
-import org.apache.ignite.ml.math.primitives.vector.VectorArrayStorageTest;
 import org.apache.ignite.ml.math.primitives.vector.AbstractVectorTest;
 import org.apache.ignite.ml.math.primitives.vector.DelegatingVectorConstructorTest;
 import org.apache.ignite.ml.math.primitives.vector.DenseVectorConstructorTest;
 import org.apache.ignite.ml.math.primitives.vector.MatrixVectorViewTest;
 import org.apache.ignite.ml.math.primitives.vector.SparseVectorConstructorTest;
+import org.apache.ignite.ml.math.primitives.vector.VectorArrayStorageTest;
 import org.apache.ignite.ml.math.primitives.vector.VectorAttributesTest;
 import org.apache.ignite.ml.math.primitives.vector.VectorFoldMapTest;
 import org.apache.ignite.ml.math.primitives.vector.VectorNormTest;
 import org.apache.ignite.ml.math.primitives.vector.VectorToMatrixTest;
 import org.apache.ignite.ml.math.primitives.vector.VectorViewTest;
-import org.apache.ignite.ml.math.isolve.lsqr.LSQROnHeapTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
index a164daf..1b78390 100644 (file)
@@ -27,8 +27,8 @@ import java.util.Optional;
 import org.apache.ignite.ml.math.primitives.MathTestConstants;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
-import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.Vector;
+import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.junit.Test;
 
 import static java.nio.file.Files.createTempFile;
index d488ac9..499a457 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.ignite.ml.math.primitives.matrix;
 
 import org.apache.ignite.ml.math.ExternalizeTest;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 import org.apache.ignite.ml.math.primitives.MathTestConstants;
 import org.junit.After;
 import org.junit.Assert;
index 2674c0a..cadf9fe 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.function.BiConsumer;
 import java.util.function.Supplier;
-import org.apache.ignite.ml.math.primitives.matrix.MatrixStorage;
 import org.apache.ignite.ml.math.StorageConstants;
 import org.apache.ignite.ml.math.primitives.matrix.storage.SparseMatrixStorage;
 import org.jetbrains.annotations.NotNull;
index 2550c6f..bfc9557 100644 (file)
@@ -19,10 +19,10 @@ package org.apache.ignite.ml.math.primitives.vector;
 
 import java.util.Arrays;
 import java.util.stream.StreamSupport;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.exceptions.IndexException;
 import org.apache.ignite.ml.math.functions.Functions;
 import org.apache.ignite.ml.math.primitives.MathTestConstants;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.vector.storage.DenseVectorStorage;
 import org.junit.Assert;
 import org.junit.Before;
index f5033e3..6b44c38 100644 (file)
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.ml.math.primitives.vector;
 
-import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
+import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
index b978729..922a1ef 100644 (file)
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.ml.math.primitives.vector;
 
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.exceptions.IndexException;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
 import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;
 import org.junit.Before;
index 691eeb1..7f7b31c 100644 (file)
@@ -21,9 +21,9 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.function.Function;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
-import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;
 import org.junit.Test;
 
index b6c9721..64c93ac 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.ignite.ml.math.primitives.vector;
 
 import org.apache.ignite.ml.math.ExternalizeTest;
-import org.apache.ignite.ml.math.primitives.vector.VectorStorage;
 import org.apache.ignite.ml.math.primitives.MathTestConstants;
 import org.junit.After;
 import org.junit.Before;
index 549a5f8..d87478b 100644 (file)
@@ -29,12 +29,12 @@ import java.util.function.BiFunction;
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.Supplier;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
-import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;
 import org.jetbrains.annotations.NotNull;
 
index 27fffb0..48e536e 100644 (file)
@@ -27,9 +27,9 @@ import org.apache.ignite.IgniteException;
 import org.apache.ignite.ml.math.ExternalizeTest;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
 import org.apache.ignite.ml.math.exceptions.UnsupportedOperationException;
+import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
-import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;
 import org.junit.Assert;
 import org.junit.Test;
index 09733b8..01ab049 100644 (file)
@@ -22,10 +22,10 @@ import java.util.Map;
 import java.util.function.BiConsumer;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
-import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.math.primitives.matrix.impl.SparseMatrix;
-import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector;
+import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
+import org.apache.ignite.ml.math.primitives.vector.impl.SparseVector;
 import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;
 import org.junit.Test;
 
index 5c09e43..51620b7 100644 (file)
 package org.apache.ignite.ml.nn;
 
 import org.apache.ignite.ml.TestUtils;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.functions.IgniteTriFunction;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.nn.architecture.MLPArchitecture;
 import org.apache.ignite.ml.optimization.LossFunctions;
index 27ddc6d..3521cb6 100644 (file)
@@ -25,10 +25,10 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.ml.TestUtils;
-import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
+import org.apache.ignite.ml.math.primitives.matrix.Matrix;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.nn.architecture.MLPArchitecture;
 import org.apache.ignite.ml.optimization.LossFunctions;
index 5e61fe6..a1d601c 100644 (file)
@@ -24,8 +24,8 @@ import java.util.List;
 import java.util.Map;
 import org.apache.ignite.ml.TestUtils;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.nn.architecture.MLPArchitecture;
 import org.apache.ignite.ml.optimization.LossFunctions;
index e11a829..bd31b19 100644 (file)
@@ -24,8 +24,8 @@ import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.nn.Activators;
 import org.apache.ignite.ml.nn.MLPTrainer;
 import org.apache.ignite.ml.nn.MultilayerPerceptron;
index e2c905f..6a17d18 100644 (file)
@@ -21,8 +21,8 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.ignite.ml.math.primitives.matrix.Matrix;
-import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
 import org.apache.ignite.ml.nn.Activators;
 import org.apache.ignite.ml.nn.MLPTrainer;
 import org.apache.ignite.ml.nn.MultilayerPerceptron;
index d5af7f3..71d831d 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.ignite.ml.regressions.linear;
 
 import org.apache.ignite.ml.TestUtils;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.regressions.logistic.binomial.LogisticRegressionModel;
 import org.apache.ignite.ml.regressions.logistic.multiclass.LogRegressionMultiClassModel;
index 679bd50..bb6a77d 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.ignite.ml.regressions.logistic;
 
 import org.apache.ignite.ml.TestUtils;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.regressions.logistic.binomial.LogisticRegressionModel;
 import org.junit.Test;
index e88e16e..9244c35 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.ignite.ml.svm;
 
 import org.apache.ignite.ml.TestUtils;
-import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.exceptions.CardinalityException;
+import org.apache.ignite.ml.math.primitives.vector.Vector;
 import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
 import org.apache.ignite.ml.regressions.linear.LinearRegressionModel;
 import org.junit.Assert;