You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/04/27 15:03:00 UTC

[25/28] ignite git commit: IGNITE-5040: ML examples: restored missed changes. This closes #1881.

IGNITE-5040: ML examples: restored missed changes. This closes #1881.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/cec602fe
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/cec602fe
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/cec602fe

Branch: refs/heads/ignite-5075-cacheStart
Commit: cec602fe7252fda8ae334d3a7331479ab8a9341a
Parents: 3dac1fe
Author: YuriBabak <y....@gmail.com>
Authored: Thu Apr 27 16:52:05 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Thu Apr 27 16:52:05 2017 +0300

----------------------------------------------------------------------
 .../ml/math/matrix/CacheMatrixExample.java      | 23 +++++---
 .../ml/math/matrix/ExampleMatrixStorage.java    |  3 +-
 .../math/matrix/MatrixCustomStorageExample.java |  6 +--
 .../examples/ml/math/matrix/MatrixExample.java  |  4 +-
 .../ml/math/matrix/OffHeapMatrixExample.java    |  6 +--
 .../matrix/SparseDistributedMatrixExample.java  |  8 ++-
 .../ml/math/matrix/SparseMatrixExample.java     |  4 +-
 .../examples/ml/math/tracer/TracerExample.java  |  2 +-
 .../ml/math/vector/CacheVectorExample.java      | 19 ++++---
 .../ml/math/vector/ExampleVectorStorage.java    |  7 +--
 .../ml/math/vector/OffHeapVectorExample.java    |  2 +-
 .../ml/math/vector/SparseVectorExample.java     |  4 --
 .../math/vector/VectorCustomStorageExample.java |  4 --
 .../examples/ml/math/vector/VectorExample.java  |  6 +--
 .../java/org/apache/ignite/ml/math/Tracer.java  | 57 +++++++++++---------
 15 files changed, 87 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
index ec414e5..d7bb8ae 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
@@ -21,13 +21,26 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.examples.ml.math.vector.CacheVectorExample;
 import org.apache.ignite.ml.math.IdentityValueMapper;
 import org.apache.ignite.ml.math.MatrixKeyMapper;
+import org.apache.ignite.ml.math.Tracer;
 import org.apache.ignite.ml.math.ValueMapper;
 import org.apache.ignite.ml.math.functions.Functions;
 import org.apache.ignite.ml.math.impls.matrix.CacheMatrix;
 
-/** */
+/**
+ *  Example that demonstrates how to use {@link CacheMatrix}.
+ *
+ *  Basically CacheMatrix is view over existing data in cache. So we have {@link MatrixKeyMapper} and {@link ValueMapper}
+ *  for this purpose. A {@link MatrixKeyMapper} allows us to map matrix indices to cache keys. And a {@link ValueMapper}
+ *  allows us map cache object to matrix elements - doubles.
+ *
+ *  In this example we use simple flat mapping for keys and {@link IdentityValueMapper} for cache objects
+ *  because they are Doubles.
+ *
+ *  @see CacheVectorExample
+ */
 public class CacheMatrixExample {
     /** */ private static final String CACHE_NAME = CacheMatrixExample.class.getSimpleName();
     /** */ private static final int ROWS = 3;
@@ -68,6 +81,8 @@ public class CacheMatrixExample {
 
                 cacheMatrix.assign(testValues);
 
+                Tracer.showAscii(cacheMatrix);
+
                 // Find all positive elements.
                 Integer nonZeroes = cacheMatrix.foldMap((o, aDouble) -> {
                     if (aDouble > 0)
@@ -75,17 +90,13 @@ public class CacheMatrixExample {
                     return o;
                 }, Functions.IDENTITY, 0);
 
-                assert nonZeroes.equals(6);
+                System.out.println("Quantity of non zeroes elements is " + nonZeroes.intValue());
 
                 System.out.println(">>>");
                 System.out.println(">>> Finished executing Ignite \"CacheMatrix\" example.");
                 System.out.println(">>> Lower triangular matrix 3x3 have only 6 positive elements.");
                 System.out.println(">>>");
             }
-            finally {
-                // Distributed cache could be removed from cluster only by #destroyCache() call.
-                ignite.destroyCache(CACHE_NAME);
-            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
index 5fb06d7..5dedfbf 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
@@ -23,9 +23,10 @@ import java.io.ObjectOutput;
 import java.util.Arrays;
 
 import org.apache.ignite.ml.math.MatrixStorage;
+import org.apache.ignite.ml.math.impls.storage.matrix.ArrayMatrixStorage;
 
 /**
- * Example matrix storage, modeled after {@link org.apache.ignite.ml.math.impls.storage.matrix.ArrayMatrixStorage}.
+ * Example matrix storage implementation, modeled after {@link ArrayMatrixStorage}.
  */
 class ExampleMatrixStorage implements MatrixStorage {
     /** Backing data array. */

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
index 76716cc..3b4f27d 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
@@ -24,7 +24,7 @@ import org.apache.ignite.ml.math.impls.matrix.AbstractMatrix;
 import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
 
 /**
- * This example shows how to use {@link Matrix} API based on custom {@link MatrixStorage}.
+ * This example shows how to create custom {@link Matrix} based on custom {@link MatrixStorage}.
  */
 public final class MatrixCustomStorageExample {
     /**
@@ -74,8 +74,8 @@ public final class MatrixCustomStorageExample {
         System.out.println(">>> Matrix product determinant: [" + detMult
             + "], equals product of two other matrices determinants: [" + detMultIsAsExp + "].");
 
-        assert detMultIsAsExp : "Determinant of product matrix [" + detMult
-            + "] should be equal to product of determinants [" + (det1 * det2) + "].";
+        System.out.println("Determinant of product matrix [" + detMult
+            + "] should be equal to product of determinants [" + (det1 * det2) + "].");
 
         System.out.println("\n>>> Matrix API usage example completed.");
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
index 66db374..755f36c 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
@@ -71,8 +71,8 @@ public final class MatrixExample {
         System.out.println(">>> Matrix product determinant: [" + detMult
             + "], equals product of two other matrices determinants: [" + detMultIsAsExp + "].");
 
-        assert detMultIsAsExp : "Determinant of product matrix [" + detMult
-            + "] should be equal to product of determinants [" + (det1 * det2) + "].";
+        System.out.println("Determinant of product matrix [" + detMult
+            + "] should be equal to product of determinants [" + (det1 * det2) + "].");
 
         System.out.println("\n>>> Basic Matrix API usage example completed.");
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
index f743bd9..db01794 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
@@ -21,7 +21,7 @@ import org.apache.ignite.ml.math.Matrix;
 import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix;
 
 /**
- * This example shows how to use off-heap {@link Matrix} API.
+ * This example shows how to create and use off-heap versions of {@link Matrix}.
  */
 public final class OffHeapMatrixExample {
     /**
@@ -76,8 +76,8 @@ public final class OffHeapMatrixExample {
         System.out.println(">>> Matrix product determinant: [" + detMult
             + "], equals product of two other matrices determinants: [" + detMultIsAsExp + "].");
 
-        assert detMultIsAsExp : "Determinant of product matrix [" + detMult
-            + "] should be equal to product of determinants [" + (det1 * det2) + "].";
+        System.out.println("Determinant of product matrix [" + detMult
+            + "] should be equal to product of determinants [" + (det1 * det2) + "].");
 
         System.out.println("\n>>> Off-heap matrix API usage example completed.");
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
index 1e5f099..c73a8a0 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
@@ -19,12 +19,16 @@ package org.apache.ignite.examples.ml.math.matrix;
 
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.ml.math.Matrix;
 import org.apache.ignite.ml.math.StorageConstants;
+import org.apache.ignite.ml.math.impls.matrix.CacheMatrix;
 import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix;
 import org.apache.ignite.thread.IgniteThread;
 
 /**
- * This example shows how to use {@link SparseDistributedMatrix} API.
+ * This example shows how to create and use {@link SparseDistributedMatrix} API.
+ *
+ * Unlike the {@link CacheMatrix} the {@link SparseDistributedMatrix} creates it's own cache.
  */
 public class SparseDistributedMatrixExample {
     /**
@@ -51,7 +55,7 @@ public class SparseDistributedMatrixExample {
 
                 distributedMatrix.assign(testValues);
 
-                assert distributedMatrix.sum() == 3.0;
+                System.out.println("Sum of all matrix elements is " + distributedMatrix.sum());
 
                 System.out.println(">>> Destroy SparseDistributedMatrix after using.");
                 // Destroy internal cache.

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
index d3715ea..a03688d 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
@@ -76,8 +76,8 @@ public final class SparseMatrixExample {
         System.out.println(">>> Matrix product determinant: [" + detMult
             + "], equals product of two other matrices determinants: [" + detMultIsAsExp + "].");
 
-        assert detMultIsAsExp : "Determinant of product matrix [" + detMult
-            + "] should be equal to product of determinants [" + (det1 * det2) + "].";
+        System.out.println("Determinant of product matrix [" + detMult
+            + "] should be equal to product of determinants [" + (det1 * det2) + "].");
 
         System.out.println("\n>>> Sparse matrix API usage example completed.");
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
index 085153c..305f4b9 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
@@ -46,7 +46,7 @@ public class TracerExample {
     public static void main(String[] args) throws IOException {
         System.out.println(">>> Tracer utility example started.");
 
-        // Tracer is a simple utility class that allows pretty-printing of matrices/vectors
+        // Tracer is a simple utility class that allows pretty-printing of matrices/vectors.
         DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
             {1.12345, 2.12345},
             {3.12345, 4.12345}

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
index 789248c..14ec43b 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
@@ -28,16 +28,27 @@ import org.apache.ignite.ml.math.impls.vector.CacheVector;
 
 /**
  * This example shows how to use {@link CacheVector} API.
+ * <p>
+ * Basically CacheVector is a view over existing data in cache. So we have {@link VectorKeyMapper} and
+ * {@link ValueMapper} for this purpose. A {@link VectorKeyMapper} allows us to map vector indices to cache keys.
+ * And a {@link ValueMapper} allows us map cache object to vector elements - doubles.</p>
+ * <p>
+ * In this example we use simple flat mapping for keys and {@link IdentityValueMapper} for cache
+ * objects because they are Doubles.</p>
  */
 public class CacheVectorExample {
-    /** */ private static final String CACHE_NAME = CacheVectorExample.class.getSimpleName();
-    /** */ private static final int CARDINALITY = 10;
+    /** */
+    private static final String CACHE_NAME = CacheVectorExample.class.getSimpleName();
+
+    /** */
+    private static final int CARDINALITY = 10;
 
     /**
      * Executes example.
      *
      * @param args Command line arguments, none required.
      */
+    @SuppressWarnings("unchecked")
     public static void main(String[] args) {
         try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
             System.out.println();
@@ -93,10 +104,6 @@ public class CacheVectorExample {
                 System.out.println(">>> Dot product is 0.0 for orthogonal vectors.");
                 System.out.println(">>>");
             }
-            finally {
-                // Distributed cache could be removed from cluster only by #destroyCache() call.
-                ignite.destroyCache(CACHE_NAME);
-            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
index bc46b63..0289a8c 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
@@ -23,23 +23,24 @@ import java.io.ObjectOutput;
 import java.util.Arrays;
 
 import org.apache.ignite.ml.math.VectorStorage;
+import org.apache.ignite.ml.math.impls.storage.vector.ArrayVectorStorage;
 
 /**
- * Example vector storage, modeled after {@link org.apache.ignite.ml.math.impls.storage.vector.ArrayVectorStorage}.
+ * Example vector storage, modeled after {@link ArrayVectorStorage}.
  */
 class ExampleVectorStorage implements VectorStorage {
     /** */
     private double[] data;
 
     /**
-     * IMPL NOTE required by Externalizable
+     * IMPL NOTE required by Externalizable.
      */
     public ExampleVectorStorage() {
         // No-op.
     }
 
     /**
-     * @param data backing data array.
+     * @param data Backing data array.
      */
     ExampleVectorStorage(double[] data) {
         assert data != null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
index f470aef..e38f62c 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/OffHeapVectorExample.java
@@ -22,7 +22,7 @@ import org.apache.ignite.ml.math.Vector;
 import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector;
 
 /**
- * This example shows how to use off-heap {@link Vector} API.
+ * This example shows how to create and use off-heap versions of {@link Vector}.
  */
 public final class OffHeapVectorExample {
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
index 8ace55b..be3ade1 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/SparseVectorExample.java
@@ -55,8 +55,6 @@ public final class SparseVectorExample {
         System.out.println("\n>>> Dot product of vectors: [" + dotProduct
             + "], it is 0 as expected: [" + dotProductIsAsExp + "].");
 
-        assert dotProductIsAsExp : "Expect dot product of perpendicular vectors to be 0.";
-
         Vector hypotenuse = v1.plus(v2);
 
         System.out.println("\n>>> Hypotenuse (sum of vectors): " + Arrays.toString(hypotenuse.getStorage().data()));
@@ -73,8 +71,6 @@ public final class SparseVectorExample {
             + "], equals sum of squared lengths of two original vectors as expected: ["
             + lenSquaredHypotenuseIsAsExp + "].");
 
-        assert lenSquaredHypotenuseIsAsExp : "Expect squared length of hypotenuse to be as per Pythagorean theorem.";
-
         System.out.println("\n>>> Sparse vector API usage example completed.");
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
index a7204ad..cbb69d0 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorCustomStorageExample.java
@@ -53,8 +53,6 @@ public final class VectorCustomStorageExample {
         System.out.println("\n>>> Dot product of vectors: [" + dotProduct
             + "], it is 0 as expected: [" + dotProductIsAsExp + "].");
 
-        assert dotProductIsAsExp : "Expect dot product of perpendicular vectors to be 0.";
-
         Vector hypotenuse = v1.plus(v2);
 
         System.out.println("\n>>> Hypotenuse (sum of vectors): " + Arrays.toString(hypotenuse.getStorage().data()));
@@ -71,8 +69,6 @@ public final class VectorCustomStorageExample {
             + "], equals sum of squared lengths of two original vectors as expected: ["
             + lenSquaredHypotenuseIsAsExp + "].");
 
-        assert lenSquaredHypotenuseIsAsExp : "Expect squared length of hypotenuse to be as per Pythagorean theorem.";
-
         System.out.println("\n>>> Vector custom storage API usage example completed.");
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
index 3390de5..9970531 100644
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/VectorExample.java
@@ -23,6 +23,8 @@ import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
 
 /**
  * This example shows how to use {@link Vector} API.
+ *
+ * Just simple local onheap version.
  */
 public final class VectorExample {
     /**
@@ -50,8 +52,6 @@ public final class VectorExample {
         System.out.println("\n>>> Dot product of vectors: [" + dotProduct
             + "], it is 0 as expected: [" + dotProductIsAsExp + "].");
 
-        assert dotProductIsAsExp : "Expect dot product of perpendicular vectors to be 0.";
-
         Vector hypotenuse = v1.plus(v2);
 
         System.out.println("\n>>> Hypotenuse (sum of vectors): " + Arrays.toString(hypotenuse.getStorage().data()));
@@ -68,8 +68,6 @@ public final class VectorExample {
             + "], equals sum of squared lengths of two original vectors as expected: ["
             + lenSquaredHypotenuseIsAsExp + "].");
 
-        assert lenSquaredHypotenuseIsAsExp : "Expect squared length of hypotenuse to be as per Pythagorean theorem.";
-
         System.out.println("\n>>> Basic Vector API usage example completed.");
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec602fe/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
index 07cc63c..d334575 100644
--- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Tracer.java
@@ -25,12 +25,14 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.util.Locale;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.lang.IgniteUuid;
 
@@ -38,22 +40,27 @@ import org.apache.ignite.lang.IgniteUuid;
  * Utility methods to support output of {@link Vector} and {@link Matrix} instances to plain text or HTML.
  */
 public class Tracer {
+    /** Locale to format strings. */
+    private static final Locale LOCALE = Locale.US;
+
     /**
      * Double to color mapper.
      */
     public interface ColorMapper extends Function<Double, Color> {
     }
 
-    /** Continuous red-to-blue color mapping. */
+    /**
+     * Continuous red-to-blue color mapping.
+     */
     static private ColorMapper defaultColorMapper(double min, double max) {
         double range = max - min;
 
         return new ColorMapper() {
             /** {@inheritDoc} */
             @Override public Color apply(Double d) {
-                int r = (int)Math.round(255 * d);
+                int r = (int) Math.round(255 * d);
                 int g = 0;
-                int b = (int)Math.round(255 * (1 - d));
+                int b = (int) Math.round(255 * (1 - d));
 
                 return new Color(r, g, b);
             }
@@ -90,7 +97,7 @@ public class Tracer {
     public static void showAscii(Vector vec, IgniteLogger log, String fmt) {
         String cls = vec.getClass().getSimpleName();
 
-        log.info(String.format("%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
+        log.info(String.format(LOCALE, "%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
     }
 
     /**
@@ -108,7 +115,7 @@ public class Tracer {
     public static void showAscii(Vector vec, String fmt) {
         String cls = vec.getClass().getSimpleName();
 
-        System.out.println(String.format("%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
+        System.out.println(String.format(LOCALE, "%s(%d) [%s]", cls, vec.size(), mkString(vec, fmt)));
     }
 
     /**
@@ -132,7 +139,7 @@ public class Tracer {
         int cols = mtx.columnSize();
 
         for (int col = 0; col < cols; col++) {
-            String s = String.format(fmt, mtx.get(row, col));
+            String s = String.format(LOCALE, fmt, mtx.get(row, col));
 
             if (!first)
                 buf.append(", ");
@@ -155,7 +162,7 @@ public class Tracer {
         int rows = mtx.rowSize();
         int cols = mtx.columnSize();
 
-        System.out.println(String.format("%s(%dx%d)", cls, rows, cols));
+        System.out.println(String.format(LOCALE, "%s(%dx%d)", cls, rows, cols));
 
         for (int row = 0; row < rows; row++)
             System.out.println(rowStr(mtx, row, fmt));
@@ -172,7 +179,7 @@ public class Tracer {
         int rows = mtx.rowSize();
         int cols = mtx.columnSize();
 
-        log.info(String.format("%s(%dx%d)", cls, rows, cols));
+        log.info(String.format(LOCALE, "%s(%dx%d)", cls, rows, cols));
 
         for (int row = 0; row < rows; row++)
             log.info(rowStr(mtx, row, fmt));
@@ -188,8 +195,8 @@ public class Tracer {
     /**
      * Saves given vector as CSV file.
      *
-     * @param vec Vector to save.
-     * @param fmt Format to use.
+     * @param vec      Vector to save.
+     * @param fmt      Format to use.
      * @param filePath Path of the file to save to.
      */
     public static void saveAsCsv(Vector vec, String fmt, String filePath) throws IOException {
@@ -201,8 +208,8 @@ public class Tracer {
     /**
      * Saves given matrix as CSV file.
      *
-     * @param mtx Matrix to save.
-     * @param fmt Format to use.
+     * @param mtx      Matrix to save.
+     * @param fmt      Format to use.
      * @param filePath Path of the file to save to.
      */
     public static void saveAsCsv(Matrix mtx, String fmt, String filePath) throws IOException {
@@ -225,7 +232,7 @@ public class Tracer {
      * Shows given matrix in the browser with D3-based visualization.
      *
      * @param mtx Matrix to show.
-     * @param cm Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
+     * @param cm  Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
      * @throws IOException Thrown in case of any errors.
      */
     public static void showHtml(Matrix mtx, ColorMapper cm) throws IOException {
@@ -256,13 +263,13 @@ public class Tracer {
     }
 
     /**
-     * @param d Value of {@link Matrix} or {@link Vector} element.
+     * @param d   Value of {@link Matrix} or {@link Vector} element.
      * @param clr {@link Color} to paint.
      * @return JSON representation for given value and color.
      */
     static private String dataColorJson(double d, Color clr) {
         return "{" +
-            "d: " + String.format("%4f", d) +
+            "d: " + String.format(LOCALE, "%4f", d) +
             ", r: " + clr.getRed() +
             ", g: " + clr.getGreen() +
             ", b: " + clr.getBlue() +
@@ -273,7 +280,7 @@ public class Tracer {
      * Shows given vector in the browser with D3-based visualization.
      *
      * @param vec Vector to show.
-     * @param cm Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
+     * @param cm  Optional color mapper. If not provided - red-to-blue (R_B) mapper will be used.
      * @throws IOException Thrown in case of any errors.
      */
     public static void showHtml(Vector vec, ColorMapper cm) throws IOException {
@@ -303,13 +310,11 @@ public class Tracer {
     private static String fileToString(String fileName) throws IOException {
         assert Tracer.class.getResourceAsStream(fileName) != null : "Can't get resource: " + fileName;
 
-        InputStreamReader is = new InputStreamReader(Tracer.class.getResourceAsStream(fileName));
+        try (InputStreamReader is
+                 = new InputStreamReader(Tracer.class.getResourceAsStream(fileName), StandardCharsets.US_ASCII)) {
 
-        String str = new BufferedReader(is).lines().collect(Collectors.joining("\n"));
-
-        is.close();
-
-        return str;
+            return new BufferedReader(is).lines().collect(Collectors.joining("\n"));
+        }
     }
 
     /**
@@ -342,7 +347,7 @@ public class Tracer {
         StringBuilder buf = new StringBuilder();
 
         for (Vector.Element x : vec.all()) {
-            String s = String.format(Locale.US, fmt, x.get());
+            String s = String.format(LOCALE, fmt, x.get());
 
             if (!first) {
                 buf.append(", ");
@@ -361,7 +366,7 @@ public class Tracer {
      * Gets JavaScript array presentation of this vector.
      *
      * @param vec Vector to JavaScript-ify.
-     * @param cm Color mapper to user.
+     * @param cm  Color mapper to user.
      */
     private static String mkJsArrayString(Vector vec, ColorMapper cm) {
         boolean first = true;
@@ -388,7 +393,7 @@ public class Tracer {
      * Gets JavaScript array presentation of this vector.
      *
      * @param mtx Matrix to JavaScript-ify.
-     * @param cm Color mapper to user.
+     * @param cm  Color mapper to user.
      */
     private static String mkJsArrayString(Matrix mtx, ColorMapper cm) {
         boolean first = true;
@@ -440,7 +445,7 @@ public class Tracer {
 
         for (int row = 0; row < rows; row++) {
             for (int col = 0; col < cols; col++) {
-                String s = String.format(Locale.US, fmt, mtx.get(row, col));
+                String s = String.format(LOCALE, fmt, mtx.get(row, col));
 
                 if (col != 0)
                     buf.append(", ");