You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2018/01/17 10:16:37 UTC
[06/11] ignite git commit: IGNITE-7203 Java 8 by default
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/ml/org/apache/ignite/examples/ml/knn/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/knn/package-info.java b/examples/src/main/ml/org/apache/ignite/examples/ml/knn/package-info.java
deleted file mode 100644
index 8de4656..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/knn/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. -->
- * kNN examples.
- */
-package org.apache.ignite.examples.ml.knn;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/KNNRegressionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/KNNRegressionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/KNNRegressionExample.java
deleted file mode 100644
index b52613a..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/KNNRegressionExample.java
+++ /dev/null
@@ -1,157 +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.ml.knn.regression;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.ExampleNodeStartup;
-import org.apache.ignite.examples.ml.knn.classification.KNNClassificationExample;
-import org.apache.ignite.ml.knn.models.KNNStrategy;
-import org.apache.ignite.ml.knn.regression.KNNMultipleLinearRegression;
-import org.apache.ignite.ml.math.distances.ManhattanDistance;
-import org.apache.ignite.ml.structures.LabeledDataset;
-import org.apache.ignite.ml.structures.LabeledDatasetTestTrainPair;
-import org.apache.ignite.ml.structures.preprocessing.LabeledDatasetLoader;
-import org.apache.ignite.ml.structures.preprocessing.LabellingMachine;
-import org.apache.ignite.ml.structures.preprocessing.Normalizer;
-import org.apache.ignite.thread.IgniteThread;
-
-/**
- * <p>
- * Example of using {@link KNNMultipleLinearRegression} with iris dataset.</p>
- * <p>
- * Note that in this example we cannot guarantee order in which nodes return results of intermediate
- * computations and therefore algorithm can return different results.</p>
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p>
- * <p>
- * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node
- * with {@code examples/config/example-ignite.xml} configuration.</p>
- */
-public class KNNRegressionExample {
- /** Separator. */
- private static final String SEPARATOR = ",";
-
- /** */
- private static final String KNN_CLEARED_MACHINES_TXT = "../datasets/cleared_machines.txt";
-
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) throws InterruptedException {
- System.out.println(">>> kNN regression example started.");
- // Start ignite grid.
- try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
- System.out.println(">>> Ignite grid started.");
-
- IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(),
- KNNRegressionExample.class.getSimpleName(), () -> {
-
- try {
- // Prepare path to read
- URL url = KNNClassificationExample.class.getResource(KNN_CLEARED_MACHINES_TXT);
- if (url == null)
- throw new RuntimeException("Can't get URL for: " + KNN_CLEARED_MACHINES_TXT);
-
- Path path = Paths.get(url.toURI());
-
- // Read dataset from file
- LabeledDataset dataset = LabeledDatasetLoader.loadFromTxtFile(path, SEPARATOR, false, false);
-
- // Normalize dataset
- Normalizer.normalizeWithMiniMax(dataset);
-
- // Random splitting of iris data as 80% train and 20% test datasets
- LabeledDatasetTestTrainPair split = new LabeledDatasetTestTrainPair(dataset, 0.2);
-
- System.out.println("\n>>> Amount of observations in train dataset: " + split.train().rowSize());
- System.out.println("\n>>> Amount of observations in test dataset: " + split.test().rowSize());
-
- LabeledDataset test = split.test();
- LabeledDataset train = split.train();
-
- // Builds weighted kNN-regression with Manhattan Distance
- KNNMultipleLinearRegression knnMdl = new KNNMultipleLinearRegression(7, new ManhattanDistance(),
- KNNStrategy.WEIGHTED, train);
-
- // Clone labels
- final double[] labels = test.labels();
-
- // Save predicted classes to test dataset
- LabellingMachine.assignLabels(test, knnMdl);
-
- // Calculate mean squared error (MSE)
- double mse = 0.0;
-
- for (int i = 0; i < test.rowSize(); i++)
- mse += Math.pow(test.label(i) - labels[i], 2.0);
- mse = mse / test.rowSize();
-
- System.out.println("\n>>> Mean squared error (MSE) " + mse);
-
- // Calculate mean absolute error (MAE)
- double mae = 0.0;
-
- for (int i = 0; i < test.rowSize(); i++)
- mae += Math.abs(test.label(i) - labels[i]);
- mae = mae / test.rowSize();
-
- System.out.println("\n>>> Mean absolute error (MAE) " + mae);
-
- // Calculate R^2 as 1 - RSS/TSS
- double avg = 0.0;
-
- for (int i = 0; i < test.rowSize(); i++)
- avg += test.label(i);
-
- avg = avg / test.rowSize();
-
- double detCf = 0.0;
- double tss = 0.0;
-
- for (int i = 0; i < test.rowSize(); i++) {
- detCf += Math.pow(test.label(i) - labels[i], 2.0);
- tss += Math.pow(test.label(i) - avg, 2.0);
- }
-
- detCf = 1 - detCf / tss;
-
- System.out.println("\n>>> R^2 " + detCf);
- }
- catch (URISyntaxException | IOException e) {
- e.printStackTrace();
- System.out.println("\n>>> Unexpected exception, check resources: " + e);
- }
- finally {
- System.out.println("\n>>> kNN regression example completed.");
- }
- });
-
- igniteThread.start();
- igniteThread.join();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/package-info.java b/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/package-info.java
deleted file mode 100644
index e7ac336..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/knn/regression/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. -->
- * kNN regression examples.
- */
-package org.apache.ignite.examples.ml.knn.regression;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index ebac2b1..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.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.ml.math.decompositions;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.decompositions.CholeskyDecomposition;
-import org.apache.ignite.ml.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/43a62cdb/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
deleted file mode 100644
index cda37f4..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java
+++ /dev/null
@@ -1,69 +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.ml.math.decompositions;
-
-import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.decompositions.EigenDecomposition;
-import org.apache.ignite.ml.math.functions.Functions;
-import org.apache.ignite.ml.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/43a62cdb/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
deleted file mode 100644
index a815047..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java
+++ /dev/null
@@ -1,83 +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.ml.math.decompositions;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.decompositions.LUDecomposition;
-import org.apache.ignite.ml.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/43a62cdb/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/QRDecompositionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/QRDecompositionExample.java b/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/QRDecompositionExample.java
deleted file mode 100644
index bed99d1..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/QRDecompositionExample.java
+++ /dev/null
@@ -1,82 +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.ml.math.decompositions;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.decompositions.QRDecomposition;
-import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix;
-
-/**
- * Example of using {@link QRDecomposition}.
- */
-public class QRDecompositionExample {
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- System.out.println(">>> QR decomposition example started.");
- Matrix 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>>> Input matrix:");
- Tracer.showAscii(m);
-
- QRDecomposition dec = new QRDecomposition(m);
- System.out.println("\n>>> Value for full rank in decomposition: [" + dec.hasFullRank() + "].");
-
- Matrix q = dec.getQ();
- Matrix r = dec.getR();
-
- System.out.println("\n>>> Orthogonal matrix Q:");
- Tracer.showAscii(q);
- System.out.println("\n>>> Upper triangular matrix R:");
- Tracer.showAscii(r);
-
- Matrix qSafeCp = safeCopy(q);
-
- Matrix identity = qSafeCp.times(qSafeCp.transpose());
-
- System.out.println("\n>>> Identity matrix obtained from Q:");
- Tracer.showAscii(identity);
-
- Matrix recomposed = qSafeCp.times(r);
-
- System.out.println("\n>>> Recomposed input matrix:");
- Tracer.showAscii(recomposed);
-
- Matrix sol = dec.solve(new DenseLocalOnHeapMatrix(3, 10));
-
- System.out.println("\n>>> Solved matrix:");
- Tracer.showAscii(sol);
-
- dec.destroy();
-
- System.out.println("\n>>> QR decomposition example completed.");
- }
-
- /** */
- private static Matrix safeCopy(Matrix orig) {
- return new DenseLocalOnHeapMatrix(orig.rowSize(), orig.columnSize()).assign(orig);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 81406ae..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java
+++ /dev/null
@@ -1,70 +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.ml.math.decompositions;
-
-import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.decompositions.SingularValueDecomposition;
-import org.apache.ignite.ml.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/43a62cdb/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
deleted file mode 100644
index 644f8ba..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/decompositions/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 decomposition examples.
- */
-package org.apache.ignite.examples.ml.math.decompositions;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index a7cbaab..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.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.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.examples.ml.math.vector.CacheVectorExample;
-import org.apache.ignite.ml.math.IdentityValueMapper;
-import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.math.distributed.MatrixKeyMapper;
-import org.apache.ignite.ml.math.distributed.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;
- /** */ 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);
-
- Tracer.showAscii(cacheMatrix);
-
- // Find all positive elements.
- Integer nonZeroes = cacheMatrix.foldMap((o, aDouble) -> {
- if (aDouble > 0)
- return o + 1;
- return o;
- }, Functions.IDENTITY, 0);
-
- 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(">>>");
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 542fbdc..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/ExampleMatrixStorage.java
+++ /dev/null
@@ -1,175 +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.ml.math.matrix;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-import org.apache.ignite.ml.math.MatrixStorage;
-import org.apache.ignite.ml.math.StorageConstants;
-import org.apache.ignite.ml.math.impls.storage.matrix.ArrayMatrixStorage;
-import org.apache.ignite.ml.math.util.MatrixUtil;
-
-/**
- * Example matrix storage implementation, modeled after {@link 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 int storageMode() {
- // This value indicate that we store matrix data by rows.
- return StorageConstants.ROW_STORAGE_MODE;
- }
-
- /** {@inheritDoc} */
- @Override public int accessMode() {
- return StorageConstants.RANDOM_ACCESS_MODE;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isArrayBased() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public double[] data() {
- return MatrixUtil.flatten(data, StorageConstants.ROW_STORAGE_MODE);
- }
-
- /** {@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/43a62cdb/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
deleted file mode 100644
index 3b4f27d..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java
+++ /dev/null
@@ -1,141 +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.ml.math.matrix;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.math.MatrixStorage;
-import org.apache.ignite.ml.math.Vector;
-import org.apache.ignite.ml.math.impls.matrix.AbstractMatrix;
-import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector;
-
-/**
- * This example shows how to create custom {@link Matrix} 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 + "].");
-
- 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.");
- }
-
- /**
- * Example of vector with custom storage, modeled after
- * {@link org.apache.ignite.ml.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/43a62cdb/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
deleted file mode 100644
index 755f36c..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java
+++ /dev/null
@@ -1,79 +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.ml.math.matrix;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.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 + "].");
-
- 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/43a62cdb/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
deleted file mode 100644
index af12e15..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/MatrixExampleUtil.java
+++ /dev/null
@@ -1,52 +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.ml.math.matrix;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.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/43a62cdb/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
deleted file mode 100644
index db01794..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java
+++ /dev/null
@@ -1,84 +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.ml.math.matrix;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix;
-
-/**
- * This example shows how to create and use off-heap versions of {@link Matrix}.
- */
-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 + "].");
-
- 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/43a62cdb/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
deleted file mode 100644
index c73a8a0..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java
+++ /dev/null
@@ -1,70 +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.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 create and use {@link SparseDistributedMatrix} API.
- *
- * Unlike the {@link CacheMatrix} the {@link SparseDistributedMatrix} creates it's own cache.
- */
-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);
-
- System.out.println("Sum of all matrix elements is " + distributedMatrix.sum());
-
- 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/43a62cdb/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
deleted file mode 100644
index a03688d..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java
+++ /dev/null
@@ -1,84 +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.ml.math.matrix;
-
-import org.apache.ignite.ml.math.Matrix;
-import org.apache.ignite.ml.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 + "].");
-
- 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/43a62cdb/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
deleted file mode 100644
index 354119a..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/matrix/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 matrix examples.
- */
-package org.apache.ignite.examples.ml.math.matrix;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 52344bf..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/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 examples.
- */
-package org.apache.ignite.examples.ml.math;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index c14335a..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/TracerExample.java
+++ /dev/null
@@ -1,63 +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.ml.math.tracer;
-
-import java.awt.Color;
-import java.io.IOException;
-import org.apache.ignite.ml.math.Tracer;
-import org.apache.ignite.ml.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 <= 1.5)
- return Color.RED;
- else if (d <= 2.5)
- 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, true);
-
- System.out.println("\n>>> Tracer utility example completed.");
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 574e598..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/tracer/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 tracer example.
- */
-package org.apache.ignite.examples.ml.math.tracer;
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 4253ac1..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java
+++ /dev/null
@@ -1,109 +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.ml.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.ml.math.IdentityValueMapper;
-import org.apache.ignite.ml.math.distributed.ValueMapper;
-import org.apache.ignite.ml.math.distributed.VectorKeyMapper;
-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;
-
- /**
- * 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();
- 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(">>>");
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/43a62cdb/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
deleted file mode 100644
index 0289a8c..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/math/vector/ExampleVectorStorage.java
+++ /dev/null
@@ -1,127 +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.ml.math.vector;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-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 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/43a62cdb/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
deleted file mode 100644
index e38f62c..0000000
--- a/examples/src/main/ml/org/apache/ignite/examples/ml/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.ml.math.vector;
-
-import java.util.Arrays;
-import org.apache.ignite.ml.math.Vector;
-import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector;
-
-/**
- * This example shows how to create and use off-heap versions of {@link Vector}.
- */
-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.");
- }
-}