From a9978972d7f1e3c1d83702c77be906c419459fcc Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaenko Date: Mon, 24 Feb 2020 17:47:23 +0100 Subject: [PATCH 1/5] Add bench report for the current version of SCAMP --- benchReports/bench-output_currentVersion.csv | 73 ++++++++++++ benchmarks/scampBench.cpp | 118 +++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 benchReports/bench-output_currentVersion.csv create mode 100644 benchmarks/scampBench.cpp diff --git a/benchReports/bench-output_currentVersion.csv b/benchReports/bench-output_currentVersion.csv new file mode 100644 index 0000000..1eabd96 --- /dev/null +++ b/benchReports/bench-output_currentVersion.csv @@ -0,0 +1,73 @@ +name,iterations,real_time,cpu_time,time_unit,bytes_per_second,items_per_second,label,error_occurred,error_message,"Buffers","LockedBuffers","LockedMemory","Memory" +"MatrixProfile/16384/16",100,161772,4062.5,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/16",10,603030,12500,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/16",1,2.73588e+06,31250,us,,,,,,6,3,1.31072e+06,2.22822e+06 +"MatrixProfile/131072/16",1,1.07615e+07,62500,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/32",100,144162,2500,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/32",10,591070,6250,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/32",10,2.32874e+06,23437.5,us,,,,,,5,3,1.31072e+06,2.09715e+06 +"MatrixProfile/131072/32",1,9.42169e+06,46875,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/64",100,139479,3593.75,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/64",10,648435,14062.5,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/64",1,2.62279e+06,15625,us,,,,,,6,3,1.31072e+06,2.22822e+06 +"MatrixProfile/131072/64",1,1.08303e+07,62500,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/128",100,158447,1875,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/128",10,593830,7812.5,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/128",10,2.41331e+06,20312.5,us,,,,,,5,3,1.31072e+06,2.09715e+06 +"MatrixProfile/131072/128",1,9.3667e+06,31250,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/256",100,149078,2343.75,us,,,,,,5,3,326656,522240 +"MatrixProfile/32768/256",10,588560,7812.5,us,,,,,,5,3,654336,1.04653e+06 +"MatrixProfile/65536/256",10,2.33702e+06,18750,us,,,,,,5,3,1.3097e+06,2.0951e+06 +"MatrixProfile/131072/256",1,9.41583e+06,31250,us,,,,,,7,3,2.62042e+06,4.97766e+06 +"MatrixProfile/16384/512",100,168620,2343.75,us,,,,,,5,3,323584,516096 +"MatrixProfile/32768/512",10,662663,6250,us,,,,,,5,3,651264,1.04038e+06 +"MatrixProfile/65536/512",10,2.49522e+06,20312.5,us,,,,,,5,3,1.30662e+06,2.08896e+06 +"MatrixProfile/131072/512",1,9.81205e+06,62500,us,,,,,,8,3,2.61734e+06,5.49274e+06 +"MatrixProfile2/16384/16",10,286369,4687.5,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/16",10,1.14865e+06,7812.5,us,,,,,,6,4,917504,1.31072e+06 +"MatrixProfile2/65536/16",1,6.19764e+06,15625,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/16",1,1.95182e+07,62500,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/32",10,277033,6250,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/32",10,1.18706e+06,4687.5,us,,,,,,6,4,917504,1.31072e+06 +"MatrixProfile2/65536/32",1,5.06217e+06,46875,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/32",1,1.94236e+07,46875,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/64",10,290060,4687.5,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/64",10,1.1533e+06,4687.5,us,,,,,,6,4,917504,1.31072e+06 +"MatrixProfile2/65536/64",1,6.23493e+06,31250,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/64",1,2.28195e+07,31250,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/128",10,300141,4687.5,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/128",10,1.21468e+06,3125,us,,,,,,6,4,917504,1.31072e+06 +"MatrixProfile2/65536/128",1,5.05835e+06,15625,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/128",1,2.02504e+07,31250,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/256",10,417074,6250,us,,,,,,6,4,457728,653312 +"MatrixProfile2/32768/256",10,1.26952e+06,3125,us,,,,,,6,4,916480,1.30867e+06 +"MatrixProfile2/65536/256",1,4.5278e+06,15625,us,,,,,,8,4,1.83398e+06,3.01158e+06 +"MatrixProfile2/131072/256",1,1.8419e+07,62500,us,,,,,,8,4,3.66899e+06,6.02624e+06 +"MatrixProfile2/16384/512",10,457417,6250,us,,,,,,6,4,454656,647168 +"MatrixProfile2/32768/512",10,1.36285e+06,3125,us,,,,,,6,4,913408,1.30253e+06 +"MatrixProfile2/65536/512",1,5.0335e+06,15625,us,,,,,,10,4,1.83091e+06,3.52666e+06 +"MatrixProfile2/131072/512",1,1.92144e+07,46875,us,,,,,,10,4,3.66592e+06,7.0656e+06 +"MatrixProfileLR/16384/16",100,156248,2656.25,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/16",10,574764,6250,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/16",1,2.52639e+06,15625,us,,,,,,11,5,2.09715e+06,3.47341e+06 +"MatrixProfileLR/131072/16",1,9.80606e+06,46875,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/32",100,146878,2656.25,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/32",10,561791,7812.5,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/32",10,2.38982e+06,15625,us,,,,,,9,5,2.09715e+06,3.21126e+06 +"MatrixProfileLR/131072/32",1,9.34682e+06,62500,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/64",100,142890,3125,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/64",10,570182,6250,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/64",10,2.34211e+06,15625,us,,,,,,9,5,2.09715e+06,3.21126e+06 +"MatrixProfileLR/131072/64",1,9.41455e+06,31250,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/128",100,144825,2187.5,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/128",10,562705,3125,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/128",10,2.29637e+06,10937.5,us,,,,,,9,5,2.09715e+06,3.21126e+06 +"MatrixProfileLR/131072/128",1,9.63782e+06,62500,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/256",100,151094,3125,us,,,,,,9,5,522240,799744 +"MatrixProfileLR/32768/256",10,569850,4687.5,us,,,,,,9,5,1.04653e+06,1.60256e+06 +"MatrixProfileLR/65536/256",10,2.37937e+06,18750,us,,,,,,9,5,2.0951e+06,3.20819e+06 +"MatrixProfileLR/131072/256",1,9.63067e+06,62500,us,,,,,,13,5,4.19226e+06,7.99027e+06 +"MatrixProfileLR/16384/512",100,163046,2031.25,us,,,,,,9,5,516096,789504 +"MatrixProfileLR/32768/512",10,604561,3125,us,,,,,,9,5,1.04038e+06,1.59232e+06 +"MatrixProfileLR/65536/512",10,2.37971e+06,15625,us,,,,,,9,5,2.08896e+06,3.19795e+06 +"MatrixProfileLR/131072/512",1,9.34088e+06,31250,us,,,,,,14,5,4.18611e+06,8.49818e+06 diff --git a/benchmarks/scampBench.cpp b/benchmarks/scampBench.cpp new file mode 100644 index 0000000..7a1adc2 --- /dev/null +++ b/benchmarks/scampBench.cpp @@ -0,0 +1,118 @@ +// Copyright (c) 2019 Shapelets.io +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include +#include +#include + +#include +#include + +#include "khivaBenchmark.h" + +template +void MatrixProfile(benchmark::State &state) { + af::setBackend(BE); + af::setDevice(D); + + auto n = state.range(0); + auto m = state.range(1); + + auto tss = af::randu(n, f64); + + af::array profile; + af::array index; + + af::sync(); + while (state.KeepRunning()) { + khiva::matrix::matrixProfile(tss, m, profile, index); + profile.eval(); + index.eval(); + af::sync(); + } + + addMemoryCounters(state); +} + +template +void MatrixProfile2(benchmark::State &state) { + af::setBackend(BE); + af::setDevice(D); + + auto n = state.range(0); + auto m = state.range(1); + + auto ta = af::randu(n, f64); + auto tb = af::randu(n, f64); + + af::array profile; + af::array index; + + af::sync(); + while (state.KeepRunning()) { + khiva::matrix::matrixProfile(ta, tb, m, profile, index); + profile.eval(); + index.eval(); + af::sync(); + } + + addMemoryCounters(state); +} + +template +void MatrixProfileLR(benchmark::State &state) { + af::setBackend(BE); + af::setDevice(D); + + auto n = state.range(0); + auto m = state.range(1); + + auto tss = af::randu(n, f64); + + af::array profileLeft; + af::array profileRight; + af::array indexLeft; + af::array indexRight; + + af::sync(); + while (state.KeepRunning()) { + khiva::matrix::matrixProfileLR(tss, m, profileLeft, indexLeft, profileRight, indexRight); + profileLeft.eval(); + profileRight.eval(); + indexLeft.eval(); + indexRight.eval(); + af::sync(); + } + + addMemoryCounters(state); +} + +void cudaBenchmarks() { + // Empty cuda benchmarks because we want to benchmark only on cpu +} + +void openclBenchmarks() { + // Empty opencl benchmarks because we want to benchmark only on cpu +} + +void cpuBenchmarks() { + BENCHMARK_TEMPLATE(MatrixProfile, af::Backend::AF_BACKEND_CPU, CPU_BENCHMARKING_DEVICE) + ->RangeMultiplier(2) + ->Ranges({{16 << 10, 128 << 10}, {16, 512}}) + ->Unit(benchmark::TimeUnit::kMicrosecond); + + BENCHMARK_TEMPLATE(MatrixProfile2, af::Backend::AF_BACKEND_CPU, CPU_BENCHMARKING_DEVICE) + ->RangeMultiplier(2) + ->Ranges({{16 << 10, 128 << 10}, {16, 512}}) + ->Unit(benchmark::TimeUnit::kMicrosecond); + + BENCHMARK_TEMPLATE(MatrixProfileLR, af::Backend::AF_BACKEND_CPU, CPU_BENCHMARKING_DEVICE) + ->RangeMultiplier(2) + ->Ranges({{16 << 10, 128 << 10}, {16, 512}}) + ->Unit(benchmark::TimeUnit::kMicrosecond); +} + +KHIVA_BENCHMARK_MAIN(cudaBenchmarks, openclBenchmarks, cpuBenchmarks) From 9ad087b5929af51fab6c75625833dd7ef2fce50c Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaenko Date: Mon, 24 Feb 2020 18:50:06 +0100 Subject: [PATCH 2/5] bench report for the new version of SCAMP --- benchReports/bench-output_new.csv | 73 +++++++++++++++++++++++++++++++ src/scamp/SCAMP | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 benchReports/bench-output_new.csv diff --git a/benchReports/bench-output_new.csv b/benchReports/bench-output_new.csv new file mode 100644 index 0000000..7f9d546 --- /dev/null +++ b/benchReports/bench-output_new.csv @@ -0,0 +1,73 @@ +name,iterations,real_time,cpu_time,time_unit,bytes_per_second,items_per_second,label,error_occurred,error_message,"Buffers","LockedBuffers","LockedMemory","Memory" +"MatrixProfile/16384/16",100,289031,2343.75,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/16",10,1.60581e+06,9375,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/16",1,6.72973e+06,15625,us,,,,,,6,3,1.31072e+06,2.22822e+06 +"MatrixProfile/131072/16",1,2.7479e+07,31250,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/32",10,423515,1562.5,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/32",10,1.71687e+06,12500,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/32",1,7.03525e+06,15625,us,,,,,,6,3,1.31072e+06,2.22822e+06 +"MatrixProfile/131072/32",1,2.81778e+07,62500,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/64",10,432466,4687.5,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/64",10,1.74154e+06,10937.5,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/64",1,6.87724e+06,15625,us,,,,,,6,3,1.31072e+06,2.22822e+06 +"MatrixProfile/131072/64",1,2.73957e+07,31250,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/128",10,410739,6250,us,,,,,,5,3,327680,524288 +"MatrixProfile/32768/128",10,1.65506e+06,14062.5,us,,,,,,5,3,655360,1.04858e+06 +"MatrixProfile/65536/128",1,6.73038e+06,15625,us,,,,,,6,3,1.31072e+06,2.22822e+06 +"MatrixProfile/131072/128",1,2.67347e+07,31250,us,,,,,,6,3,2.62144e+06,4.45645e+06 +"MatrixProfile/16384/256",10,400370,3125,us,,,,,,5,3,326656,522240 +"MatrixProfile/32768/256",10,1.60667e+06,10937.5,us,,,,,,5,3,654336,1.04653e+06 +"MatrixProfile/65536/256",1,6.6425e+06,0,us,,,,,,7,3,1.3097e+06,2.4873e+06 +"MatrixProfile/131072/256",1,2.62655e+07,46875,us,,,,,,7,3,2.62042e+06,4.97766e+06 +"MatrixProfile/16384/512",10,398480,1562.5,us,,,,,,5,3,323584,516096 +"MatrixProfile/32768/512",10,1.59044e+06,10937.5,us,,,,,,5,3,651264,1.04038e+06 +"MatrixProfile/65536/512",1,6.34789e+06,15625,us,,,,,,8,3,1.30662e+06,2.74022e+06 +"MatrixProfile/131072/512",1,2.5658e+07,31250,us,,,,,,8,3,2.61734e+06,5.49274e+06 +"MatrixProfile2/16384/16",10,1.05094e+06,4687.5,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/16",1,3.47745e+06,15625,us,,,,,,8,4,917504,1.50733e+06 +"MatrixProfile2/65536/16",1,1.38954e+07,15625,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/16",1,5.52894e+07,46875,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/32",10,814045,1562.5,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/32",1,3.23696e+06,0,us,,,,,,8,4,917504,1.50733e+06 +"MatrixProfile2/65536/32",1,1.3202e+07,31250,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/32",1,5.44673e+07,46875,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/64",10,797690,1562.5,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/64",1,3.21798e+06,0,us,,,,,,8,4,917504,1.50733e+06 +"MatrixProfile2/65536/64",1,1.35444e+07,46875,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/64",1,5.2188e+07,31250,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/128",10,791992,3125,us,,,,,,6,4,458752,655360 +"MatrixProfile2/32768/128",1,3.1121e+06,15625,us,,,,,,8,4,917504,1.50733e+06 +"MatrixProfile2/65536/128",1,1.29054e+07,31250,us,,,,,,8,4,1.83501e+06,3.01466e+06 +"MatrixProfile2/131072/128",1,5.1558e+07,46875,us,,,,,,8,4,3.67002e+06,6.02931e+06 +"MatrixProfile2/16384/256",10,777652,0,us,,,,,,6,4,457728,653312 +"MatrixProfile2/32768/256",1,3.06964e+06,0,us,,,,,,8,4,916480,1.50426e+06 +"MatrixProfile2/65536/256",1,1.26942e+07,15625,us,,,,,,8,4,1.83398e+06,3.01158e+06 +"MatrixProfile2/131072/256",1,5.07126e+07,46875,us,,,,,,8,4,3.66899e+06,6.02624e+06 +"MatrixProfile2/16384/512",10,788919,1562.5,us,,,,,,6,4,454656,647168 +"MatrixProfile2/32768/512",1,3.06522e+06,0,us,,,,,,10,4,913408,1.75718e+06 +"MatrixProfile2/65536/512",1,1.24514e+07,15625,us,,,,,,10,4,1.83091e+06,3.52666e+06 +"MatrixProfile2/131072/512",1,4.90612e+07,31250,us,,,,,,10,4,3.66592e+06,7.0656e+06 +"MatrixProfileLR/16384/16",10,431697,0,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/16",10,1.97178e+06,1562.5,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/16",1,6.97045e+06,15625,us,,,,,,11,5,2.09715e+06,3.47341e+06 +"MatrixProfileLR/131072/16",1,2.81528e+07,46875,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/32",10,418560,1562.5,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/32",10,1.68618e+06,4687.5,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/32",1,7.00486e+06,15625,us,,,,,,11,5,2.09715e+06,3.47341e+06 +"MatrixProfileLR/131072/32",1,2.72861e+07,46875,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/64",10,408388,4687.5,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/64",10,1.67229e+06,7812.5,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/64",1,6.75037e+06,31250,us,,,,,,11,5,2.09715e+06,3.47341e+06 +"MatrixProfileLR/131072/64",1,2.69318e+07,46875,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/128",10,406505,0,us,,,,,,9,5,524288,802816 +"MatrixProfileLR/32768/128",10,1.63576e+06,9375,us,,,,,,9,5,1.04858e+06,1.60563e+06 +"MatrixProfileLR/65536/128",1,6.74544e+06,46875,us,,,,,,11,5,2.09715e+06,3.47341e+06 +"MatrixProfileLR/131072/128",1,2.65674e+07,46875,us,,,,,,11,5,4.1943e+06,6.94682e+06 +"MatrixProfileLR/16384/256",10,402117,4687.5,us,,,,,,9,5,522240,799744 +"MatrixProfileLR/32768/256",10,1.64151e+06,6250,us,,,,,,9,5,1.04653e+06,1.60256e+06 +"MatrixProfileLR/65536/256",1,6.60595e+06,15625,us,,,,,,13,5,2.0951e+06,3.99258e+06 +"MatrixProfileLR/131072/256",1,2.68686e+07,46875,us,,,,,,13,5,4.19226e+06,7.99027e+06 +"MatrixProfileLR/16384/512",10,404139,1562.5,us,,,,,,9,5,516096,789504 +"MatrixProfileLR/32768/512",10,1.62436e+06,3125,us,,,,,,9,5,1.04038e+06,1.59232e+06 +"MatrixProfileLR/65536/512",1,6.55693e+06,31250,us,,,,,,14,5,2.08896e+06,4.23834e+06 +"MatrixProfileLR/131072/512",1,2.81879e+07,46875,us,,,,,,14,5,4.18611e+06,8.49818e+06 diff --git a/src/scamp/SCAMP b/src/scamp/SCAMP index 34a4981..086a5ce 160000 --- a/src/scamp/SCAMP +++ b/src/scamp/SCAMP @@ -1 +1 @@ -Subproject commit 34a498197d1fc36d74408936866ffb634d43be65 +Subproject commit 086a5cea18846e56d16df5df2eaabaff7edfa5e7 From b2ab7160ca13fd5465a9cbdef02b4594a0726f7a Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaenko Date: Thu, 27 Feb 2020 21:24:49 +0100 Subject: [PATCH 3/5] Add threshold parameter for testing SCAMP (Matrix Profile) --- CMakeSettings.json | 24 ++++--- include/khiva/internal/matrixInternal.h | 4 ++ include/khiva/matrix.h | 11 ++++ src/khiva/matrix.cpp | 8 +++ src/khiva/matrixInternal.cpp | 88 ++++++++++++++++++++++--- 5 files changed, 113 insertions(+), 22 deletions(-) diff --git a/CMakeSettings.json b/CMakeSettings.json index 7c3438b..00d9168 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -1,9 +1,5 @@ { - "environments": [ - { - "VCToolsVersion": "14.24" - } - ], + "environments": [ { "VCToolsVersion": "14.24" } ], "configurations": [ { "name": "x64-Debug", @@ -17,16 +13,17 @@ "ctestCommandArgs": "", "variables": [ { - "name": "CMAKE_TOOLCHAIN_FILE", - "value": "${env.VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", - "type": "STRING" + "name": "KHIVA_BUILD_DOCUMENTATION", + "value": "OFF", + "type": "BOOL" }, { "name": "KHIVA_USE_CONAN", "value": "OFF", "type": "STRING" } - ] + ], + "cmakeToolchain": "C:/Users/Dmitry Nikolaenko/repositories/vcpkg/scripts/buildsystems/vcpkg.cmake" }, { "name": "x64-Release", @@ -40,16 +37,17 @@ "inheritEnvironments": [ "msvc_x64_x64" ], "variables": [ { - "name": "CMAKE_TOOLCHAIN_FILE", - "value": "${env.VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", - "type": "STRING" + "name": "KHIVA_BUILD_DOCUMENTATION", + "value": "OFF", + "type": "BOOL" }, { "name": "KHIVA_USE_CONAN", "value": "OFF", "type": "STRING" } - ] + ], + "cmakeToolchain": "C:/Users/Dmitry Nikolaenko/repositories/vcpkg/scripts/buildsystems/vcpkg.cmake" } ] } \ No newline at end of file diff --git a/include/khiva/internal/matrixInternal.h b/include/khiva/internal/matrixInternal.h index 61bf00d..b192c1b 100644 --- a/include/khiva/internal/matrixInternal.h +++ b/include/khiva/internal/matrixInternal.h @@ -186,6 +186,10 @@ KHIVAAPI LeftRightProfilePair scampLR(std::vector &&ta, long m); KHIVAAPI void scampLR(af::array tss, long m, af::array &profileLeft, af::array &indexLeft, af::array &profileRight, af::array &indexRight); +KHIVAAPI void scampThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index); + +KHIVAAPI void scampThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, af::array &index); + } // namespace internal } // namespace matrix } // namespace khiva diff --git a/include/khiva/matrix.h b/include/khiva/matrix.h index 32482aa..e72bce7 100644 --- a/include/khiva/matrix.h +++ b/include/khiva/matrix.h @@ -199,6 +199,17 @@ KHIVAAPI void matrixProfileLR(af::array tss, long m, af::array &profileLeft, af: */ KHIVAAPI void getChains(af::array tss, long m, af::array &chains); +/** + * @brief TODO: dmitry + */ +KHIVAAPI void matrixProfileThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index); + +/** + * @brief TODO: dmitry + */ +KHIVAAPI void matrixProfileThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, + af::array &index); + } // namespace matrix } // namespace khiva diff --git a/src/khiva/matrix.cpp b/src/khiva/matrix.cpp index 0d9c94d..c243b77 100644 --- a/src/khiva/matrix.cpp +++ b/src/khiva/matrix.cpp @@ -114,5 +114,13 @@ void matrixProfileLR(af::array tss, long m, af::array &profileLeft, af::array &i void getChains(af::array tss, long m, af::array &chains) { internal::getChains(tss, m, chains); } +void matrixProfileThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index) { + internal::scampThresh(tss, m, threshold, profile, index); +} + +void matrixProfileThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, af::array &index) { + internal::scampThresh(ta, tb, m, threshold, profile, index); +} + } // namespace matrix } // namespace khiva diff --git a/src/khiva/matrixInternal.cpp b/src/khiva/matrixInternal.cpp index 0d00b3c..925dfd4 100644 --- a/src/khiva/matrixInternal.cpp +++ b/src/khiva/matrixInternal.cpp @@ -72,15 +72,15 @@ void InitProfileMemory(SCAMP::SCAMPArgs &args) { } break; } - // case SCAMP::PROFILE_TYPE_SUM_THRESH: { - // args.profile_a.data.emplace_back(); - // args.profile_a.data[0].double_value.resize(args.timeseries_a.size() - args.window + 1, 0); - // if (args.has_b) { - // args.profile_b.data.emplace_back(); - // args.profile_b.data[0].double_value.resize(args.timeseries_b.size() - args.window + 1, 0); - // } - // break; - //} + case SCAMP::PROFILE_TYPE_SUM_THRESH: { + args.profile_a.data.emplace_back(); + args.profile_a.data[0].double_value.resize(args.timeseries_a.size() - args.window + 1, 0); + if (args.has_b) { + args.profile_b.data.emplace_back(); + args.profile_b.data[0].double_value.resize(args.timeseries_b.size() - args.window + 1, 0); + } + break; + } default: break; } @@ -177,6 +177,37 @@ MatrixProfilePair scamp(std::vector &&ta, std::vector &&tb, long return getProfileOutput(args.profile_a, args.window); } +MatrixProfilePair scampThresh(std::vector &&tss, long m, double threshold) { + auto args = getDefaultArgs(); + args.window = m; + args.has_b = false; + args.timeseries_a = std::move(tss); + + args.distance_threshold = threshold; + args.profile_a.type = SCAMP::PROFILE_TYPE_SUM_THRESH; + args.profile_b.type = SCAMP::PROFILE_TYPE_SUM_THRESH; + args.precision_type = SCAMP::PRECISION_DOUBLE; + args.profile_type = SCAMP::PROFILE_TYPE_SUM_THRESH; + runScamp(args); + return getProfileOutput(args.profile_a, args.window); +} + +MatrixProfilePair scampThresh(std::vector &&ta, std::vector &&tb, long m, double threshold) { + auto args = getDefaultArgs(); + args.window = m; + args.has_b = true; + args.timeseries_a = std::move(ta); + args.timeseries_b = std::move(tb); + + args.distance_threshold = threshold; + args.profile_a.type = SCAMP::PROFILE_TYPE_SUM_THRESH; + args.profile_b.type = SCAMP::PROFILE_TYPE_SUM_THRESH; + args.precision_type = SCAMP::PRECISION_DOUBLE; + args.profile_type = SCAMP::PROFILE_TYPE_SUM_THRESH; + runScamp(args); + return getProfileOutput(args.profile_a, args.window); +} + void sortChains(ChainVector &chains) { chains.erase(std::remove_if(chains.begin(), chains.end(), [](const Chain &currChain) { return currChain.empty(); }), chains.end()); @@ -461,6 +492,45 @@ void scamp(af::array ta, af::array tb, long m, af::array &profile, af::array &in } } +void scampThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index) { + if (tss.dims(2) > 1 || tss.dims(3) > 1) { + throw std::invalid_argument("Dimension 2 o dimension 3 is bigger than 1"); + } + + profile = af::array(tss.dims(0) - m + 1, tss.dims(1), f64); + index = af::array(tss.dims(0) - m + 1, tss.dims(1), u32); + + tss = tss.as(f64); + for (dim_t tssIdx = 0; tssIdx < tss.dims(1); ++tssIdx) { + auto vect = khiva::vectorutil::get(tss(af::span, tssIdx)); + auto res = ::scampThresh(std::move(vect), m, threshold); + profile(af::span, tssIdx) = khiva::vectorutil::createArray(res.first); + index(af::span, tssIdx) = khiva::vectorutil::createArray(res.second); + } +} + +void scampThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, af::array &index) { + if (ta.dims(2) > 1 || ta.dims(3) > 1 || tb.dims(2) > 1 || tb.dims(3) > 1) { + throw std::invalid_argument("Dimension 2 o dimension 3 is bigger than 1"); + } + + profile = af::array(tb.dims(0) - m + 1, ta.dims(1), tb.dims(1), f64); + index = af::array(tb.dims(0) - m + 1, ta.dims(1), tb.dims(1), u32); + + ta = ta.as(f64); + tb = tb.as(f64); + + for (dim_t tbIdx = 0; tbIdx < tb.dims(1); ++tbIdx) { + for (dim_t taIdx = 0; taIdx < ta.dims(1); ++taIdx) { + auto vectA = khiva::vectorutil::get(ta(af::span, taIdx)); + auto vectB = khiva::vectorutil::get(tb(af::span, tbIdx)); + auto res = ::scampThresh(std::move(vectB), std::move(vectA), m, threshold); + profile(af::span, taIdx, tbIdx) = khiva::vectorutil::createArray(res.first); + index(af::span, taIdx, tbIdx) = khiva::vectorutil::createArray(res.second); + } + } +} + LeftRightProfilePair scampLR(std::vector &&ta, long m) { auto args = getDefaultArgs(); args.window = m; From bf76f5570a1ea368247c3fb068794e1df6033269 Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaenko Date: Mon, 2 Mar 2020 17:17:59 +0100 Subject: [PATCH 4/5] Bump up the revision of SCAMP submodule --- src/scamp/SCAMP | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scamp/SCAMP b/src/scamp/SCAMP index 086a5ce..3ab5526 160000 --- a/src/scamp/SCAMP +++ b/src/scamp/SCAMP @@ -1 +1 @@ -Subproject commit 086a5cea18846e56d16df5df2eaabaff7edfa5e7 +Subproject commit 3ab5526509e9d2543fa9af117945c3397e371d37 From 06759fc027b632b1a7e9cd837b7b986f14f87776 Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaenko Date: Mon, 2 Mar 2020 17:23:15 +0100 Subject: [PATCH 5/5] Add new Matrix Profile functions to compute sum of correlations above a threshold and add/correct some descriptions --- benchmarks/scampBench.cpp | 57 +++++++++++++++++++++++++ include/khiva/internal/matrixInternal.h | 5 ++- include/khiva/matrix.h | 45 +++++++++++++------ src/khiva/matrix.cpp | 8 ++-- src/khiva/matrixInternal.cpp | 38 +++++++++++------ test/matrixTest.cpp | 57 +++++++++++++++++++++++++ 6 files changed, 177 insertions(+), 33 deletions(-) diff --git a/benchmarks/scampBench.cpp b/benchmarks/scampBench.cpp index 7a1adc2..9d3c5f2 100644 --- a/benchmarks/scampBench.cpp +++ b/benchmarks/scampBench.cpp @@ -62,6 +62,53 @@ void MatrixProfile2(benchmark::State &state) { addMemoryCounters(state); } +template +void MatrixProfileThresh(benchmark::State &state) { + af::setBackend(BE); + af::setDevice(D); + + auto n = state.range(0); + auto m = state.range(1); + double threshold = 0.5; + + auto tss = af::randu(n, f64); + + af::array sumCorrelation; + + af::sync(); + while (state.KeepRunning()) { + khiva::matrix::matrixProfileThresh(tss, m, threshold, sumCorrelation); + sumCorrelation.eval(); + af::sync(); + } + + addMemoryCounters(state); +} + +template +void MatrixProfileThresh2(benchmark::State &state) { + af::setBackend(BE); + af::setDevice(D); + + auto n = state.range(0); + auto m = state.range(1); + double threshold = 0.5; + + auto ta = af::randu(n, f64); + auto tb = af::randu(n, f64); + + af::array sumCorrelation; + + af::sync(); + while (state.KeepRunning()) { + khiva::matrix::matrixProfileThresh(ta, tb, m, threshold, sumCorrelation); + sumCorrelation.eval(); + af::sync(); + } + + addMemoryCounters(state); +} + template void MatrixProfileLR(benchmark::State &state) { af::setBackend(BE); @@ -113,6 +160,16 @@ void cpuBenchmarks() { ->RangeMultiplier(2) ->Ranges({{16 << 10, 128 << 10}, {16, 512}}) ->Unit(benchmark::TimeUnit::kMicrosecond); + + BENCHMARK_TEMPLATE(MatrixProfileThresh, af::Backend::AF_BACKEND_CPU, CPU_BENCHMARKING_DEVICE) + ->RangeMultiplier(2) + ->Ranges({{16 << 10, 128 << 10}, {16, 512}}) + ->Unit(benchmark::TimeUnit::kMicrosecond); + + BENCHMARK_TEMPLATE(MatrixProfileThresh2, af::Backend::AF_BACKEND_CPU, CPU_BENCHMARKING_DEVICE) + ->RangeMultiplier(2) + ->Ranges({{16 << 10, 128 << 10}, {16, 512}}) + ->Unit(benchmark::TimeUnit::kMicrosecond); } KHIVA_BENCHMARK_MAIN(cudaBenchmarks, openclBenchmarks, cpuBenchmarks) diff --git a/include/khiva/internal/matrixInternal.h b/include/khiva/internal/matrixInternal.h index b192c1b..4333cf2 100644 --- a/include/khiva/internal/matrixInternal.h +++ b/include/khiva/internal/matrixInternal.h @@ -28,6 +28,7 @@ using MatrixProfilePair = std::pair; using LeftRightProfilePair = std::pair; using Chain = std::vector; using ChainVector = std::vector; +using SumCorrelationsVector = std::vector; /** * @brief Calculates the sliding dot product of the time series 'q' against t. @@ -186,9 +187,9 @@ KHIVAAPI LeftRightProfilePair scampLR(std::vector &&ta, long m); KHIVAAPI void scampLR(af::array tss, long m, af::array &profileLeft, af::array &indexLeft, af::array &profileRight, af::array &indexRight); -KHIVAAPI void scampThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index); +KHIVAAPI void scampThresh(af::array tss, long m, double threshold, af::array &sumCorrelation); -KHIVAAPI void scampThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, af::array &index); +KHIVAAPI void scampThresh(af::array ta, af::array tb, long m, double threshold, af::array &sumCorrelation); } // namespace internal } // namespace matrix diff --git a/include/khiva/matrix.h b/include/khiva/matrix.h index e72bce7..652824d 100644 --- a/include/khiva/matrix.h +++ b/include/khiva/matrix.h @@ -129,18 +129,17 @@ KHIVAAPI void stomp(af::array ta, af::array tb, long m, af::array &profile, af:: KHIVAAPI void stomp(af::array t, long m, af::array &profile, af::array &index); /** - * @brief Calculates the matrix profile between 't' and itself using a subsequence length of 'm'. + * @brief Calculates the matrix profile between 'tss' and itself using a subsequence length of 'm'. * This method filters the trivial matches. * * [1] Yan Zhu, Zachary Zimmerman, Nader Shakibay Senobari, Chin-Chia Michael Yeh, Gareth Funning, Abdullah Mueen, * Philip Brisk and Eamonn Keogh (2016). Matrix Profile II: Exploiting a Novel Algorithm and GPUs to break the one * Hundred Million Barrier for Time Series Motifs and Joins. IEEE ICDM 2016. * - * @param ta Query time series. - * @param tb Reference time series. + * @param tss Query and reference time series. * @param m Subsequence length. - * @param profile The matrix profile, which reflects the distance to the closer element of the subsequence from 'ta' - * in 'tb'. + * @param profile The matrix profile, which reflects the distance to the closest element of the subsequence from 'tss' + * in a different location of itself. * @param index The matrix profile index, which points to where the aforementioned minimum is located. */ KHIVAAPI void matrixProfile(af::array tss, long m, af::array &profile, af::array &index); @@ -152,10 +151,11 @@ KHIVAAPI void matrixProfile(af::array tss, long m, af::array &profile, af::array * Philip Brisk and Eamonn Keogh (2016). Matrix Profile II: Exploiting a Novel Algorithm and GPUs to break the one * Hundred Million Barrier for Time Series Motifs and Joins. IEEE ICDM 2016. * - * @param t Query and reference time series. + * @param ta Query time series. + * @param tb Reference time series. * @param m Subsequence length. - * @param profile The matrix profile, which reflects the distance to the closer element of the subsequence from 't' in a - * different location of itself. + * @param profile The matrix profile, which reflects the distance to the closest element of the subsequence from 'ta' + * in 'tb'. * @param index The matrix profile index, which points to where the aforementioned minimum is located. */ KHIVAAPI void matrixProfile(af::array ta, af::array tb, long m, af::array &profile, af::array &index); @@ -200,15 +200,34 @@ KHIVAAPI void matrixProfileLR(af::array tss, long m, af::array &profileLeft, af: KHIVAAPI void getChains(af::array tss, long m, af::array &chains); /** - * @brief TODO: dmitry + * @brief Calculates the sum of correlations above a threshold between 'tss' and itself using a subsequence + * length of 'm' at each location in 'tss'. + * + * [1] Yan Zhu, Zachary Zimmerman, Nader Shakibay Senobari, Chin-Chia Michael Yeh, Gareth Funning, Abdullah Mueen, + * Philip Brisk and Eamonn Keogh (2016). Matrix Profile II: Exploiting a Novel Algorithm and GPUs to break the one + * Hundred Million Barrier for Time Series Motifs and Joins. IEEE ICDM 2016. + * + * @param tss Query and reference time series. + * @param m Subsequence length. + * @param sumCorrelation The sum of correlations above a threshold between 'tss' and itself using a subsequence length + * of 'm' at each location in 'tss'. */ -KHIVAAPI void matrixProfileThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index); +KHIVAAPI void matrixProfileThresh(af::array tss, long m, double threshold, af::array &sumCorrelation); /** - * @brief TODO: dmitry + * @brief Calculates the sum of correlations above a threshold between 'ta' and 'tb' using a subsequence length of 'm'. + * + * [1] Yan Zhu, Zachary Zimmerman, Nader Shakibay Senobari, Chin-Chia Michael Yeh, Gareth Funning, Abdullah Mueen, + * Philip Brisk and Eamonn Keogh (2016). Matrix Profile II: Exploiting a Novel Algorithm and GPUs to break the one + * Hundred Million Barrier for Time Series Motifs and Joins. IEEE ICDM 2016. + * + * @param ta Query time series. + * @param tb Reference time series. + * @param m Subsequence length. + * @param sumCorrelation The sum of correlations above a threshold between 'ta' and 'tb' using a subsequence length of + * 'm' at each location in 'ta'. */ -KHIVAAPI void matrixProfileThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, - af::array &index); +KHIVAAPI void matrixProfileThresh(af::array ta, af::array tb, long m, double threshold, af::array &sumCorrelation); } // namespace matrix } // namespace khiva diff --git a/src/khiva/matrix.cpp b/src/khiva/matrix.cpp index c243b77..62d8170 100644 --- a/src/khiva/matrix.cpp +++ b/src/khiva/matrix.cpp @@ -114,12 +114,12 @@ void matrixProfileLR(af::array tss, long m, af::array &profileLeft, af::array &i void getChains(af::array tss, long m, af::array &chains) { internal::getChains(tss, m, chains); } -void matrixProfileThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index) { - internal::scampThresh(tss, m, threshold, profile, index); +void matrixProfileThresh(af::array tss, long m, double threshold, af::array &sumCorrelation) { + internal::scampThresh(tss, m, threshold, sumCorrelation); } -void matrixProfileThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, af::array &index) { - internal::scampThresh(ta, tb, m, threshold, profile, index); +void matrixProfileThresh(af::array ta, af::array tb, long m, double threshold, af::array &sumCorrelation) { + internal::scampThresh(ta, tb, m, threshold, sumCorrelation); } } // namespace matrix diff --git a/src/khiva/matrixInternal.cpp b/src/khiva/matrixInternal.cpp index 925dfd4..ccceb2b 100644 --- a/src/khiva/matrixInternal.cpp +++ b/src/khiva/matrixInternal.cpp @@ -129,6 +129,20 @@ MatrixProfilePair getProfileOutput(const SCAMP::Profile &p, uint64_t window) { return std::make_pair(std::move(distances), std::move(indexes)); } +SumCorrelationsVector getThreshProfileOutput(const SCAMP::Profile &p, uint64_t window) { + SumCorrelationsVector sumCorrelations; + + const auto &arr = p.data[0].double_value; + sumCorrelations.resize(arr.size()); + + for (int i = 0; i < arr.size(); ++i) { + sumCorrelations[i] = arr[i]; + // distances[i] = static_cast(convertToEuclidean(e.floats[0], window)); + // indexes[i] = (e.floats[0] < -1) ? -1 : e.ints[1]; + } + return sumCorrelations; +} + void runScamp(SCAMP::SCAMPArgs &args) { std::vector devices; #ifdef _HAS_CUDA_ @@ -177,7 +191,7 @@ MatrixProfilePair scamp(std::vector &&ta, std::vector &&tb, long return getProfileOutput(args.profile_a, args.window); } -MatrixProfilePair scampThresh(std::vector &&tss, long m, double threshold) { +SumCorrelationsVector scampThresh(std::vector &&tss, long m, double threshold) { auto args = getDefaultArgs(); args.window = m; args.has_b = false; @@ -189,10 +203,10 @@ MatrixProfilePair scampThresh(std::vector &&tss, long m, double threshol args.precision_type = SCAMP::PRECISION_DOUBLE; args.profile_type = SCAMP::PROFILE_TYPE_SUM_THRESH; runScamp(args); - return getProfileOutput(args.profile_a, args.window); + return getThreshProfileOutput(args.profile_a, args.window); } -MatrixProfilePair scampThresh(std::vector &&ta, std::vector &&tb, long m, double threshold) { +SumCorrelationsVector scampThresh(std::vector &&ta, std::vector &&tb, long m, double threshold) { auto args = getDefaultArgs(); args.window = m; args.has_b = true; @@ -205,7 +219,7 @@ MatrixProfilePair scampThresh(std::vector &&ta, std::vector &&tb args.precision_type = SCAMP::PRECISION_DOUBLE; args.profile_type = SCAMP::PROFILE_TYPE_SUM_THRESH; runScamp(args); - return getProfileOutput(args.profile_a, args.window); + return getThreshProfileOutput(args.profile_a, args.window); } void sortChains(ChainVector &chains) { @@ -492,30 +506,27 @@ void scamp(af::array ta, af::array tb, long m, af::array &profile, af::array &in } } -void scampThresh(af::array tss, long m, double threshold, af::array &profile, af::array &index) { +void scampThresh(af::array tss, long m, double threshold, af::array &sumCorrelation) { if (tss.dims(2) > 1 || tss.dims(3) > 1) { throw std::invalid_argument("Dimension 2 o dimension 3 is bigger than 1"); } - profile = af::array(tss.dims(0) - m + 1, tss.dims(1), f64); - index = af::array(tss.dims(0) - m + 1, tss.dims(1), u32); + sumCorrelation = af::array(tss.dims(0) - m + 1, tss.dims(1), f64); tss = tss.as(f64); for (dim_t tssIdx = 0; tssIdx < tss.dims(1); ++tssIdx) { auto vect = khiva::vectorutil::get(tss(af::span, tssIdx)); auto res = ::scampThresh(std::move(vect), m, threshold); - profile(af::span, tssIdx) = khiva::vectorutil::createArray(res.first); - index(af::span, tssIdx) = khiva::vectorutil::createArray(res.second); + sumCorrelation(af::span, tssIdx) = khiva::vectorutil::createArray(res); } } -void scampThresh(af::array ta, af::array tb, long m, double threshold, af::array &profile, af::array &index) { +void scampThresh(af::array ta, af::array tb, long m, double threshold, af::array &sumCorrelation) { if (ta.dims(2) > 1 || ta.dims(3) > 1 || tb.dims(2) > 1 || tb.dims(3) > 1) { throw std::invalid_argument("Dimension 2 o dimension 3 is bigger than 1"); } - profile = af::array(tb.dims(0) - m + 1, ta.dims(1), tb.dims(1), f64); - index = af::array(tb.dims(0) - m + 1, ta.dims(1), tb.dims(1), u32); + sumCorrelation = af::array(tb.dims(0) - m + 1, ta.dims(1), tb.dims(1), f64); ta = ta.as(f64); tb = tb.as(f64); @@ -525,8 +536,7 @@ void scampThresh(af::array ta, af::array tb, long m, double threshold, af::array auto vectA = khiva::vectorutil::get(ta(af::span, taIdx)); auto vectB = khiva::vectorutil::get(tb(af::span, tbIdx)); auto res = ::scampThresh(std::move(vectB), std::move(vectA), m, threshold); - profile(af::span, taIdx, tbIdx) = khiva::vectorutil::createArray(res.first); - index(af::span, taIdx, tbIdx) = khiva::vectorutil::createArray(res.second); + sumCorrelation(af::span, taIdx, tbIdx) = khiva::vectorutil::createArray(res); } } } diff --git a/test/matrixTest.cpp b/test/matrixTest.cpp index ca32401..9d60f0d 100644 --- a/test/matrixTest.cpp +++ b/test/matrixTest.cpp @@ -1258,6 +1258,61 @@ void findBestDiscordsException() { } } +void matrixSumCorrelation() { + auto ta = khiva::vectorutil::createArray( + {-0.9247, 0.1808, 2.5441, 0.3516, -0.3452, 0.2191, -0.7687, 0.2413, -1.1948, 0.8927, -0.5378, 0.2270, + 0.9354, -0.7613, 0.5787, -0.6174, 0.5889, 0.7897, -0.0645, 0.9520, -1.1411, 0.8281, -0.7363, -0.7446}, + 8, 3); + + auto tb = khiva::vectorutil::createArray({0.2512, 0.6436, -2.3651, -0.7734, -0.0511, 1.6693, 1.9453, -1.9047, + 0.8149, -0.1831, -0.1542, -1.3490, 1.2285, -1.0472, 0.3911, -0.0637}, + 8, 2); + long m = 3; + double threshold = 0.5; + + af::array sumCorrelation; + + khiva::matrix::matrixProfileThresh(ta, tb, m, threshold, sumCorrelation); + + ASSERT_EQ(sumCorrelation.dims(0), 6); + ASSERT_EQ(sumCorrelation.dims(1), 3); + ASSERT_EQ(sumCorrelation.dims(2), 2); + ASSERT_EQ(sumCorrelation.dims(3), 1); + + auto sumCorrelationVect = khiva::vectorutil::get(sumCorrelation); + ASSERT_NEAR(1.9584, sumCorrelationVect[7], 1e-3); + ASSERT_NEAR(1.8904, sumCorrelationVect[17], 1e-3); + ASSERT_NEAR(2.1383, sumCorrelationVect[18], 1e-3); + ASSERT_NEAR(2.7268, sumCorrelationVect[27], 1e-3); + ASSERT_NEAR(0.8593, sumCorrelationVect[35], 1e-3); +} + +void matrixSumCorrelationSelfJoin() { + auto ta = khiva::vectorutil::createArray( + {0.6010, 0.0278, 0.9806, 0.2126, 0.0655, 0.5497, 0.2864, 0.3410, 0.7509, 0.4105, 0.1583, 0.3712, + 0.3543, 0.6450, 0.9675, 0.3636, 0.4165, 0.5814, 0.8962, 0.3712, 0.6755, 0.6105, 0.5232, 0.5567, + 0.7896, 0.8966, 0.0536, 0.5775, 0.2908, 0.9941, 0.5143, 0.3670, 0.3336, 0.0363, 0.5349, 0.0123, + 0.3988, 0.9787, 0.2308, 0.6244, 0.7917, 0.1654, 0.8657, 0.3766, 0.7331, 0.2522, 0.9644, 0.4711}, + 16, 3); + + long m = 6; + double threshold = 0.5; + + af::array sumCorrelation; + + khiva::matrix::matrixProfileThresh(ta, m, threshold, sumCorrelation); + + ASSERT_EQ(sumCorrelation.dims(0), 11); + ASSERT_EQ(sumCorrelation.dims(1), 3); + ASSERT_EQ(sumCorrelation.dims(2), 1); + ASSERT_EQ(sumCorrelation.dims(3), 1); + + auto sumCorrelationVect = khiva::vectorutil::get(sumCorrelation); + ASSERT_NEAR(0.8752, sumCorrelationVect[7], 1e-3); + ASSERT_NEAR(0.0, sumCorrelationVect[21], 1e-3); + ASSERT_NEAR(1.3062, sumCorrelationVect[25], 1e-3); +} + KHIVA_TEST(MatrixTests, SlidingDotProduct, slidingDotProduct) KHIVA_TEST(MatrixTests, MeanStdev, meanStdev) KHIVA_TEST(MatrixTests, MeanStdevMEqualsLength, meanStdevMEqualsLength) @@ -1296,3 +1351,5 @@ KHIVA_TEST(MatrixTests, FindBestDiscordsMirror, findBestDiscordsMirror) KHIVA_TEST(MatrixTests, FindBestDiscordsConsecutive, findBestDiscordsConsecutive) KHIVA_TEST(MatrixTests, FindBestDiscordsMirrorException, findBestDiscordsMirrorException) KHIVA_TEST(MatrixTests, FindBestDiscordsException, findBestDiscordsException) +KHIVA_TEST(MatrixTests, MatrixSumCorrelation, matrixSumCorrelation) +KHIVA_TEST(MatrixTests, MatrixSumCorrelationSelfJoin, matrixSumCorrelationSelfJoin)