IGNITE-6123: First performance measurement of implemented ml algorithms this closes #2780
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2e65a785 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2e65a785 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2e65a785 Branch: refs/heads/ignite-zk-ce Commit: 2e65a7857fe13161dd3211634531c93284ce3faa Parents: 9656929 Author: Oleg Ignatenko <[email protected]> Authored: Tue Dec 12 15:16:03 2017 +0300 Committer: Yury Babak <[email protected]> Committed: Tue Dec 12 15:16:03 2017 +0300 ---------------------------------------------------------------------- modules/yardstick/DEVNOTES-standalone.txt | 11 +- modules/yardstick/DEVNOTES.txt | 11 ++ .../yardstick/config/benchmark-ml.properties | 87 +++++++++++++++ modules/yardstick/pom-standalone.xml | 46 +++++++- modules/yardstick/pom.xml | 44 ++++++++ .../apache/ignite/yardstick/ml/DataChanger.java | 65 ++++++++++++ ...niteKMeansDistributedClustererBenchmark.java | 76 +++++++++++++ .../IgniteKMeansLocalClustererBenchmark.java | 50 +++++++++ .../yardstick/ml/clustering/package-info.java | 22 ++++ .../IgniteCholeskyDecompositionBenchmark.java | 69 ++++++++++++ .../IgniteEigenDecompositionBenchmark.java | 69 ++++++++++++ .../IgniteLUDecompositionBenchmark.java | 75 +++++++++++++ ...niteSingularValueDecompositionBenchmark.java | 59 +++++++++++ .../ml/decomposition/package-info.java | 22 ++++ .../math/IgniteAbstractMatrixMulBenchmark.java | 106 +++++++++++++++++++ ...niteDenseLocalOffHeapMatrixMulBenchmark.java | 32 ++++++ ...gniteDenseLocalOnHeapMatrixMulBenchmark.java | 32 ++++++ ...parseBlockDistributedMatrixMulBenchmark.java | 32 ++++++ ...niteSparseDistributedMatrixMulBenchmark.java | 35 ++++++ .../IgniteSparseLocalMatrixMulBenchmark.java | 32 ++++++ .../ignite/yardstick/ml/math/package-info.java | 22 ++++ .../ignite/yardstick/ml/package-info.java | 22 ++++ ...iteOLSMultipleLinearRegressionBenchmark.java | 92 ++++++++++++++++ .../yardstick/ml/regression/package-info.java | 22 ++++ 24 files changed, 1131 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/DEVNOTES-standalone.txt ---------------------------------------------------------------------- diff --git a/modules/yardstick/DEVNOTES-standalone.txt b/modules/yardstick/DEVNOTES-standalone.txt index 50aa7c4..4636e8f 100644 --- a/modules/yardstick/DEVNOTES-standalone.txt +++ b/modules/yardstick/DEVNOTES-standalone.txt @@ -7,10 +7,19 @@ mvn clean package Artifacts can be found in `/target/assembly directory.` +Building from standalone sources with ML Grid benchmarks +==================================================== + +You need Java 8 or higher and "ml" profile enabled. Run + +mvn clean package -Pml + +See also: https://apacheignite.readme.io/docs/machine-learning#section-getting-started + Writing Ignite Benchmarks ========================= All benchmarks extend `AbstractBenchmark` class. A new benchmark should also extend this abstract class and implement `test` method. This method is the entry point for -a benchmark execution. \ No newline at end of file +a benchmark execution. http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/DEVNOTES.txt ---------------------------------------------------------------------- diff --git a/modules/yardstick/DEVNOTES.txt b/modules/yardstick/DEVNOTES.txt index b8b1f53..9f79f55 100644 --- a/modules/yardstick/DEVNOTES.txt +++ b/modules/yardstick/DEVNOTES.txt @@ -12,6 +12,17 @@ This command will compile the project and also unpack scripts from `yardstick-re Artifacts can be found in `modules/yardstick/target/assembly` directory. +Building from Ignite sources with ML Grid benchmarks +==================================================== + +You need Java 8 or higher and "ml" profile enabled. Run + +mvn clean package -Pyardstick -Pml -pl modules/yardstick -am -DskipTests + +in the Apache Ignite root directory. + +See also: https://apacheignite.readme.io/docs/machine-learning#section-getting-started + Writing Ignite Benchmarks ========================= http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/config/benchmark-ml.properties ---------------------------------------------------------------------- diff --git a/modules/yardstick/config/benchmark-ml.properties b/modules/yardstick/config/benchmark-ml.properties new file mode 100644 index 0000000..ef20773 --- /dev/null +++ b/modules/yardstick/config/benchmark-ml.properties @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Contains benchmarks for ML Grid methods. +# + +# JVM options. +JVM_OPTS=${JVM_OPTS}" -DIGNITE_QUIET=false" + +# Uncomment to enable concurrent garbage collection (GC) if you encounter long GC pauses. +# JVM_OPTS=${JVM_OPTS}" \ +# -Xms6g \ +# -Xmx6g \ +# -Xloggc:./gc${now0}.log \ +# -XX:+PrintGCDetails \ +# -verbose:gc \ +# -XX:+UseParNewGC \ +# -XX:+UseConcMarkSweepGC \ +# " + +#Ignite version +ver="RELEASE-" + +# List of default probes. +# Add DStatProbe or VmStatProbe if your OS supports it (e.g. if running on Linux). +BENCHMARK_DEFAULT_PROBES=ThroughputLatencyProbe,PercentileProbe + +# Packages where the specified benchmark is searched by reflection mechanism. +BENCHMARK_PACKAGES=org.yardstickframework,org.apache.ignite.yardstick + +# Probe point writer class name. +# BENCHMARK_WRITER= + +# Comma-separated list of the hosts to run BenchmarkServers on. 2 nodes on local host are enabled by default. +SERVER_HOSTS=localhost,localhost + +# Comma-separated list of the hosts to run BenchmarkDrivers on. 1 node on local host is enabled by default. +DRIVER_HOSTS=localhost + +# Remote username. +# REMOTE_USER= + +# Number of nodes, used to wait for the specified number of nodes to start. +nodesNum=$((`echo ${SERVER_HOSTS} | tr ',' '\n' | wc -l` + `echo ${DRIVER_HOSTS} | tr ',' '\n' | wc -l`)) + +# Backups count. +b=1 + +# Warmup. +w=60 + +# Duration. +d=300 + +# Threads count. +t=64 + +# Sync mode. +sm=PRIMARY_SYNC + +# Run configuration. +# Note that each benchmark is set to run for 300 seconds (5 min) with warm-up set to 60 seconds (1 minute). +CONFIGS="\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteKMeansLocalClustererBenchmark -sn IgniteNode -ds ${ver}kmeans-local-clusterer-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteOLSMultipleLinearRegressionBenchmark -sn IgniteNode -ds ${ver}ols-multiple-linear-regression-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteSingularValueDecompositionBenchmark -sn IgniteNode -ds ${ver}singular-value-decomposition-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteCholeskyDecompositionBenchmark -sn IgniteNode -ds ${ver}cholesky-decomposition-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteLUDecompositionBenchmark -sn IgniteNode -ds ${ver}lu-decomposition-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteEigenDecompositionBenchmark -sn IgniteNode -ds ${ver}eigen-decomposition-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteDenseLocalOnHeapMatrixMulBenchmark -sn IgniteNode -ds ${ver}dense-local-onheap-matrix-mul-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteDenseLocalOffHeapMatrixMulBenchmark -sn IgniteNode -ds ${ver}dense-local-offheap-matrix-mul-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteSparseLocalMatrixMulBenchmark -sn IgniteNode -ds ${ver}sparse-local-matrix-mul-${b}-backup,\ +-cfg ${SCRIPT_DIR}/../config/ignite-localhost-config.xml -nn ${nodesNum} -b ${b} -w ${w} -d ${d} -t ${t} -sm ${sm} -dn IgniteSparseBlockDistributedMatrixMulBenchmark -sn IgniteNode -ds ${ver}sparse-block-distributed-matrix-mul-${b}-backup,\ +" http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/pom-standalone.xml ---------------------------------------------------------------------- diff --git a/modules/yardstick/pom-standalone.xml b/modules/yardstick/pom-standalone.xml index d6d5a20..78569a3 100644 --- a/modules/yardstick/pom-standalone.xml +++ b/modules/yardstick/pom-standalone.xml @@ -31,6 +31,8 @@ <properties> <yardstick.version>0.8.3</yardstick.version> <spring.version>4.1.0.RELEASE</spring.version> + <!-- Will be changed by profile activation. Allows to combine profiles. --> + <ml.folder>src/main/java</ml.folder> </properties> <dependencies> @@ -101,9 +103,51 @@ </dependency> </dependencies> + <profiles> + <profile> + <id>ml</id> + + <activation> + <jdk>[1.8,)</jdk> + </activation> + + <properties> + <ml.folder>src/main/ml</ml.folder> + <java.ver>1.8</java.ver> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-ml</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </profile> + </profiles> + <build> <plugins> <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-sources</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${ml.folder}</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> <groupId>com.mycila</groupId> <artifactId>license-maven-plugin</artifactId> <version>2.8</version> @@ -206,4 +250,4 @@ </plugin> </plugins> </build> -</project> \ No newline at end of file +</project> http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/pom.xml ---------------------------------------------------------------------- diff --git a/modules/yardstick/pom.xml b/modules/yardstick/pom.xml index 450c4eb..6a98584 100644 --- a/modules/yardstick/pom.xml +++ b/modules/yardstick/pom.xml @@ -39,6 +39,8 @@ <mysql.connector.version>5.1.39</mysql.connector.version> <postgres.connector.version>9.4.1208.jre7</postgres.connector.version> <spring.version>4.1.0.RELEASE</spring.version> + <!-- Will be changed by profile activation. Allows to combine profiles. --> + <ml.folder>src/main/java</ml.folder> </properties> <dependencies> @@ -121,9 +123,51 @@ </dependency> </dependencies> + <profiles> + <profile> + <id>ml</id> + + <activation> + <jdk>[1.8,)</jdk> + </activation> + + <properties> + <ml.folder>src/main/ml</ml.folder> + <java.ver>1.8</java.ver> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-ml</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </profile> + </profiles> + <build> <plugins> <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-sources</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${ml.folder}</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> <groupId>com.mycila</groupId> <artifactId>license-maven-plugin</artifactId> <version>2.8</version> http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/DataChanger.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/DataChanger.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/DataChanger.java new file mode 100644 index 0000000..600113b --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/DataChanger.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.ml; + +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; + +/** + * Helps to ensure use of meaningfully different data in repeated invocations of benchmarked code in + * {@link IgniteAbstractBenchmark#test(Map)} method. + */ +public class DataChanger { + /** */ + private static final AtomicInteger changer = new AtomicInteger(0); + + /** + * @return Positive "seed" to mutate data. + */ + public static double next() { + return (changer.incrementAndGet() % 17) + 1; + } + + /** */ + public static class Scale { + /** */ + private final double scale; + + /** */ + public Scale() { + this.scale = DataChanger.next(); + } + + /** */ + public double[][] mutate(double[][] orig) { + for (int i = 0; i < orig.length; i++) + orig[i] = mutate(orig[i]); + + return orig; + } + + /** */ + public double[] mutate(double[] orig) { + for (int i = 0; i < orig.length; i++) + orig[i] *= scale; + + return orig; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansDistributedClustererBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansDistributedClustererBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansDistributedClustererBenchmark.java new file mode 100644 index 0000000..051ab7b --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansDistributedClustererBenchmark.java @@ -0,0 +1,76 @@ +/* + * 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.yardstick.ml.clustering; + +import java.util.Map; +import org.apache.ignite.Ignite; +import org.apache.ignite.ml.clustering.KMeansDistributedClusterer; +import org.apache.ignite.ml.math.StorageConstants; +import org.apache.ignite.ml.math.distances.EuclideanDistance; +import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.thread.IgniteThread; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + * Todo: IGNITE-7118, enable this benchmark. + */ +@SuppressWarnings("unused") +public class IgniteKMeansDistributedClustererBenchmark extends IgniteAbstractBenchmark { + /** */ + @IgniteInstanceResource + Ignite ignite; + + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + final DataChanger.Scale scale = new DataChanger.Scale(); + + // Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread + // because we create ignite cache internally. + IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), + this.getClass().getSimpleName(), new Runnable() { + /** {@inheritDoc} */ + @Override public void run() { + // IMPL NOTE originally taken from KMeansDistributedClustererTest + KMeansDistributedClusterer clusterer = new KMeansDistributedClusterer( + new EuclideanDistance(), 1, 1, 1L); + + double[] v1 = scale.mutate(new double[] {1959, 325100}); + double[] v2 = scale.mutate(new double[] {1960, 373200}); + + SparseDistributedMatrix points = new SparseDistributedMatrix( + 2, 2, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE); + + points.setRow(0, v1); + points.setRow(1, v2); + + clusterer.cluster(points, 1); + + points.destroy(); + } + }); + + igniteThread.start(); + + igniteThread.join(); + + return true; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansLocalClustererBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansLocalClustererBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansLocalClustererBenchmark.java new file mode 100644 index 0000000..d68fc6d --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/IgniteKMeansLocalClustererBenchmark.java @@ -0,0 +1,50 @@ +/* + * 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.yardstick.ml.clustering; + +import java.util.Map; +import org.apache.ignite.ml.clustering.KMeansLocalClusterer; +import org.apache.ignite.ml.math.distances.EuclideanDistance; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteKMeansLocalClustererBenchmark extends IgniteAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + final DataChanger.Scale scale = new DataChanger.Scale(); + + // IMPL NOTE originally taken from KMeansLocalClustererTest + KMeansLocalClusterer clusterer = new KMeansLocalClusterer(new EuclideanDistance(), 1, 1L); + + double[] v1 = scale.mutate(new double[] {1959, 325100}); + double[] v2 = scale.mutate(new double[] {1960, 373200}); + + DenseLocalOnHeapMatrix points = new DenseLocalOnHeapMatrix(new double[][] { + v1, + v2}); + + clusterer.cluster(points, 1); + + return true; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/package-info.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/package-info.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/package-info.java new file mode 100644 index 0000000..af217d2 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/clustering/package-info.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * <!-- Package description. --> + * ML Grid clustering benchmarks. + */ +package org.apache.ignite.yardstick.ml.clustering; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteCholeskyDecompositionBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteCholeskyDecompositionBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteCholeskyDecompositionBenchmark.java new file mode 100644 index 0000000..6997180 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteCholeskyDecompositionBenchmark.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.ml.decomposition; + +import java.util.Map; +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.Vector; +import org.apache.ignite.ml.math.decompositions.CholeskyDecomposition; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; +import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteCholeskyDecompositionBenchmark extends IgniteAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + runCholeskyDecomposition(); + + return true; + } + + /** + * Based on CholeskyDecompositionTest. + */ + private void runCholeskyDecomposition() { + final DataChanger.Scale scale = new DataChanger.Scale(); + + Matrix m = new DenseLocalOnHeapMatrix(scale.mutate(new double[][] { + {2.0d, -1.0d, 0.0d}, + {-1.0d, 2.0d, -1.0d}, + {0.0d, -1.0d, 2.0d} + })); + + CholeskyDecomposition dec = new CholeskyDecomposition(m); + + dec.getL(); + dec.getLT(); + + Matrix bs = new DenseLocalOnHeapMatrix(scale.mutate(new double[][] { + {4.0, -6.0, 7.0}, + {1.0, 1.0, 1.0} + })).transpose(); + dec.solve(bs); + + Vector b = new DenseLocalOnHeapVector(scale.mutate(new double[] {4.0, -6.0, 7.0})); + dec.solve(b); + + dec.destroy(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteEigenDecompositionBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteEigenDecompositionBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteEigenDecompositionBenchmark.java new file mode 100644 index 0000000..e61c40c --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteEigenDecompositionBenchmark.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.ml.decomposition; + +import java.util.Map; +import org.apache.ignite.ml.math.decompositions.EigenDecomposition; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteEigenDecompositionBenchmark extends IgniteAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + runEigenDecomposition(); + + return true; + } + + /** + * Based on EigenDecompositionTest. + */ + private void runEigenDecomposition() { + final DataChanger.Scale scale = new DataChanger.Scale(); + + EigenDecomposition decomposition1 = new EigenDecomposition(new DenseLocalOnHeapMatrix( + scale.mutate(new double[][] { + {1.0d, 0.0d, 0.0d, 1.0d}, + {0.0d, 1.0d, 0.0d, 1.0d}, + {0.0d, 0.0d, 2.0d, 0.0d}, + {1.0d, 1.0d, 0.0d, 2.0d}}))); + + decomposition1.getD(); + decomposition1.getV(); + + decomposition1.destroy(); + + EigenDecomposition decomposition2 = new EigenDecomposition(new DenseLocalOnHeapMatrix( + scale.mutate(new double[][] { + {1.0d, 0.0d, 0.0d}, + {0.0d, 1.0d, 0.0d}, + {0.0d, 0.0d, 2.0d}, + {1.0d, 1.0d, 0.0d}}))); + // TODO: IGNITE-5828, find out why decomposition of 3X4 matrix throws row index exception + + decomposition2.getD(); + decomposition2.getV(); + + decomposition2.destroy(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteLUDecompositionBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteLUDecompositionBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteLUDecompositionBenchmark.java new file mode 100644 index 0000000..1368ef9 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteLUDecompositionBenchmark.java @@ -0,0 +1,75 @@ +/* + * 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.yardstick.ml.decomposition; + +import java.util.Map; +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.decompositions.LUDecomposition; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; +import org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView; +import org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteLUDecompositionBenchmark extends IgniteAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + runLUDecomposition(); + + return true; + } + + /** + * Based on LUDecompositionTest. + */ + private void runLUDecomposition() { + Matrix testMatrix = new DenseLocalOnHeapMatrix(new DataChanger.Scale().mutate(new double[][] { + {2.0d, 1.0d, 1.0d, 0.0d}, + {4.0d, 3.0d, 3.0d, 1.0d}, + {8.0d, 7.0d, 9.0d, 5.0d}, + {6.0d, 7.0d, 9.0d, 8.0d}})); + + LUDecomposition dec1 = new LUDecomposition(new PivotedMatrixView(testMatrix)); + + dec1.solve(new DenseLocalOnHeapVector(testMatrix.rowSize())); + + dec1.destroy(); + + LUDecomposition dec2 = new LUDecomposition(new PivotedMatrixView(testMatrix)); + + dec2.solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize())); + + dec2.destroy(); + + LUDecomposition dec3 = new LUDecomposition(testMatrix); + + dec3.getL(); + + dec3.getU(); + + dec3.getP(); + + dec3.getPivot(); + + dec3.destroy(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteSingularValueDecompositionBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteSingularValueDecompositionBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteSingularValueDecompositionBenchmark.java new file mode 100644 index 0000000..9f02852 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/IgniteSingularValueDecompositionBenchmark.java @@ -0,0 +1,59 @@ +/* + * 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.yardstick.ml.decomposition; + +import java.util.Map; +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.decompositions.SingularValueDecomposition; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteSingularValueDecompositionBenchmark extends IgniteAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + runSingularValueDecomposition(); + + return true; + } + + /** + * Based on SingularValueDecompositionTest#basicTest. + */ + private void runSingularValueDecomposition() { + Matrix m = new DenseLocalOnHeapMatrix(new DataChanger.Scale().mutate(new double[][] { + {2.0d, -1.0d, 0.0d}, + {-1.0d, 2.0d, -1.0d}, + {0.0d, -1.0d, 2.0d} + })); + + SingularValueDecomposition dec = new SingularValueDecomposition(m); + + Matrix s = dec.getS(); + Matrix u = dec.getU(); + Matrix v = dec.getV(); + + u.times(s).times(v.transpose()); + + dec.destroy(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/package-info.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/package-info.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/package-info.java new file mode 100644 index 0000000..4aaece3 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/decomposition/package-info.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * <!-- Package description. --> + * ML Grid decomposition benchmarks. + */ +package org.apache.ignite.yardstick.ml.decomposition; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java new file mode 100644 index 0000000..31162c3 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteAbstractMatrixMulBenchmark.java @@ -0,0 +1,106 @@ +/* + * 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.yardstick.ml.math; + +import java.util.Map; +import org.apache.ignite.Ignite; +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.thread.IgniteThread; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +abstract class IgniteAbstractMatrixMulBenchmark extends IgniteAbstractBenchmark { + /** */ + private static final int SIZE = 1 << 8; + + /** */ + private double[][] dataSquare = createAndFill(SIZE, SIZE); + + /** */ + private double[][] dataRect1 = createAndFill(SIZE / 2, SIZE); + + /** */ + private double[][] dataRect2 = createAndFill(SIZE, SIZE / 2); + + /** */ + @IgniteInstanceResource + Ignite ignite; + + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + final double scale = DataChanger.next(); + + // Create IgniteThread, we may want to work with SparseDistributedMatrix inside IgniteThread + // because we create ignite cache internally. + IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), + this.getClass().getSimpleName(), new Runnable() { + /** {@inheritDoc} */ + @Override public void run() { + Matrix m1, m2, m3, m4, m5, m6; + + Matrix m7 = (m1 = createAndFill(dataSquare, scale)).times((m2 = createAndFill(dataSquare, scale))); + Matrix m8 = (m3 = createAndFill(dataRect1, scale)).times((m4 = createAndFill(dataRect2, scale))); + Matrix m9 = (m5 = createAndFill(dataRect2, scale)).times((m6 = createAndFill(dataRect1, scale))); + + m1.destroy(); + m2.destroy(); + m3.destroy(); + m4.destroy(); + m5.destroy(); + m6.destroy(); + m7.destroy(); + m8.destroy(); + m9.destroy(); + } + }); + + igniteThread.start(); + + igniteThread.join(); + + return true; + } + + /** Override in subclasses with specific type Matrix. */ + abstract Matrix newMatrix(int rowSize, int colSize); + + /** */ + private Matrix createAndFill(double[][] data, double scale) { + Matrix res = newMatrix(data.length, data[0].length).assign(data); + + for (int i = 0; i < data.length && i < data[0].length; i++) + res.set(i, i, data[i][i] * scale); + + return res; + } + + /** */ + private double[][] createAndFill(int rowSize, int colSize) { + double[][] data = new double[rowSize][colSize]; + + for (int i = 0; i < rowSize; i++) + for (int j = 0; j < colSize; j++) + data[i][j] = -0.5d + Math.random(); + + return data; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOffHeapMatrixMulBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOffHeapMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOffHeapMatrixMulBenchmark.java new file mode 100644 index 0000000..027b515 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOffHeapMatrixMulBenchmark.java @@ -0,0 +1,32 @@ +/* + * 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.yardstick.ml.math; + +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOffHeapMatrix; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteDenseLocalOffHeapMatrixMulBenchmark extends IgniteAbstractMatrixMulBenchmark { + /** {@inheritDoc} */ + @Override Matrix newMatrix(int rowSize, int colSize) { + return new DenseLocalOffHeapMatrix(rowSize, colSize); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOnHeapMatrixMulBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOnHeapMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOnHeapMatrixMulBenchmark.java new file mode 100644 index 0000000..6830130 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteDenseLocalOnHeapMatrixMulBenchmark.java @@ -0,0 +1,32 @@ +/* + * 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.yardstick.ml.math; + +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteDenseLocalOnHeapMatrixMulBenchmark extends IgniteAbstractMatrixMulBenchmark { + /** {@inheritDoc} */ + @Override Matrix newMatrix(int rowSize, int colSize) { + return new DenseLocalOnHeapMatrix(rowSize, colSize); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseBlockDistributedMatrixMulBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseBlockDistributedMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseBlockDistributedMatrixMulBenchmark.java new file mode 100644 index 0000000..8762620 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseBlockDistributedMatrixMulBenchmark.java @@ -0,0 +1,32 @@ +/* + * 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.yardstick.ml.math; + +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.impls.matrix.SparseBlockDistributedMatrix; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteSparseBlockDistributedMatrixMulBenchmark extends IgniteAbstractMatrixMulBenchmark { + /** {@inheritDoc} */ + @Override Matrix newMatrix(int rowSize, int colSize) { + return new SparseBlockDistributedMatrix(rowSize, colSize); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java new file mode 100644 index 0000000..d02ce88 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseDistributedMatrixMulBenchmark.java @@ -0,0 +1,35 @@ +/* + * 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.yardstick.ml.math; + +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.StorageConstants; +import org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix; + +/** + * Ignite benchmark that performs ML Grid operations. + * Todo: IGNITE-7097, complete implementation of this benchmark. + */ +@SuppressWarnings("unused") +public class IgniteSparseDistributedMatrixMulBenchmark extends IgniteAbstractMatrixMulBenchmark { + /** {@inheritDoc} */ + @Override Matrix newMatrix(int rowSize, int colSize) { + return new SparseDistributedMatrix(rowSize, colSize, + StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseLocalMatrixMulBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseLocalMatrixMulBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseLocalMatrixMulBenchmark.java new file mode 100644 index 0000000..de2c99b --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/IgniteSparseLocalMatrixMulBenchmark.java @@ -0,0 +1,32 @@ +/* + * 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.yardstick.ml.math; + +import org.apache.ignite.ml.math.Matrix; +import org.apache.ignite.ml.math.impls.matrix.SparseLocalOnHeapMatrix; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteSparseLocalMatrixMulBenchmark extends IgniteAbstractMatrixMulBenchmark { + /** {@inheritDoc} */ + @Override Matrix newMatrix(int rowSize, int colSize) { + return new SparseLocalOnHeapMatrix(rowSize, colSize); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/package-info.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/package-info.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/package-info.java new file mode 100644 index 0000000..d37e967 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/math/package-info.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * <!-- Package description. --> + * ML Grid math benchmarks. + */ +package org.apache.ignite.yardstick.ml.math; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/package-info.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/package-info.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/package-info.java new file mode 100644 index 0000000..4751f35 --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/package-info.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * <!-- Package description. --> + * ML Grid benchmarks. + */ +package org.apache.ignite.yardstick.ml; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/IgniteOLSMultipleLinearRegressionBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/IgniteOLSMultipleLinearRegressionBenchmark.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/IgniteOLSMultipleLinearRegressionBenchmark.java new file mode 100644 index 0000000..9b36a4a --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/IgniteOLSMultipleLinearRegressionBenchmark.java @@ -0,0 +1,92 @@ +/* + * 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.yardstick.ml.regression; + +import java.util.Map; +import org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix; +import org.apache.ignite.ml.regressions.OLSMultipleLinearRegression; +import org.apache.ignite.yardstick.IgniteAbstractBenchmark; +import org.apache.ignite.yardstick.ml.DataChanger; + +/** + * Ignite benchmark that performs ML Grid operations. + */ +@SuppressWarnings("unused") +public class IgniteOLSMultipleLinearRegressionBenchmark extends IgniteAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + runLongly(); + + return true; + } + + /** + * Based on OLSMultipleLinearRegressionTest#testLongly. + */ + private void runLongly() { + // Y values are first, then independent vars + // Each row is one observation + double[] design = new DataChanger.Scale().mutate(new double[] { + 60323, 83.0, 234289, 2356, 1590, 107608, 1947, + 61122, 88.5, 259426, 2325, 1456, 108632, 1948, + 60171, 88.2, 258054, 3682, 1616, 109773, 1949, + 61187, 89.5, 284599, 3351, 1650, 110929, 1950, + 63221, 96.2, 328975, 2099, 3099, 112075, 1951, + 63639, 98.1, 346999, 1932, 3594, 113270, 1952, + 64989, 99.0, 365385, 1870, 3547, 115094, 1953, + 63761, 100.0, 363112, 3578, 3350, 116219, 1954, + 66019, 101.2, 397469, 2904, 3048, 117388, 1955, + 67857, 104.6, 419180, 2822, 2857, 118734, 1956, + 68169, 108.4, 442769, 2936, 2798, 120445, 1957, + 66513, 110.8, 444546, 4681, 2637, 121950, 1958, + 68655, 112.6, 482704, 3813, 2552, 123366, 1959, + 69564, 114.2, 502601, 3931, 2514, 125368, 1960, + 69331, 115.7, 518173, 4806, 2572, 127852, 1961, + 70551, 116.9, 554894, 4007, 2827, 130081, 1962 + }); + + final int nobs = 16; + final int nvars = 6; + + // Estimate the model + OLSMultipleLinearRegression mdl = new OLSMultipleLinearRegression(); + mdl.newSampleData(design, nobs, nvars, new DenseLocalOnHeapMatrix()); + + // Check expected beta values from NIST + mdl.estimateRegressionParameters(); + + // Check expected residuals from R + mdl.estimateResiduals(); + + // Check standard errors from NIST + mdl.estimateRegressionParametersStandardErrors(); + + // Estimate model without intercept + mdl.setNoIntercept(true); + mdl.newSampleData(design, nobs, nvars, new DenseLocalOnHeapMatrix()); + + // Check expected beta values from R + mdl.estimateRegressionParameters(); + + // Check standard errors from R + mdl.estimateRegressionParametersStandardErrors(); + + // Check expected residuals from R + mdl.estimateResiduals(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2e65a785/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/package-info.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/package-info.java b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/package-info.java new file mode 100644 index 0000000..0a5dc1a --- /dev/null +++ b/modules/yardstick/src/main/ml/org/apache/ignite/yardstick/ml/regression/package-info.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * <!-- Package description. --> + * ML Grid regression benchmarks. + */ +package org.apache.ignite.yardstick.ml.regression; \ No newline at end of file
