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/18 05:26:06 UTC
[51/54] [abbrv] ignite git commit: IGNITE-5000 Rename Ignite Math
module to Ignite ML module
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/CacheVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/CacheVectorExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/CacheVectorExample.java
deleted file mode 100644
index dd0fcb3..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/CacheVectorExample.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.examples.java8.math.vector;
-
-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.math.IdentityValueMapper;
-import org.apache.ignite.math.ValueMapper;
-import org.apache.ignite.math.VectorKeyMapper;
-import org.apache.ignite.math.impls.vector.CacheVector;
-
-/**
- * This example shows how to use {@link CacheVector} API.
- */
-public class CacheVectorExample {
- /** */ private static final String CACHE_NAME = CacheVectorExample.class.getSimpleName();
- /** */ private static final int CARDINALITY = 10;
-
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
- System.out.println();
- System.out.println(">>> CacheVector example started.");
-
- CacheConfiguration<Integer, Double> cfg = new CacheConfiguration<>();
-
- cfg.setName(CACHE_NAME);
-
- try (IgniteCache<Integer, Double> cache = ignite.getOrCreateCache(cfg)) {
- double[] testValues1 = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
- double[] testValues2 = {0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
-
- ValueMapper valMapper = new IdentityValueMapper();
-
- // Map vector element index to cache keys.
- VectorKeyMapper<Integer> keyMapper1 = new VectorKeyMapper<Integer>() {
- @Override public Integer apply(int i) {
- return i;
- }
-
- @Override public boolean isValid(Integer integer) {
- return integer >= 0 && CARDINALITY > integer;
- }
- };
-
- // Map vector element index to cache keys with shift.
- VectorKeyMapper<Integer> keyMapper2 = new VectorKeyMapper<Integer>() {
- @Override public Integer apply(int i) {
- return i + CARDINALITY;
- }
-
- @Override public boolean isValid(Integer integer) {
- return integer >= 0 && CARDINALITY > integer;
- }
- };
-
- // Create two cache vectors over one cache.
- CacheVector cacheVector1 = new CacheVector(CARDINALITY, cache, keyMapper1, valMapper);
- System.out.println(">>> First cache vector created.");
-
- CacheVector cacheVector2 = new CacheVector(CARDINALITY, cache, keyMapper2, valMapper);
- System.out.println(">>> Second cache vector created.");
-
- cacheVector1.assign(testValues1);
- cacheVector2.assign(testValues2);
-
- // Dot product for orthogonal vectors is 0.0.
- assert cacheVector1.dot(cacheVector2) == 0.0;
-
- System.out.println(">>>");
- System.out.println(">>> Finished executing Ignite \"CacheVector\" example.");
- 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/732dfea9/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/ExampleVectorStorage.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/ExampleVectorStorage.java b/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/ExampleVectorStorage.java
deleted file mode 100644
index 3b88e0a..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/ExampleVectorStorage.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.examples.java8.math.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-
-import org.apache.ignite.math.VectorStorage;
-
-/**
- * Example vector storage, modeled after {@link org.apache.ignite.math.impls.storage.vector.ArrayVectorStorage}.
- */
-class ExampleVectorStorage implements VectorStorage {
- /** */
- private double[] data;
-
- /**
- * IMPL NOTE required by Externalizable
- */
- public ExampleVectorStorage() {
- // No-op.
- }
-
- /**
- * @param data backing data array.
- */
- ExampleVectorStorage(double[] data) {
- assert data != null;
-
- this.data = data;
- }
-
- /** {@inheritDoc} */
- @Override public int size() {
- return data == null ? 0 : data.length;
- }
-
- /** {@inheritDoc} */
- @Override public double get(int i) {
- return data[i];
- }
-
- /** {@inheritDoc} */
- @Override public void set(int i, double v) {
- data[i] = v;
- }
-
- /** {@inheritDoc}} */
- @Override public boolean isArrayBased() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public double[] data() {
- return data;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isSequentialAccess() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isDense() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isRandomAccess() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isDistributed() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(data);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- data = (double[])in.readObject();
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- int res = 1;
-
- res = res * 37 + Arrays.hashCode(data);
-
- return res;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object obj) {
- if (this == obj)
- return true;
-
- if (obj == null || getClass() != obj.getClass())
- return false;
-
- ExampleVectorStorage that = (ExampleVectorStorage)obj;
-
- return Arrays.equals(data, (that.data));
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/OffHeapVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/OffHeapVectorExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/OffHeapVectorExample.java
deleted file mode 100644
index 7184245..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/OffHeapVectorExample.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.examples.java8.math.vector;
-
-import java.util.Arrays;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.vector.DenseLocalOffHeapVector;
-
-/**
- * This example shows how to use off-heap {@link Vector} API.
- */
-public final class OffHeapVectorExample {
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- System.out.println();
- System.out.println(">>> Off-heap vector API usage example started.");
-
- System.out.println("\n>>> Creating perpendicular off-heap vectors.");
- double[] data1 = new double[] {1, 0, 3, 0, 5, 0};
- double[] data2 = new double[] {0, 2, 0, 4, 0, 6};
-
- Vector v1 = new DenseLocalOffHeapVector(data1.length);
- Vector v2 = new DenseLocalOffHeapVector(data2.length);
-
- v1.assign(data1);
- v2.assign(data2);
-
- System.out.println(">>> First vector: " + Arrays.toString(data1));
- System.out.println(">>> Second vector: " + Arrays.toString(data2));
-
- double dotProduct = v1.dot(v2);
- boolean dotProductIsAsExp = dotProduct == 0;
-
- 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()));
-
- double lenSquared1 = v1.getLengthSquared();
- double lenSquared2 = v2.getLengthSquared();
- double lenSquaredHypotenuse = hypotenuse.getLengthSquared();
-
- boolean lenSquaredHypotenuseIsAsExp = lenSquaredHypotenuse == lenSquared1 + lenSquared2;
-
- System.out.println(">>> Squared length of first vector: [" + lenSquared1 + "].");
- System.out.println(">>> Squared length of second vector: [" + lenSquared2 + "].");
- System.out.println(">>> Squared length of hypotenuse: [" + lenSquaredHypotenuse
- + "], 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>>> Off-heap vector API usage example completed.");
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/SparseVectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/SparseVectorExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/SparseVectorExample.java
deleted file mode 100644
index 79e0567..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/SparseVectorExample.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.examples.java8.math.vector;
-
-import java.util.Arrays;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.vector.SparseLocalVector;
-
-import static org.apache.ignite.math.StorageConstants.RANDOM_ACCESS_MODE;
-
-/**
- * This example shows how to use sparse {@link Vector} API.
- */
-public final class SparseVectorExample {
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- System.out.println();
- System.out.println(">>> Sparse vector API usage example started.");
-
- System.out.println("\n>>> Creating perpendicular sparse vectors.");
- double[] data1 = new double[] {1, 0, 3, 0, 5, 0};
- double[] data2 = new double[] {0, 2, 0, 4, 0, 6};
-
- Vector v1 = new SparseLocalVector(data1.length, RANDOM_ACCESS_MODE);
- Vector v2 = new SparseLocalVector(data2.length, RANDOM_ACCESS_MODE);
-
- v1.assign(data1);
- v2.assign(data2);
-
- System.out.println(">>> First vector: " + Arrays.toString(data1));
- System.out.println(">>> Second vector: " + Arrays.toString(data2));
-
- double dotProduct = v1.dot(v2);
- boolean dotProductIsAsExp = dotProduct == 0;
-
- 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()));
-
- double lenSquared1 = v1.getLengthSquared();
- double lenSquared2 = v2.getLengthSquared();
- double lenSquaredHypotenuse = hypotenuse.getLengthSquared();
-
- boolean lenSquaredHypotenuseIsAsExp = lenSquaredHypotenuse == lenSquared1 + lenSquared2;
-
- System.out.println(">>> Squared length of first vector: [" + lenSquared1 + "].");
- System.out.println(">>> Squared length of second vector: [" + lenSquared2 + "].");
- System.out.println(">>> Squared length of hypotenuse: [" + lenSquaredHypotenuse
- + "], 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/732dfea9/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorCustomStorageExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorCustomStorageExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorCustomStorageExample.java
deleted file mode 100644
index b2778c5..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorCustomStorageExample.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.examples.java8.math.vector;
-
-import java.util.Arrays;
-import org.apache.ignite.math.Matrix;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.VectorStorage;
-import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
-import org.apache.ignite.math.impls.vector.AbstractVector;
-
-/**
- * This example shows how to use {@link Vector} based on custom {@link VectorStorage}.
- */
-public final class VectorCustomStorageExample {
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- System.out.println();
- System.out.println(">>> Vector custom storage API usage example started.");
-
- System.out.println("\n>>> Creating perpendicular vectors.");
- double[] data1 = new double[] {1, 0, 3, 0, 5, 0};
- double[] data2 = new double[] {0, 2, 0, 4, 0, 6};
-
- Vector v1 = new VectorCustomStorage(data1);
- Vector v2 = new VectorCustomStorage(data2);
-
- System.out.println(">>> First vector: " + Arrays.toString(data1));
- System.out.println(">>> Second vector: " + Arrays.toString(data2));
-
- double dotProduct = v1.dot(v2);
- boolean dotProductIsAsExp = dotProduct == 0;
-
- 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()));
-
- double lenSquared1 = v1.getLengthSquared();
- double lenSquared2 = v2.getLengthSquared();
- double lenSquaredHypotenuse = hypotenuse.getLengthSquared();
-
- boolean lenSquaredHypotenuseIsAsExp = lenSquaredHypotenuse == lenSquared1 + lenSquared2;
-
- System.out.println(">>> Squared length of first vector: [" + lenSquared1 + "].");
- System.out.println(">>> Squared length of second vector: [" + lenSquared2 + "].");
- System.out.println(">>> Squared length of hypotenuse: [" + lenSquaredHypotenuse
- + "], 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.");
- }
-
- /**
- * Example of vector with custom storage, modeled after
- * {@link org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector}.
- */
- static class VectorCustomStorage extends AbstractVector {
- /**
- * @param arr Source array.
- * @param cp {@code true} to clone array, reuse it otherwise.
- */
- private VectorStorage mkStorage(double[] arr, boolean cp) {
- assert arr != null;
-
- return new ExampleVectorStorage(cp ? arr.clone() : arr);
- }
-
- /** */
- public VectorCustomStorage() {
- // No-op.
- }
-
- /**
- * @param arr Source array.
- * @param shallowCp {@code true} to use shallow copy.
- */
- VectorCustomStorage(double[] arr, boolean shallowCp) {
- setStorage(mkStorage(arr, shallowCp));
- }
-
- /**
- * @param arr Source array.
- */
- VectorCustomStorage(double[] arr) {
- this(arr, false);
- }
-
- /** {@inheritDoc} */
- @Override public Matrix likeMatrix(int rows, int cols) {
- return new DenseLocalOnHeapMatrix(rows, cols);
- }
-
- /** {@inheritDoc */
- @Override public Vector like(int crd) {
- return new org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector(crd);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorExample.java
deleted file mode 100644
index f852f0a..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/VectorExample.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.examples.java8.math.vector;
-
-import java.util.Arrays;
-import org.apache.ignite.math.Vector;
-import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
-
-/**
- * This example shows how to use {@link Vector} API.
- */
-public final class VectorExample {
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- System.out.println();
- System.out.println(">>> Basic Vector API usage example started.");
-
- System.out.println("\n>>> Creating perpendicular vectors.");
- double[] data1 = new double[] {1, 0, 3, 0, 5, 0};
- double[] data2 = new double[] {0, 2, 0, 4, 0, 6};
-
- Vector v1 = new DenseLocalOnHeapVector(data1);
- Vector v2 = new DenseLocalOnHeapVector(data2);
-
- System.out.println(">>> First vector: " + Arrays.toString(data1));
- System.out.println(">>> Second vector: " + Arrays.toString(data2));
-
- double dotProduct = v1.dot(v2);
- boolean dotProductIsAsExp = dotProduct == 0;
-
- 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()));
-
- double lenSquared1 = v1.getLengthSquared();
- double lenSquared2 = v2.getLengthSquared();
- double lenSquaredHypotenuse = hypotenuse.getLengthSquared();
-
- boolean lenSquaredHypotenuseIsAsExp = lenSquaredHypotenuse == lenSquared1 + lenSquared2;
-
- System.out.println(">>> Squared length of first vector: [" + lenSquared1 + "].");
- System.out.println(">>> Squared length of second vector: [" + lenSquared2 + "].");
- System.out.println(">>> Squared length of hypotenuse: [" + lenSquaredHypotenuse
- + "], 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/732dfea9/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/package-info.java
deleted file mode 100644
index ff09e4e..0000000
--- a/examples/src/main/java8/org/apache/ignite/examples/java8/math/vector/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Core algebra vector examples.
- */
-package org.apache.ignite.examples.java8.math.vector;
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java
new file mode 100644
index 0000000..07308f5
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java
@@ -0,0 +1,80 @@
+/*
+ * 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.examples.ml.math.decompositions;
+
+import org.apache.ignite.math.Matrix;
+import org.apache.ignite.math.Tracer;
+import org.apache.ignite.math.decompositions.CholeskyDecomposition;
+import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+
+/**
+ * Example of using {@link CholeskyDecomposition}.
+ */
+public class CholeskyDecompositionExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println(">>> Cholesky decomposition example started.");
+ // Let's compute a Cholesky decomposition of Hermitian matrix m:
+ // m = l l^{*}, where
+ // l is a lower triangular matrix
+ // l^{*} is its conjugate transpose
+
+ DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
+ {2.0d, -1.0d, 0.0d},
+ {-1.0d, 2.0d, -1.0d},
+ {0.0d, -1.0d, 2.0d}
+ });
+ System.out.println("\n>>> Matrix m for decomposition: ");
+ Tracer.showAscii(m);
+
+ // This decomposition is useful when dealing with systems of linear equations of the form
+ // m x = b where m is a Hermitian matrix.
+ // For such systems Cholesky decomposition provides
+ // more effective method of solving compared to LU decomposition.
+ // Suppose we want to solve system
+ // m x = b for various bs. Then after we computed Cholesky decomposition, we can feed various bs
+ // as a matrix of the form
+ // (b1, b2, ..., bm)
+ // to the method Cholesky::solve which returns solutions in the form
+ // (sol1, sol2, ..., solm)
+ CholeskyDecomposition dec = new CholeskyDecomposition(m);
+ System.out.println("\n>>> Made decomposition m = l * l^{*}.");
+ System.out.println(">>> Matrix l is ");
+ Tracer.showAscii(dec.getL());
+ System.out.println(">>> Matrix l^{*} is ");
+ Tracer.showAscii(dec.getLT());
+
+ Matrix bs = new DenseLocalOnHeapMatrix(new double[][] {
+ {4.0, -6.0, 7.0},
+ {1.0, 1.0, 1.0}
+ }).transpose();
+ System.out.println("\n>>> Solving systems of linear equations of the form m x = b for various bs represented by columns of matrix");
+ Tracer.showAscii(bs);
+ Matrix sol = dec.solve(bs);
+
+ System.out.println("\n>>> List of solutions: ");
+ for (int i = 0; i < sol.columnSize(); i++)
+ Tracer.showAscii(sol.viewColumn(i));
+
+ System.out.println("\n>>> Cholesky decomposition example completed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
new file mode 100644
index 0000000..16e692b
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
@@ -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.examples.ml.math.decompositions;
+
+import org.apache.ignite.math.Tracer;
+import org.apache.ignite.math.decompositions.EigenDecomposition;
+import org.apache.ignite.math.functions.Functions;
+import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+
+/**
+ * Example of using {@link EigenDecomposition}.
+ */
+public class EigenDecompositionExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println(">>> Eigen decomposition example started.");
+
+ // Let's compute EigenDecomposition for some square (n x n) matrix m with real eigenvalues:
+ // m = v d v^{-1}, where d is diagonal matrix having eigenvalues of m on diagonal
+ // and v is matrix where i-th column is eigenvector for i-th eigenvalue (i from 0 to n - 1)
+ DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
+ {1.0d, 0.0d, 0.0d, 0.0d},
+ {0.0d, 1.0d, 0.0d, 0.0d},
+ {0.0d, 0.0d, 2.0d, 0.0d},
+ {1.0d, 1.0d, 0.0d, 2.0d}
+ });
+ System.out.println("\n>>> Matrix m for decomposition: ");
+ Tracer.showAscii(m);
+
+ EigenDecomposition dec = new EigenDecomposition(m);
+ System.out.println("\n>>> Made decomposition.");
+ System.out.println(">>> Matrix getV is ");
+ Tracer.showAscii(dec.getV());
+ System.out.println(">>> Matrix getD is ");
+ Tracer.showAscii(dec.getD());
+
+ // From this decomposition we, for example, can easily compute determinant of matrix m
+ // det (m) = det (v d v^{-1}) =
+ // det(v) det (d) det(v^{-1}) =
+ // det(v) det(v)^{-1} det(d) =
+ // det (d) =
+ // product of diagonal elements of d =
+ // product of eigenvalues
+ double det = dec.getRealEigenValues().foldMap(Functions.MULT, Functions.IDENTITY, 1.0);
+ System.out.println("\n>>> Determinant is " + det);
+
+ System.out.println("\n>>> Eigen decomposition example completed.");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
new file mode 100644
index 0000000..c670eab
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
@@ -0,0 +1,83 @@
+/*
+ * 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.examples.ml.math.decompositions;
+
+import org.apache.ignite.math.Matrix;
+import org.apache.ignite.math.Tracer;
+import org.apache.ignite.math.decompositions.LUDecomposition;
+import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+
+/**
+ * Example of using {@link LUDecomposition}.
+ */
+public class LUDecompositionExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println(">>> LU decomposition example started.");
+ // Let's compute a LU decomposition for some (n x n) matrix m:
+ // m = p l u, where
+ // p is an (n x n) is a row-permutation matrix
+ // l is a (n x n) lower triangular matrix
+ // u is a (n x n) upper triangular matrix
+
+ DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
+ {1.0d, 1.0d, -1.0d},
+ {1.0d, -2.0d, 3.0d},
+ {2.0d, 3.0d, 1.0d}
+ });
+ System.out.println("\n>>> Matrix m for decomposition: ");
+ Tracer.showAscii(m);
+
+ // This decomposition is useful when dealing with systems of linear equations.
+ // (see https://en.wikipedia.org/wiki/LU_decomposition)
+ // suppose we want to solve system
+ // m x = b for various bs. Then after we computed LU decomposition, we can feed various bs
+ // as a matrix of the form
+ // (b1, b2, ..., bm)
+ // to the method LUDecomposition::solve which returns solutions in the form
+ // (sol1, sol2, ..., solm)
+
+ LUDecomposition dec = new LUDecomposition(m);
+ System.out.println("\n>>> Made decomposition.");
+ System.out.println(">>> Matrix getL is ");
+ Tracer.showAscii(dec.getL());
+ System.out.println(">>> Matrix getU is ");
+ Tracer.showAscii(dec.getU());
+ System.out.println(">>> Matrix getP is ");
+ Tracer.showAscii(dec.getP());
+
+ Matrix bs = new DenseLocalOnHeapMatrix(new double[][] {
+ {4.0, -6.0, 7.0},
+ {1.0, 1.0, 1.0}
+ });
+ System.out.println("\n>>> Matrix to solve: ");
+ Tracer.showAscii(bs);
+
+ Matrix sol = dec.solve(bs.transpose());
+
+ System.out.println("\n>>> List of solutions: ");
+ for (int i = 0; i < sol.columnSize(); i++)
+ Tracer.showAscii(sol.viewColumn(i));
+
+ System.out.println("\n>>> LU decomposition example completed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
new file mode 100644
index 0000000..281fbc4
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
@@ -0,0 +1,70 @@
+/*
+ * 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.examples.ml.math.decompositions;
+
+import org.apache.ignite.math.Tracer;
+import org.apache.ignite.math.decompositions.SingularValueDecomposition;
+import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+
+/**
+ * Example of using {@link SingularValueDecomposition}.
+ */
+public class SingularValueDecompositionExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println(">>> Singular value decomposition (SVD) example started.");
+
+ // Let's compute a SVD of (l x k) matrix m. This decomposition can be thought as extension of EigenDecomposition to
+ // rectangular matrices. The factorization we get is following:
+ // m = u * s * v^{*}, where
+ // u is a real or complex unitary matrix
+ // s is a rectangular diagonal matrix with non-negative real numbers on diagonal (this numbers are singular values of m)
+ // v is a real or complex unitary matrix
+ // If m is real then u and v are also real.
+ // Complex case is not supported for the moment.
+ DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
+ {1.0d, 0.0d, 0.0d, 0.0d, 2.0d},
+ {0.0d, 0.0d, 3.0d, 0.0d, 0.0d},
+ {0.0d, 0.0d, 0.0d, 0.0d, 0.0d},
+ {0.0d, 2.0d, 0.0d, 0.0d, 0.0d}
+ });
+ System.out.println("\n>>> Matrix m for decomposition: ");
+ Tracer.showAscii(m);
+
+ SingularValueDecomposition dec = new SingularValueDecomposition(m);
+ System.out.println("\n>>> Made decomposition m = u * s * v^{*}.");
+ System.out.println(">>> Matrix u is ");
+ Tracer.showAscii(dec.getU());
+ System.out.println(">>> Matrix s is ");
+ Tracer.showAscii(dec.getS());
+ System.out.println(">>> Matrix v is ");
+ Tracer.showAscii(dec.getV());
+
+ // This decomposition can in particular help with solving problem of finding x minimizing 2-norm of m x such
+ // that 2-norm of x is 1. It appears that it is the right singular vector corresponding to minimal singular
+ // value, which is always last.
+ System.out.println("\n>>> Vector x minimizing 2-norm of m x such that 2 norm of x is 1: ");
+ Tracer.showAscii(dec.getV().viewColumn(dec.getSingularValues().length - 1));
+
+ System.out.println("\n>>> Singular value decomposition (SVD) example completed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/package-info.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/package-info.java
new file mode 100644
index 0000000..644f8ba
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Core algebra decomposition examples.
+ */
+package org.apache.ignite.examples.ml.math.decompositions;
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/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
new file mode 100644
index 0000000..80f861f
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java
@@ -0,0 +1,91 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+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.math.IdentityValueMapper;
+import org.apache.ignite.math.MatrixKeyMapper;
+import org.apache.ignite.math.ValueMapper;
+import org.apache.ignite.math.functions.Functions;
+import org.apache.ignite.math.impls.matrix.CacheMatrix;
+
+/** */
+public class CacheMatrixExample {
+ /** */ private static final String CACHE_NAME = CacheMatrixExample.class.getSimpleName();
+ /** */ private static final int ROWS = 3;
+ /** */ private static final int COLS = 3;
+
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+ System.out.println();
+ System.out.println(">>> CacheMatrix example started.");
+
+ CacheConfiguration<Integer, Double> cfg = new CacheConfiguration<>();
+
+ cfg.setName(CACHE_NAME);
+
+ try (IgniteCache<Integer, Double> cache = ignite.getOrCreateCache(cfg)) {
+ double[][] testValues = {{1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {1.0, 1.0, 1.0}};
+
+ ValueMapper valMapper = new IdentityValueMapper();
+
+ // Map matrix element indices to cache keys.
+ MatrixKeyMapper<Integer> keyMapper = new MatrixKeyMapper<Integer>() {
+ @Override public Integer apply(int x, int y) {
+ return x * COLS + y;
+ }
+
+ @Override public boolean isValid(Integer integer) {
+ return integer >= 0 && integer < COLS * ROWS;
+ }
+ };
+
+ // Create cache matrix.
+ CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(ROWS, COLS, cache, keyMapper, valMapper);
+
+ cacheMatrix.assign(testValues);
+
+ // Find all positive elements.
+ Integer nonZeroes = cacheMatrix.foldMap((o, aDouble) -> {
+ if (aDouble > 0)
+ return o + 1;
+ return o;
+ }, Functions.IDENTITY, 0);
+
+ assert nonZeroes.equals(6);
+
+ 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/732dfea9/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
new file mode 100644
index 0000000..d0c8604
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
@@ -0,0 +1,162 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+
+import org.apache.ignite.math.MatrixStorage;
+
+/**
+ * Example matrix storage, modeled after {@link org.apache.ignite.math.impls.storage.matrix.ArrayMatrixStorage}.
+ */
+class ExampleMatrixStorage implements MatrixStorage {
+ /** Backing data array. */
+ private double[][] data;
+ /** Amount of rows in a matrix storage. */
+ private int rows;
+ /** Amount of columns in a matrix storage. */
+ private int cols;
+
+ /**
+ *
+ */
+ public ExampleMatrixStorage() {
+ // No-op.
+ }
+
+ /**
+ * @param rows Amount of rows in a matrix storage.
+ * @param cols Amount of columns in a matrix storage.
+ */
+ ExampleMatrixStorage(int rows, int cols) {
+ assert rows > 0;
+ assert cols > 0;
+
+ this.data = new double[rows][cols];
+ this.rows = rows;
+ this.cols = cols;
+ }
+
+ /**
+ * @param data Backing data array.
+ */
+ ExampleMatrixStorage(double[][] data) {
+ assert data != null;
+ assert data[0] != null;
+
+ this.data = data;
+ this.rows = data.length;
+ this.cols = data[0].length;
+
+ assert rows > 0;
+ assert cols > 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public double get(int x, int y) {
+ return data[x][y];
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isSequentialAccess() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isDense() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isRandomAccess() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isDistributed() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void set(int x, int y, double v) {
+ data[x][y] = v;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int columnSize() {
+ return cols;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int rowSize() {
+ return rows;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isArrayBased() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public double[][] data() {
+ return data;
+ }
+
+ /** {@inheritDoc */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt(rows);
+ out.writeInt(cols);
+
+ out.writeObject(data);
+ }
+
+ /** {@inheritDoc */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ rows = in.readInt();
+ cols = in.readInt();
+
+ data = (double[][])in.readObject();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int res = 1;
+
+ res += res * 37 + rows;
+ res += res * 37 + cols;
+ res += res * 37 + Arrays.deepHashCode(data);
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ ExampleMatrixStorage that = (ExampleMatrixStorage)o;
+
+ return Arrays.deepEquals(data, that.data);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/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
new file mode 100644
index 0000000..b3df9f1
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
@@ -0,0 +1,141 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+import org.apache.ignite.math.Matrix;
+import org.apache.ignite.math.MatrixStorage;
+import org.apache.ignite.math.Vector;
+import org.apache.ignite.math.impls.matrix.AbstractMatrix;
+import org.apache.ignite.math.impls.vector.DenseLocalOnHeapVector;
+
+/**
+ * This example shows how to use {@link Matrix} API based on custom {@link MatrixStorage}.
+ */
+public final class MatrixCustomStorageExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println();
+ System.out.println(">>> Matrix API usage example started.");
+
+ System.out.println("\n>>> Creating a matrix to be transposed.");
+ double[][] data = new double[][] {{1, 2, 3}, {4, 5, 6}};
+ Matrix m = new MatrixCustomStorage(data);
+ Matrix transposed = m.transpose();
+
+ System.out.println(">>> Matrix: ");
+ MatrixExampleUtil.print(m);
+ System.out.println(">>> Transposed matrix: ");
+ MatrixExampleUtil.print(transposed);
+
+ MatrixExampleUtil.verifyTransposition(m, transposed);
+
+ System.out.println("\n>>> Creating matrices to be multiplied.");
+ double[][] data1 = new double[][] {{1, 2}, {3, 4}};
+ double[][] data2 = new double[][] {{5, 6}, {7, 8}};
+
+ Matrix m1 = new MatrixCustomStorage(data1);
+ Matrix m2 = new MatrixCustomStorage(data2);
+ Matrix mult = m1.times(m2);
+
+ System.out.println(">>> First matrix: ");
+ MatrixExampleUtil.print(m1);
+ System.out.println(">>> Second matrix: ");
+ MatrixExampleUtil.print(m2);
+ System.out.println(">>> Matrix product: ");
+ MatrixExampleUtil.print(mult);
+
+ System.out.println("\n>>> Calculating matrices determinants.");
+ double det1 = m1.determinant();
+ double det2 = m2.determinant();
+ double detMult = mult.determinant();
+ boolean detMultIsAsExp = Math.abs(detMult - det1 * det2) < 0.0001d;
+
+ System.out.println(">>> First matrix determinant: [" + det1 + "].");
+ System.out.println(">>> Second matrix determinant: [" + det2 + "].");
+ 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("\n>>> Matrix API usage example completed.");
+ }
+
+ /**
+ * Example of vector with custom storage, modeled after
+ * {@link org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix}.
+ */
+ static class MatrixCustomStorage extends AbstractMatrix {
+ /**
+ *
+ */
+ public MatrixCustomStorage() {
+ // No-op.
+ }
+
+ /**
+ * @param rows Amount of rows in a matrix.
+ * @param cols Amount of columns in a matrix.
+ */
+ MatrixCustomStorage(int rows, int cols) {
+ assert rows > 0;
+ assert cols > 0;
+
+ setStorage(new ExampleMatrixStorage(rows, cols));
+ }
+
+ /**
+ * @param mtx Source matrix.
+ */
+ MatrixCustomStorage(double[][] mtx) {
+ assert mtx != null;
+
+ setStorage(new ExampleMatrixStorage(mtx));
+ }
+
+ /**
+ * @param orig original matrix to be copied.
+ */
+ private MatrixCustomStorage(MatrixCustomStorage orig) {
+ assert orig != null;
+
+ setStorage(new ExampleMatrixStorage(orig.rowSize(), orig.columnSize()));
+
+ assign(orig);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Matrix copy() {
+ return new MatrixCustomStorage(this);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Matrix like(int rows, int cols) {
+ return new MatrixCustomStorage(rows, cols);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Vector likeVector(int crd) {
+ return new DenseLocalOnHeapVector(crd);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/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
new file mode 100644
index 0000000..66f50d5
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
@@ -0,0 +1,79 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+import org.apache.ignite.math.Matrix;
+import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+
+/**
+ * This example shows how to use {@link Matrix} API.
+ */
+public final class MatrixExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println();
+ System.out.println(">>> Basic Matrix API usage example started.");
+
+ System.out.println("\n>>> Creating a matrix to be transposed.");
+ double[][] data = new double[][] {{1, 2, 3}, {4, 5, 6}};
+ Matrix m = new DenseLocalOnHeapMatrix(data);
+ Matrix transposed = m.transpose();
+
+ System.out.println(">>> Matrix: ");
+ MatrixExampleUtil.print(m);
+ System.out.println(">>> Transposed matrix: ");
+ MatrixExampleUtil.print(transposed);
+
+ MatrixExampleUtil.verifyTransposition(m, transposed);
+
+ System.out.println("\n>>> Creating matrices to be multiplied.");
+ double[][] data1 = new double[][] {{1, 2}, {3, 4}};
+ double[][] data2 = new double[][] {{5, 6}, {7, 8}};
+
+ Matrix m1 = new DenseLocalOnHeapMatrix(data1);
+ Matrix m2 = new DenseLocalOnHeapMatrix(data2);
+ Matrix mult = m1.times(m2);
+
+ System.out.println(">>> First matrix: ");
+ MatrixExampleUtil.print(m1);
+ System.out.println(">>> Second matrix: ");
+ MatrixExampleUtil.print(m2);
+ System.out.println(">>> Matrix product: ");
+ MatrixExampleUtil.print(mult);
+
+ System.out.println("\n>>> Calculating matrices determinants.");
+ double det1 = m1.determinant();
+ double det2 = m2.determinant();
+ double detMult = mult.determinant();
+ boolean detMultIsAsExp = Math.abs(detMult - det1 * det2) < 0.0001d;
+
+ System.out.println(">>> First matrix determinant: [" + det1 + "].");
+ System.out.println(">>> Second matrix determinant: [" + det2 + "].");
+ 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("\n>>> Basic Matrix API usage example completed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
new file mode 100644
index 0000000..bf406a8
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
@@ -0,0 +1,52 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+import org.apache.ignite.math.Matrix;
+import org.apache.ignite.math.Tracer;
+
+/**
+ * Utility functions for {@link Matrix} API examples.
+ */
+class MatrixExampleUtil {
+ /**
+ * Verifies matrix transposition.
+ *
+ * @param m Original matrix.
+ * @param transposed Transposed matrix.
+ */
+ static void verifyTransposition(Matrix m, Matrix transposed) {
+ for (int row = 0; row < m.rowSize(); row++)
+ for (int col = 0; col < m.columnSize(); col++) {
+ double val = m.get(row, col);
+ double valTransposed = transposed.get(col, row);
+
+ assert val == valTransposed : "Values not equal at (" + row + "," + col
+ + "), original: " + val + " transposed: " + valTransposed;
+ }
+ }
+
+ /**
+ * Prints matrix values to console.
+ *
+ * @param m Matrix to print.
+ */
+ static void print(Matrix m) {
+ Tracer.showAscii(m);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/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
new file mode 100644
index 0000000..71dc2b8
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
@@ -0,0 +1,84 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+import org.apache.ignite.math.Matrix;
+import org.apache.ignite.math.impls.matrix.DenseLocalOffHeapMatrix;
+
+/**
+ * This example shows how to use off-heap {@link Matrix} API.
+ */
+public final class OffHeapMatrixExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println();
+ System.out.println(">>> Off-heap matrix API usage example started.");
+
+ System.out.println("\n>>> Creating a matrix to be transposed.");
+ double[][] data = new double[][] {{1, 2, 3}, {4, 5, 6}};
+ Matrix m = new DenseLocalOffHeapMatrix(data.length, data[0].length);
+ m.assign(data);
+ Matrix transposed = m.transpose();
+
+ System.out.println(">>> Matrix: ");
+ MatrixExampleUtil.print(m);
+ System.out.println(">>> Transposed matrix: ");
+ MatrixExampleUtil.print(transposed);
+
+ MatrixExampleUtil.verifyTransposition(m, transposed);
+
+ System.out.println("\n>>> Creating matrices to be multiplied.");
+ double[][] data1 = new double[][] {{1, 2}, {3, 4}};
+ double[][] data2 = new double[][] {{5, 6}, {7, 8}};
+
+ Matrix m1 = new DenseLocalOffHeapMatrix(data1.length, data1[0].length);
+ Matrix m2 = new DenseLocalOffHeapMatrix(data2.length, data2[0].length);
+
+ m1.assign(data1);
+ m2.assign(data2);
+
+ Matrix mult = m1.times(m2);
+
+ System.out.println(">>> First matrix: ");
+ MatrixExampleUtil.print(m1);
+ System.out.println(">>> Second matrix: ");
+ MatrixExampleUtil.print(m2);
+ System.out.println(">>> Matrix product: ");
+ MatrixExampleUtil.print(mult);
+
+ System.out.println("\n>>> Calculating matrices determinants.");
+ double det1 = m1.determinant();
+ double det2 = m2.determinant();
+ double detMult = mult.determinant();
+ boolean detMultIsAsExp = Math.abs(detMult - det1 * det2) < 0.0001d;
+
+ System.out.println(">>> First matrix determinant: [" + det1 + "].");
+ System.out.println(">>> Second matrix determinant: [" + det2 + "].");
+ 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("\n>>> Off-heap matrix API usage example completed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/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
new file mode 100644
index 0000000..ffbd9af
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
@@ -0,0 +1,65 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.math.StorageConstants;
+import org.apache.ignite.math.impls.matrix.SparseDistributedMatrix;
+import org.apache.ignite.thread.IgniteThread;
+
+/**
+ * This example shows how to use {@link SparseDistributedMatrix} API.
+ */
+public class SparseDistributedMatrixExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) throws InterruptedException {
+ System.out.println();
+ System.out.println(">>> Sparse distributed matrix API usage example started.");
+ // Start ignite grid.
+ try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+ System.out.println(">>> Ignite grid started.");
+ // Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread
+ // because we create ignite cache internally.
+ IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), SparseDistributedMatrixExample.class.getSimpleName(), () -> {
+
+ double[][] testValues = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
+
+ System.out.println(">>> Create new SparseDistributedMatrix inside IgniteThread.");
+ // Create SparseDistributedMatrix, new cache will be created automagically.
+ SparseDistributedMatrix distributedMatrix = new SparseDistributedMatrix(testValues.length, testValues[0].length,
+ StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
+
+ distributedMatrix.assign(testValues);
+
+ assert distributedMatrix.sum() == 3.0;
+
+ System.out.println(">>> Destroy SparseDistributedMatrix after using.");
+ // Destroy internal cache.
+ distributedMatrix.destroy();
+ });
+
+ igniteThread.start();
+
+ igniteThread.join();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/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
new file mode 100644
index 0000000..d63d985
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
@@ -0,0 +1,84 @@
+/*
+ * 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.examples.ml.math.matrix;
+
+import org.apache.ignite.math.Matrix;
+import org.apache.ignite.math.impls.matrix.SparseLocalOnHeapMatrix;
+
+/**
+ * This example shows how to use sparse {@link Matrix} API.
+ */
+public final class SparseMatrixExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ System.out.println();
+ System.out.println(">>> Sparse matrix API usage example started.");
+
+ System.out.println("\n>>> Creating a matrix to be transposed.");
+ double[][] data = new double[][] {{1, 2, 3}, {4, 5, 6}};
+ Matrix m = new SparseLocalOnHeapMatrix(data.length, data[0].length);
+ m.assign(data);
+ Matrix transposed = m.transpose();
+
+ System.out.println(">>> Matrix: ");
+ MatrixExampleUtil.print(m);
+ System.out.println(">>> Transposed matrix: ");
+ MatrixExampleUtil.print(transposed);
+
+ MatrixExampleUtil.verifyTransposition(m, transposed);
+
+ System.out.println("\n>>> Creating matrices to be multiplied.");
+ double[][] data1 = new double[][] {{1, 2}, {3, 4}};
+ double[][] data2 = new double[][] {{5, 6}, {7, 8}};
+
+ Matrix m1 = new SparseLocalOnHeapMatrix(data1.length, data1[0].length);
+ Matrix m2 = new SparseLocalOnHeapMatrix(data2.length, data2[0].length);
+
+ m1.assign(data1);
+ m2.assign(data2);
+
+ Matrix mult = m1.times(m2);
+
+ System.out.println(">>> First matrix: ");
+ MatrixExampleUtil.print(m1);
+ System.out.println(">>> Second matrix: ");
+ MatrixExampleUtil.print(m2);
+ System.out.println(">>> Matrix product: ");
+ MatrixExampleUtil.print(mult);
+
+ System.out.println("\n>>> Calculating matrices determinants.");
+ double det1 = m1.determinant();
+ double det2 = m2.determinant();
+ double detMult = mult.determinant();
+ boolean detMultIsAsExp = Math.abs(detMult - det1 * det2) < 0.0001d;
+
+ System.out.println(">>> First matrix determinant: [" + det1 + "].");
+ System.out.println(">>> Second matrix determinant: [" + det2 + "].");
+ 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("\n>>> Sparse matrix API usage example completed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/package-info.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/package-info.java
new file mode 100644
index 0000000..354119a
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Core algebra matrix examples.
+ */
+package org.apache.ignite.examples.ml.math.matrix;
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/package-info.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/package-info.java
new file mode 100644
index 0000000..52344bf
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Core algebra examples.
+ */
+package org.apache.ignite.examples.ml.math;
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/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
new file mode 100644
index 0000000..0bf7743
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
@@ -0,0 +1,63 @@
+/*
+ * 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.examples.ml.math.tracer;
+
+import java.awt.Color;
+import java.io.IOException;
+import org.apache.ignite.math.Tracer;
+import org.apache.ignite.math.impls.matrix.DenseLocalOnHeapMatrix;
+
+/**
+ * Example of using {@link Tracer} utility API.
+ */
+public class TracerExample {
+ /**
+ * Double to color mapper example.
+ */
+ private static final Tracer.ColorMapper COLOR_MAPPER = d -> {
+ if (d <= 0.33)
+ return Color.RED;
+ else if (d <= 0.66)
+ return Color.GREEN;
+ else
+ return Color.BLUE;
+ };
+
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ 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
+ DenseLocalOnHeapMatrix m = new DenseLocalOnHeapMatrix(new double[][] {
+ {1.12345, 2.12345},
+ {3.12345, 4.12345}
+ });
+
+ System.out.println("\n>>> Tracer output to console in ASCII.");
+ Tracer.showAscii(m, "%.3g");
+
+ System.out.println("\n>>> Tracer output to browser in HTML.");
+ Tracer.showHtml(m, COLOR_MAPPER);
+
+ System.out.println("\n>>> Tracer utility example completed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/732dfea9/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/package-info.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/package-info.java
new file mode 100644
index 0000000..574e598
--- /dev/null
+++ b/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Core algebra tracer example.
+ */
+package org.apache.ignite.examples.ml.math.tracer;