IGNITE-8450: [ML] Cleanup the ML package: remove unused vector/matrix classes.
this closes #3958 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9dccb3db Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9dccb3db Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9dccb3db Branch: refs/heads/master Commit: 9dccb3db5b5392c410e115fb860c16e2b2bcc61a Parents: 0772a96 Author: zaleslaw <[email protected]> Authored: Wed May 16 15:36:30 2018 +0300 Committer: Yury Babak <[email protected]> Committed: Wed May 16 15:36:30 2018 +0300 ---------------------------------------------------------------------- .../CholeskyDecompositionExample.java | 80 -- .../EigenDecompositionExample.java | 69 -- .../decompositions/LUDecompositionExample.java | 83 -- .../decompositions/QRDecompositionExample.java | 82 -- .../SingularValueDecompositionExample.java | 70 -- .../ml/math/decompositions/package-info.java | 22 - .../ml/math/matrix/CacheMatrixExample.java | 102 -- .../math/matrix/MatrixCustomStorageExample.java | 14 - .../examples/ml/math/matrix/MatrixExample.java | 14 - .../ml/math/matrix/OffHeapMatrixExample.java | 14 - .../matrix/SparseDistributedMatrixExample.java | 70 -- .../ml/math/matrix/SparseMatrixExample.java | 15 - .../ml/math/vector/CacheVectorExample.java | 109 --- .../java/org/apache/ignite/ml/math/Algebra.java | 590 ------------ .../java/org/apache/ignite/ml/math/Blas.java | 8 +- .../org/apache/ignite/ml/math/Constants.java | 59 -- .../ignite/ml/math/IdentityValueMapper.java | 56 -- .../org/apache/ignite/ml/math/MathUtils.java | 32 - .../java/org/apache/ignite/ml/math/Matrix.java | 15 - .../org/apache/ignite/ml/math/VectorUtils.java | 3 +- .../decompositions/CholeskyDecomposition.java | 309 ------ .../decompositions/DecompositionSupport.java | 105 --- .../math/decompositions/EigenDecomposition.java | 936 ------------------- .../ml/math/decompositions/LUDecomposition.java | 383 -------- .../ml/math/decompositions/QRDSolver.java | 197 ---- .../ml/math/decompositions/QRDecomposition.java | 212 ----- .../SingularValueDecomposition.java | 623 ------------ .../ml/math/decompositions/package-info.java | 22 - .../ignite/ml/math/distributed/CacheUtils.java | 734 --------------- .../ml/math/distributed/DistributedStorage.java | 35 - .../ml/math/distributed/MatrixKeyMapper.java | 33 - .../ignite/ml/math/distributed/ValueMapper.java | 37 - .../ml/math/distributed/VectorKeyMapper.java | 32 - .../distributed/keys/DataStructureCacheKey.java | 35 - .../math/distributed/keys/MatrixBlockKey.java | 38 - .../math/distributed/keys/RowColMatrixKey.java | 30 - .../math/distributed/keys/VectorBlockKey.java | 34 - .../distributed/keys/impl/MatrixBlockKey.java | 166 ---- .../distributed/keys/impl/SparseMatrixKey.java | 119 --- .../distributed/keys/impl/VectorBlockKey.java | 152 --- .../distributed/keys/impl/package-info.java | 22 - .../ml/math/distributed/keys/package-info.java | 22 - .../ml/math/distributed/package-info.java | 22 - .../ml/math/impls/matrix/AbstractMatrix.java | 24 - .../ml/math/impls/matrix/CacheMatrix.java | 158 ---- .../ml/math/impls/matrix/DiagonalMatrix.java | 101 -- .../ml/math/impls/matrix/FunctionMatrix.java | 95 -- .../ml/math/impls/matrix/MatrixBlockEntry.java | 50 - .../ml/math/impls/matrix/PivotedMatrixView.java | 241 ----- .../ml/math/impls/matrix/RandomMatrix.java | 97 -- .../matrix/SparseBlockDistributedMatrix.java | 314 ------- .../impls/matrix/SparseDistributedMatrix.java | 290 ------ .../math/impls/matrix/TransposedMatrixView.java | 84 -- .../storage/matrix/BlockMatrixStorage.java | 434 --------- .../storage/matrix/BlockVectorStorage.java | 368 -------- .../storage/matrix/CacheMatrixStorage.java | 196 ---- .../storage/matrix/DiagonalMatrixStorage.java | 158 ---- .../storage/matrix/FunctionMatrixStorage.java | 190 ---- .../storage/matrix/PivotedMatrixStorage.java | 266 ------ .../storage/matrix/RandomMatrixStorage.java | 187 ---- .../matrix/SparseDistributedMatrixStorage.java | 330 ------- .../storage/vector/CacheVectorStorage.java | 175 ---- .../storage/vector/ConstantVectorStorage.java | 134 --- .../storage/vector/FunctionVectorStorage.java | 143 --- .../storage/vector/PivotedVectorStorage.java | 176 ---- .../storage/vector/RandomVectorStorage.java | 152 --- .../SingleElementVectorDelegateStorage.java | 145 --- .../vector/SingleElementVectorStorage.java | 145 --- .../vector/SparseDistributedVectorStorage.java | 281 ------ .../impls/vector/AbstractReadOnlyVector.java | 131 --- .../ml/math/impls/vector/CacheVector.java | 140 --- .../ml/math/impls/vector/ConstantVector.java | 84 -- .../ml/math/impls/vector/FunctionVector.java | 112 --- .../ml/math/impls/vector/PivotedVectorView.java | 163 ---- .../ml/math/impls/vector/RandomVector.java | 130 --- .../math/impls/vector/SingleElementVector.java | 102 -- .../impls/vector/SingleElementVectorView.java | 97 -- .../vector/SparseBlockDistributedVector.java | 135 --- .../impls/vector/SparseDistributedVector.java | 147 --- .../ml/math/impls/vector/VectorBlockEntry.java | 47 - .../apache/ignite/ml/math/util/MatrixUtil.java | 17 +- .../ignite/ml/nn/ReplicatedVectorMatrix.java | 14 - .../ignite/ml/structures/LabeledDataset.java | 4 - .../ml/math/MathImplDistributedTestSuite.java | 47 - .../ignite/ml/math/MathImplLocalTestSuite.java | 39 - .../ignite/ml/math/MathImplMainTestSuite.java | 1 - .../CholeskyDecompositionTest.java | 160 ---- .../decompositions/EigenDecompositionTest.java | 193 ---- .../decompositions/LUDecompositionTest.java | 252 ----- .../ml/math/decompositions/QRDSolverTest.java | 87 -- .../decompositions/QRDecompositionTest.java | 141 --- .../SingularValueDecompositionTest.java | 122 --- .../ml/math/impls/matrix/CacheMatrixTest.java | 371 -------- .../math/impls/matrix/DiagonalMatrixTest.java | 209 ----- .../matrix/FunctionMatrixConstructorTest.java | 113 --- .../math/impls/matrix/MatrixAttributeTest.java | 14 +- .../matrix/MatrixImplementationFixtures.java | 135 +-- .../impls/matrix/MatrixImplementationsTest.java | 196 +--- .../impls/matrix/MatrixKeyMapperForTests.java | 74 -- .../PivotedMatrixViewConstructorTest.java | 129 --- .../matrix/RandomMatrixConstructorTest.java | 71 -- .../SparseDistributedBlockMatrixTest.java | 408 -------- .../matrix/SparseDistributedMatrixTest.java | 316 ------- .../impls/matrix/TransposedMatrixViewTest.java | 87 -- .../SparseDistributedMatrixStorageTest.java | 126 --- .../SparseDistributedVectorStorageTest.java | 123 --- .../ml/math/impls/vector/CacheVectorTest.java | 430 --------- .../vector/ConstantVectorConstructorTest.java | 52 -- .../vector/FunctionVectorConstructorTest.java | 121 --- .../PivotedVectorViewConstructorTest.java | 211 ----- .../vector/RandomVectorConstructorTest.java | 145 --- .../SingleElementVectorConstructorTest.java | 159 ---- .../SingleElementVectorViewConstructorTest.java | 137 --- .../SparseBlockDistributedVectorTest.java | 186 ---- .../vector/SparseDistributedVectorTest.java | 191 ---- .../math/impls/vector/VectorAttributesTest.java | 25 +- .../vector/VectorImplementationsFixtures.java | 203 ---- .../impls/vector/VectorImplementationsTest.java | 30 +- .../math/impls/vector/VectorIterableTest.java | 376 -------- .../math/impls/vector/VectorToMatrixTest.java | 50 +- .../apache/ignite/yardstick/ml/DataChanger.java | 65 -- .../IgniteCholeskyDecompositionBenchmark.java | 69 -- .../IgniteEigenDecompositionBenchmark.java | 69 -- .../IgniteLUDecompositionBenchmark.java | 75 -- ...niteSingularValueDecompositionBenchmark.java | 59 -- .../ml/decomposition/package-info.java | 22 - .../math/IgniteAbstractMatrixMulBenchmark.java | 120 --- ...niteDenseLocalOffHeapMatrixMulBenchmark.java | 32 - ...gniteDenseLocalOnHeapMatrixMulBenchmark.java | 32 - ...parseBlockDistributedMatrixMulBenchmark.java | 32 - ...iteSparseDistributedMatrixMul2Benchmark.java | 74 -- ...niteSparseDistributedMatrixMulBenchmark.java | 49 - .../IgniteSparseLocalMatrixMulBenchmark.java | 32 - .../ignite/yardstick/ml/math/package-info.java | 22 - .../ignite/yardstick/ml/package-info.java | 22 - 135 files changed, 47 insertions(+), 18519 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/CholeskyDecompositionExample.java deleted file mode 100644 index ebac2b1..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/EigenDecompositionExample.java deleted file mode 100644 index cda37f4..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/LUDecompositionExample.java deleted file mode 100644 index a815047..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/QRDecompositionExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/QRDecompositionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/QRDecompositionExample.java deleted file mode 100644 index bed99d1..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/SingularValueDecompositionExample.java deleted file mode 100644 index 81406ae..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/package-info.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/decompositions/package-info.java deleted file mode 100644 index 644f8ba..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/CacheMatrixExample.java deleted file mode 100644 index a7cbaab..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java index 3b4f27d..95bf5cc 100644 --- a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java +++ b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixCustomStorageExample.java @@ -63,20 +63,6 @@ public final class MatrixCustomStorageExample { 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."); } http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java index 755f36c..3e5e6ff 100644 --- a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java +++ b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/MatrixExample.java @@ -60,20 +60,6 @@ public final class MatrixExample { 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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java index db01794..8ad1d1d 100644 --- a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java +++ b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/OffHeapMatrixExample.java @@ -65,20 +65,6 @@ public final class OffHeapMatrixExample { 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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseDistributedMatrixExample.java deleted file mode 100644 index c73a8a0..0000000 --- a/examples/src/main/java/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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java index a03688d..2596298 100644 --- a/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java +++ b/examples/src/main/java/org/apache/ignite/examples/ml/math/matrix/SparseMatrixExample.java @@ -64,21 +64,6 @@ public final class SparseMatrixExample { 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/9dccb3db/examples/src/main/java/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/math/vector/CacheVectorExample.java deleted file mode 100644 index 4253ac1..0000000 --- a/examples/src/main/java/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/9dccb3db/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java deleted file mode 100644 index c54e390..0000000 --- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Algebra.java +++ /dev/null @@ -1,590 +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. - */ - -/* -Copyright 1999 CERN - European Organization for Nuclear Research. -Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose -is hereby granted without fee, provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear in supporting documentation. -CERN makes no representations about the suitability of this software for any purpose. -It is provided "as is" without expressed or implied warranty. -*/ - -package org.apache.ignite.ml.math; - -/** - * Miscellaneous arithmetic and algebra functions. - * Lifted from Apache Mahout. - */ -public class Algebra extends Constants { - /** */ - private static final double[] STIRLING_CORRECTION = { - 0.0, - 8.106146679532726e-02, 4.134069595540929e-02, - 2.767792568499834e-02, 2.079067210376509e-02, - 1.664469118982119e-02, 1.387612882307075e-02, - 1.189670994589177e-02, 1.041126526197209e-02, - 9.255462182712733e-03, 8.330563433362871e-03, - 7.573675487951841e-03, 6.942840107209530e-03, - 6.408994188004207e-03, 5.951370112758848e-03, - 5.554733551962801e-03, 5.207655919609640e-03, - 4.901395948434738e-03, 4.629153749334029e-03, - 4.385560249232324e-03, 4.166319691996922e-03, - 3.967954218640860e-03, 3.787618068444430e-03, - 3.622960224683090e-03, 3.472021382978770e-03, - 3.333155636728090e-03, 3.204970228055040e-03, - 3.086278682608780e-03, 2.976063983550410e-03, - 2.873449362352470e-03, 2.777674929752690e-03, - }; - - /** */ - private static final double[] LOG_FACTORIALS = { - 0.00000000000000000, 0.00000000000000000, 0.69314718055994531, - 1.79175946922805500, 3.17805383034794562, 4.78749174278204599, - 6.57925121201010100, 8.52516136106541430, 10.60460290274525023, - 12.80182748008146961, 15.10441257307551530, 17.50230784587388584, - 19.98721449566188615, 22.55216385312342289, 25.19122118273868150, - 27.89927138384089157, 30.67186010608067280, 33.50507345013688888, - 36.39544520803305358, 39.33988418719949404, 42.33561646075348503, - 45.38013889847690803, 48.47118135183522388, 51.60667556776437357, - 54.78472939811231919, 58.00360522298051994, 61.26170176100200198, - 64.55753862700633106, 67.88974313718153498, 71.25703896716800901 - }; - - /** */ - private static final long[] LONG_FACTORIALS = { - 1L, - 1L, - 2L, - 6L, - 24L, - 120L, - 720L, - 5040L, - 40320L, - 362880L, - 3628800L, - 39916800L, - 479001600L, - 6227020800L, - 87178291200L, - 1307674368000L, - 20922789888000L, - 355687428096000L, - 6402373705728000L, - 121645100408832000L, - 2432902008176640000L - }; - - /** */ - private static final double[] DOUBLE_FACTORIALS = { - 5.109094217170944E19, - 1.1240007277776077E21, - 2.585201673888498E22, - 6.204484017332394E23, - 1.5511210043330984E25, - 4.032914611266057E26, - 1.0888869450418352E28, - 3.048883446117138E29, - 8.841761993739701E30, - 2.652528598121911E32, - 8.222838654177924E33, - 2.6313083693369355E35, - 8.68331761881189E36, - 2.952327990396041E38, - 1.0333147966386144E40, - 3.719933267899013E41, - 1.3763753091226346E43, - 5.23022617466601E44, - 2.0397882081197447E46, - 8.15915283247898E47, - 3.34525266131638E49, - 1.4050061177528801E51, - 6.041526306337384E52, - 2.6582715747884495E54, - 1.196222208654802E56, - 5.502622159812089E57, - 2.5862324151116827E59, - 1.2413915592536068E61, - 6.082818640342679E62, - 3.0414093201713376E64, - 1.5511187532873816E66, - 8.06581751709439E67, - 4.274883284060024E69, - 2.308436973392413E71, - 1.2696403353658264E73, - 7.109985878048632E74, - 4.052691950487723E76, - 2.350561331282879E78, - 1.386831185456898E80, - 8.32098711274139E81, - 5.075802138772246E83, - 3.146997326038794E85, - 1.9826083154044396E87, - 1.2688693218588414E89, - 8.247650592082472E90, - 5.443449390774432E92, - 3.6471110918188705E94, - 2.48003554243683E96, - 1.7112245242814127E98, - 1.1978571669969892E100, - 8.504785885678624E101, - 6.123445837688612E103, - 4.470115461512686E105, - 3.307885441519387E107, - 2.4809140811395404E109, - 1.8854947016660506E111, - 1.451830920282859E113, - 1.1324281178206295E115, - 8.94618213078298E116, - 7.15694570462638E118, - 5.797126020747369E120, - 4.7536433370128435E122, - 3.94552396972066E124, - 3.314240134565354E126, - 2.8171041143805494E128, - 2.4227095383672744E130, - 2.107757298379527E132, - 1.854826422573984E134, - 1.6507955160908465E136, - 1.4857159644817605E138, - 1.3520015276784033E140, - 1.2438414054641305E142, - 1.156772507081641E144, - 1.0873661566567426E146, - 1.0329978488239061E148, - 9.916779348709491E149, - 9.619275968248216E151, - 9.426890448883248E153, - 9.332621544394415E155, - 9.332621544394418E157, - 9.42594775983836E159, - 9.614466715035125E161, - 9.902900716486178E163, - 1.0299016745145631E166, - 1.0813967582402912E168, - 1.1462805637347086E170, - 1.2265202031961373E172, - 1.324641819451829E174, - 1.4438595832024942E176, - 1.5882455415227423E178, - 1.7629525510902457E180, - 1.974506857221075E182, - 2.2311927486598138E184, - 2.543559733472186E186, - 2.925093693493014E188, - 3.393108684451899E190, - 3.96993716080872E192, - 4.6845258497542896E194, - 5.574585761207606E196, - 6.689502913449135E198, - 8.094298525273444E200, - 9.875044200833601E202, - 1.2146304367025332E205, - 1.506141741511141E207, - 1.882677176888926E209, - 2.3721732428800483E211, - 3.0126600184576624E213, - 3.856204823625808E215, - 4.974504222477287E217, - 6.466855489220473E219, - 8.471580690878813E221, - 1.1182486511960037E224, - 1.4872707060906847E226, - 1.99294274616152E228, - 2.690472707318049E230, - 3.6590428819525483E232, - 5.0128887482749884E234, - 6.917786472619482E236, - 9.615723196941089E238, - 1.3462012475717523E241, - 1.8981437590761713E243, - 2.6953641378881633E245, - 3.8543707171800694E247, - 5.550293832739308E249, - 8.047926057471989E251, - 1.1749972043909107E254, - 1.72724589045464E256, - 2.5563239178728637E258, - 3.8089226376305687E260, - 5.7133839564458575E262, - 8.627209774233244E264, - 1.3113358856834527E267, - 2.0063439050956838E269, - 3.0897696138473515E271, - 4.789142901463393E273, - 7.471062926282892E275, - 1.1729568794264134E278, - 1.8532718694937346E280, - 2.946702272495036E282, - 4.714723635992061E284, - 7.590705053947223E286, - 1.2296942187394494E289, - 2.0044015765453032E291, - 3.287218585534299E293, - 5.423910666131583E295, - 9.003691705778434E297, - 1.5036165148649983E300, - 2.5260757449731988E302, - 4.2690680090047056E304, - 7.257415615308004E306 - }; - - /** - * Efficiently returns the binomial coefficient, often also referred to as - * "n over k" or "n choose k". The binomial coefficient is defined as - * {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )}. - * <ul> <li>{@code k<0}: {@code 0}.</li> - * <li>{@code k==0}: {@code 1}.</li> - * <li>{@code k==1}: {@code n}.</li> - * <li>else: {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k)}.</li> - * </ul> - * - * @param n Size of set. - * @param k Size of subset. - * @return Binomial coefficient. - */ - public static double binomial(double n, long k) { - if (k < 0) - return 0; - - if (k == 0) - return 1; - - if (k == 1) - return n; - - // binomial(n,k) = (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k ) - double a = n - k + 1; - double b = 1; - double binomial = 1; - - for (long i = k; i-- > 0; ) - binomial *= (a++) / (b++); - - return binomial; - } - - /** - * Efficiently returns the binomial coefficient, often also referred to as "n over k" or "n choose k". - * The binomial coefficient is defined as - * <ul> <li>{@code k<0}: {@code 0}. <li>{@code k==0 || k==n}: {@code 1}. <li>{@code k==1 || k==n-1}: - * {@code n}. <li>else: {@code (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k )}. </ul> - * - * @param n Size of set. - * @param k Size of subset. - * @return Binomial coefficient. - */ - public static double binomial(long n, long k) { - if (k < 0) - return 0; - - if (k == 0 || k == n) - return 1; - - if (k == 1 || k == n - 1) - return n; - - if (n > k) { - int max = LONG_FACTORIALS.length + DOUBLE_FACTORIALS.length; - - if (n < max) { - double nFac = factorial((int)n); - double kFac = factorial((int)k); - double nMinusKFac = factorial((int)(n - k)); - double nk = nMinusKFac * kFac; - - if (nk != Double.POSITIVE_INFINITY) // No numeric overflow? - return nFac / nk; - } - - if (k > n / 2) - k = n - k; - } - - // binomial(n,k) = (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k ) - long a = n - k + 1; - long b = 1; - double binomial = 1; - - for (long i = k; i-- > 0; ) - binomial *= (double)a++ / (b++); - - return binomial; - } - - /** - * Returns the smallest <code>long >= value</code>. - * <dl><dt>Examples: {@code 1.0 -> 1, 1.2 -> 2, 1.9 -> 2}. This - * method is safer than using (long) Math.ceil(value), because of possible rounding error.</dt></dl> - * - * @param val Value for ceil. - * @return Ceil of the given value. - */ - public static long ceil(double val) { - return Math.round(Math.ceil(val)); - } - - /** - * Evaluates the series of Chebyshev polynomials Ti at argument x/2. The series is given by - * <pre class="snippet"> - * N-1 - * - ' - * y = > coef[i] T (x/2) - * - i - * i=0 - * </pre> - * Coefficients are stored in reverse order, i.e. the zero order term is last in the array. Note N is the number of - * coefficients, not the order. - * <p> - * If coefficients are for the interval a to b, x must have been transformed to x - * -< 2(2x - b - a)/(b-a) before entering the routine. This maps x from (a, b) to (-1, 1), over which the - * Chebyshev polynomials are defined.</p> - * <p> - * If the coefficients are for the inverted interval, in which (a, b) is - * mapped to (1/b, 1/a), the transformation required is {@code x -> 2(2ab/x - b - a)/(b-a)}. If b is infinity, this - * becomes {@code x -> 4a/x - 1}.</p> - * <p> - * SPEED: - * </p> - * Taking advantage of the recurrence properties of the Chebyshev - * polynomials, the routine requires one more addition per loop than evaluating a nested polynomial of the same - * degree. - * - * @param x Argument to the polynomial. - * @param coef Coefficients of the polynomial. - * @param N Number of coefficients. - */ - public static double chbevl(double x, double[] coef, int N) { - int p = 0; - - double b0 = coef[p++]; - double b1 = 0.0; - int i = N - 1; - - double b2; - - do { - b2 = b1; - b1 = b0; - b0 = x * b1 - b2 + coef[p++]; - } - while (--i > 0); - - return 0.5 * (b0 - b2); - } - - /** - * Instantly returns the factorial {@code k!}. - * - * @param k must hold {@code k >= 0}. - */ - private static double factorial(int k) { - if (k < 0) - throw new IllegalArgumentException(); - - int len1 = LONG_FACTORIALS.length; - - if (k < len1) - return LONG_FACTORIALS[k]; - - int len2 = DOUBLE_FACTORIALS.length; - - return (k < len1 + len2) ? DOUBLE_FACTORIALS[k - len1] : Double.POSITIVE_INFINITY; - } - - /** - * Returns the largest <code>long <= value</code>. - * <dl><dt>Examples: {@code 1.0 -> 1, 1.2 -> 1, 1.9 -> 1 <dt> 2.0 -> 2, 2.2 -> 2, 2.9 -> 2}</dt></dl> - * This method is safer than using (long) Math.floor(value), because of possible rounding error. - */ - public static long floor(double val) { - return Math.round(Math.floor(val)); - } - - /** - * Returns {@code log<sub>base</sub>value}. - */ - public static double log(double base, double val) { - return Math.log(val) / Math.log(base); - } - - /** - * Returns {@code log<sub>10</sub>value}. - */ - public static double log10(double val) { - // 1.0 / Math.log(10) == 0.43429448190325176 - return Math.log(val) * 0.43429448190325176; - } - - /** - * Returns {@code log<sub>2</sub>value}. - */ - public static double log2(double val) { - // 1.0 / Math.log(2) == 1.4426950408889634 - return Math.log(val) * 1.4426950408889634; - } - - /** - * Returns {@code log(k!)}. Tries to avoid overflows. For {@code k<30} simply looks up a table in O(1). - * For {@code k>=30} uses Stirling's approximation. - * - * @param k must hold {@code k >= 0}. - */ - public static double logFactorial(int k) { - if (k >= 30) { - double r = 1.0 / k; - double rr = r * r; - double C7 = -5.95238095238095238e-04; - double C5 = 7.93650793650793651e-04; - double C3 = -2.77777777777777778e-03; - double C1 = 8.33333333333333333e-02; - double C0 = 9.18938533204672742e-01; - - return (k + 0.5) * Math.log(k) - k + C0 + r * (C1 + rr * (C3 + rr * (C5 + rr * C7))); - } - else - return LOG_FACTORIALS[k]; - } - - /** - * Instantly returns the factorial {@code k!}. - * - * @param k must hold {@code k >= 0 && k < 21} - */ - public static long longFactorial(int k) { - if (k < 0) - throw new IllegalArgumentException("Negative k"); - - if (k < LONG_FACTORIALS.length) - return LONG_FACTORIALS[k]; - - throw new IllegalArgumentException("Overflow"); - } - - /** - * Returns the StirlingCorrection. - * <p> - * Correction term of the Stirling approximation for {@code log(k!)} (series in - * 1/k, or table values for small k) with int parameter k. {@code log k! = (k + 1/2)log(k + 1) - (k + 1) + - * (1/2)log(2Pi) + STIRLING_CORRECTION(k + 1) log k! = (k + 1/2)log(k) - k + (1/2)log(2Pi) + - * STIRLING_CORRECTION(k) } </p> - */ - public static double stirlingCorrection(int k) { - if (k > 30) { - double r = 1.0 / k; - double rr = r * r; - double C7 = -5.95238095238095238e-04; - double C5 = 7.93650793650793651e-04; - double C3 = -2.77777777777777778e-03; - double C1 = 8.33333333333333333e-02; - - return r * (C1 + rr * (C3 + rr * (C5 + rr * C7))); - } - else - return STIRLING_CORRECTION[k]; - } - - /** - * Evaluates the given polynomial of degree {@code N} at {@code x}, assuming coefficient of N is 1.0. Otherwise same - * as {@link #evalPoly(double, double[], int)}. - * <pre class="snippet"> - * 2 N - * y = C + C x + C x +...+ C x - * 0 1 2 N - * </pre> - * where <pre class="snippet"> - * C = 1 - * N - * </pre> - * and hence is omitted from the array. - * <p> - * Coefficients are stored in reverse order:</p> - * <pre class="snippet"> - * coef[0] = C , ..., coef[N-1] = C . - * N-1 0 - * </pre> - * Calling arguments are otherwise the same as {@link #evalPoly(double, double[], int)}. - * <p> - * In the interest of speed, there are no checks for out of bounds arithmetic. - * - * @param x Argument to the polynomial. - * @param coef Coefficients of the polynomial. - * @param n Degree of the polynomial. - */ - public static double evalPoly1(double x, double[] coef, int n) { - double res = x + coef[0]; - - for (int i = 1; i < n; i++) - res = res * x + coef[i]; - - return res; - } - - /** - * Evaluates the given polynomial of degree {@code N} at {@code x}. - * <pre class="snippet"> - * 2 N - * y = C + C x + C x +...+ C x - * 0 1 2 N - * </pre> - * <p> - * Coefficients are stored in reverse order:</p> - * <pre class="snippet"> - * coef[0] = C , ..., coef[N] = C . - * N 0 - * </pre> - * <p> - * In the interest of speed, there are no checks for out of bounds arithmetic.</p> - * - * @param x Argument to the polynomial. - * @param coef Coefficients of the polynomial. - * @param n Degree of the polynomial. - */ - public static double evalPoly(double x, double[] coef, int n) { - double res = coef[0]; - - for (int i = 1; i <= n; i++) - res = res * x + coef[i]; - - return res; - } - - /** - * Gets <code>sqrt(a^2 + b^2)</code> without under/overflow. - * - * @param a First side value. - * @param b Second side value. - * @return Hypotenuse value. - */ - public static double hypot(double a, double b) { - double r; - - if (Math.abs(a) > Math.abs(b)) { - r = b / a; - r = Math.abs(a) * Math.sqrt(1 + r * r); - } - else if (b != 0) { - r = a / b; - r = Math.abs(b) * Math.sqrt(1 + r * r); - } - else - r = 0.0; - - return r; - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java index 9929725..bc603c8 100644 --- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java +++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Blas.java @@ -25,10 +25,7 @@ import org.apache.ignite.ml.math.exceptions.MathIllegalArgumentException; import org.apache.ignite.ml.math.exceptions.NonSquareMatrixException; import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix; import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; -import org.apache.ignite.ml.math.impls.matrix.SparseBlockDistributedMatrix; -import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix; import org.apache.ignite.ml.math.impls.matrix.SparseLocalOnHeapMatrix; -import org.apache.ignite.ml.math.impls.vector.CacheVector; import org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector; import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector; import org.apache.ignite.ml.math.impls.vector.SparseLocalOffHeapVector; @@ -271,8 +268,7 @@ public class Blas { * Currently we support only local onheap matrices for BLAS. */ private static void checkMatrixType(Matrix a, String op) { - if (a instanceof DenseLocalOffHeapMatrix || a instanceof SparseDistributedMatrix - || a instanceof SparseBlockDistributedMatrix) + if (a instanceof DenseLocalOffHeapMatrix) throw new IllegalArgumentException("Operation doesn't support for matrix [class=" + a.getClass().getName() + ", operation=" + op + "]."); } @@ -281,7 +277,7 @@ public class Blas { * Currently we support only local onheap vectors for BLAS. */ private static void checkVectorType(Vector a, String op) { - if (a instanceof DenseLocalOffHeapVector || a instanceof SparseLocalOffHeapVector || a instanceof CacheVector) + if (a instanceof DenseLocalOffHeapVector || a instanceof SparseLocalOffHeapVector) throw new IllegalArgumentException("Operation doesn't support for vector [class=" + a.getClass().getName() + ", operation=" + op + "]."); } http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java deleted file mode 100644 index f9b6c88..0000000 --- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Constants.java +++ /dev/null @@ -1,59 +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. - */ - -/* -Copyright 1999 CERN - European Organization for Nuclear Research. -Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose -is hereby granted without fee, provided that the above copyright notice appear in all copies and -that both that copyright notice and this permission notice appear in supporting documentation. -CERN makes no representations about the suitability of this software for any purpose. -It is provided "as is" without expressed or implied warranty. -*/ - -package org.apache.ignite.ml.math; - -/** - * Math constants. Lifted from Apache Mahout. - */ -public class Constants { - /** Constant for {@code 2**-53}. */ - public static final double MACHEP = 1.11022302462515654042E-16; - - /** Constant for {@code log(2**1024)}. */ - public static final double MAXLOG = 7.09782712893383996732E2; - - /** Constant for {@code log(2**-1022)}. */ - public static final double MINLOG = -7.451332191019412076235E2; - - /** Constant for gamma function. */ - public static final double MAXGAM = 171.624376956302725; - - /** Constant for {@code 1/(sqrt(2*pi))}. */ - public static final double SQTPI = 2.50662827463100050242E0; - - /** Constant for {@code sqrt(2)/2}. */ - public static final double SQRTH = 7.07106781186547524401E-1; - - /** Constant for {@code log(Pi)}. */ - public static final double LOGPI = 1.14472988584940017414; - - /** Constant for big value. */ - public static final double BIG = 4.503599627370496e15; - - /** Constant for inverse of big value. */ - public static final double BIGINV = 2.22044604925031308085e-16; -} http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java deleted file mode 100644 index 615006e..0000000 --- a/modules/ml/src/main/java/org/apache/ignite/ml/math/IdentityValueMapper.java +++ /dev/null @@ -1,56 +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.ml.math; - -import org.apache.ignite.ml.math.distributed.ValueMapper; - -/** - * Identity value mapper. - */ -public class IdentityValueMapper implements ValueMapper<Double> { - /** */ - private static final long serialVersionUID = -8010078306142216389L; - - /** {@inheritDoc} */ - @Override public Double fromDouble(double v) { - return v; - } - - /** {@inheritDoc} */ - @Override public double toDouble(Double v) { - assert v != null; - - return v; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return Long.hashCode(serialVersionUID); - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (o == null || getClass() != o.getClass()) - return false; - - return true; - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/modules/ml/src/main/java/org/apache/ignite/ml/math/MathUtils.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/MathUtils.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/MathUtils.java deleted file mode 100644 index c7b33c3..0000000 --- a/modules/ml/src/main/java/org/apache/ignite/ml/math/MathUtils.java +++ /dev/null @@ -1,32 +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.ml.math; - -import org.apache.ignite.ml.math.exceptions.NullArgumentException; - -/** - * Miscellaneous utility functions. - */ -public final class MathUtils { - /** */ - public static void checkNotNull(Object o) - throws NullArgumentException { - if (o == null) - throw new NullArgumentException(); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java index 9d1ece4..0e85659 100644 --- a/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java +++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/Matrix.java @@ -280,21 +280,6 @@ public interface Matrix extends MetaAttributes, Externalizable, StorageOpsMetric public int rowSize(); /** - * Returns matrix determinant using Laplace theorem. - * - * @return A determinant for this matrix. - * @throws CardinalityException Thrown if matrix is not square. - */ - public double determinant(); - - /** - * Returns the inverse matrix of this matrix - * - * @return Inverse of this matrix - */ - public Matrix inverse(); - - /** * Divides each value in this matrix by the argument. * * @param x Divider value. http://git-wip-us.apache.org/repos/asf/ignite/blob/9dccb3db/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorUtils.java ---------------------------------------------------------------------- diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorUtils.java b/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorUtils.java index 2f51245..85c61bb 100644 --- a/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorUtils.java +++ b/modules/ml/src/main/java/org/apache/ignite/ml/math/VectorUtils.java @@ -21,7 +21,6 @@ import java.util.Map; import org.apache.ignite.ml.math.functions.IgniteBiFunction; import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector; import org.apache.ignite.ml.math.impls.vector.MapWrapperVector; -import org.apache.ignite.ml.math.impls.vector.SparseDistributedVector; /** * Some utils for {@link Vector}. @@ -62,7 +61,7 @@ public class VectorUtils { * @return One-hot encoded number. */ public static Vector num2Vec(int num, int vecSize, boolean isDistributed) { - Vector res = isDistributed ? new SparseDistributedVector(vecSize) : new DenseLocalOnHeapVector(vecSize); + Vector res = new DenseLocalOnHeapVector(vecSize); return res.setX(num, 1); }
