Skip to content

Commit

Permalink
Merge pull request #18 from esi-mineset/unit-test-improevements-16-bb
Browse files Browse the repository at this point in the history
Add some additional unit tests (#16)
  • Loading branch information
ensozos authored Jan 20, 2019
2 parents 59bbc17 + 7570703 commit 3ce677e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class MatrixProfileAccuracyTest {

/** Set this to true if you want to automatically update the results files */
private static final boolean UPDATE_RESULTS = false;
private static final int STEPS_IN_DAY = 287;


@Test
Expand All @@ -35,15 +36,15 @@ public void testMatrixProfileSelfJoinStampWindow8() {
public void testMatrixProfileSelfJoinStamp_ArtDailyFlatMiddle() {
verifyResult("numenta_art_daily_flatmiddle",
"numenta_art_daily_flatmiddle_profile_pair_0_1.exp",
80, 0.1, false);
STEPS_IN_DAY, 0.1, false);
}

// Originally ran in 2m 40s on 4 core laptop before making it multi-threaded - only 23s when 10% of steps used
@Test
public void testMatrixProfileSelfJoinStamp_ArtDailyJumpsDown() {
verifyResult("numenta_art_daily_jumps_down",
"numenta_art_daily_jumps_down_profile_pair_0_1.exp",
80, 0.1, false);
STEPS_IN_DAY, 0.1, false);
}


Expand All @@ -60,15 +61,15 @@ public void testMatrixProfileSelfJoinStampWindow8_concurrent() {
public void testMatrixProfileSelfJoinStamp_ArtDailyFlatMiddle_concurrent() {
verifyResult("numenta_art_daily_flatmiddle",
"numenta_art_daily_flatmiddle_profile_pair_0_1.exp",
80, 0.1, true);
STEPS_IN_DAY, 0.1, true);
}

// Ran in 56s on 4 core laptop after making it multi-threaded, but took only 15 seconds using only 10%; 35s at 20%
@Test
public void testMatrixProfileSelfJoinStamp_ArtDailyJumpsDown_concurrent() {
verifyResult("numenta_art_daily_jumps_down",
"numenta_art_daily_jumps_down_profile_pair_0_1.exp",
80, 0.1, true);
STEPS_IN_DAY, 0.1, true);
}

private void verifyResult(String seriesFile, String expResultFile,
Expand All @@ -85,7 +86,7 @@ private void verifyResult(String seriesFile, String expResultFile,
concurrent ? concurrentMP.stamp(series, window, accuracy) : serialMP.stamp(series, window, accuracy);

// Uncomment this to export results to excel. Plotting in excel can be very instructive.
//CsvExport.printToCsvFile(series, expectedResultWhenSelfJoin, "acc_" + seriesFile + ".xls");
CsvExport.printToCsvFile(series, pair, "acc_" + seriesFile + ".xls");
//CsvExport.printPairToFile(pair, "acc_" + seriesFile + ".xls");

if (UPDATE_RESULTS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MatrixProfilePerformanceTest {

/** Set this to true if you want to automatically update the results files */
private static final boolean UPDATE_RESULTS = false;
private static final int STEPS_IN_DAY = 287;



Expand All @@ -31,15 +32,15 @@ public void testMatrixProfileSelfJoinStmpWindow8() {
public void testMatrixProfileSelfJoinStmp_ArtDailyFlatMiddle() {
verifyResult("numenta_art_daily_flatmiddle",
"numenta_art_daily_flatmiddle_profile_pair.exp",
80, false);
STEPS_IN_DAY, false);
}

// Ran in 2m 40s on 4 core laptop before making it multi-threaded.
@Test
public void testMatrixProfileSelfJoinStmp_ArtDailyJumpsDown() {
verifyResult("numenta_art_daily_jumps_down",
"numenta_art_daily_jumps_down_profile_pair.exp",
80, false);
STEPS_IN_DAY, false);
}

/* Commenting some tests to reduce runtime.
Expand All @@ -49,15 +50,15 @@ public void testMatrixProfileSelfJoinStmp_ArtDailyJumpsDown() {
public void testMatrixProfileSelfJoinStmp_ArtIncreaseSpikeDensity() {
verifyResult("numenta_art_increase_spike_density",
"numenta_art_increase_spike_density_profile_pair.exp",
80, false);
STEPS_IN_DAY, false);
}
// Ran in 3m 1s on 4 core laptop before making it multi-threaded.
@Test
public void testMatrixProfileSelfJoinStmp_ArtLoadBalancerSpikes() {
verifyResult("numenta_art_load_balancer_spikes",
"numenta_art_load_balancer_spikes_profile_pair.exp",
80, false);
STEPS_IN_DAY, false);
}*/


Expand All @@ -73,15 +74,15 @@ public void testMatrixProfileSelfJoinStmpWindow8_concurrent() {
public void testMatrixProfileSelfJoinStmp_ArtDailyFlatMiddle_concurrent() {
verifyResult("numenta_art_daily_flatmiddle",
"numenta_art_daily_flatmiddle_profile_pair.exp",
80, true);
STEPS_IN_DAY, true);
}

// Ran in 56s on 4 core laptop after making it multi-threaded.
@Test
public void testMatrixProfileSelfJoinStmp_ArtDailyJumpsDown_concurrent() {
verifyResult("numenta_art_daily_jumps_down",
"numenta_art_daily_jumps_down_profile_pair.exp",
80, true);
STEPS_IN_DAY, true);
}

/**
Expand Down Expand Up @@ -113,7 +114,7 @@ private void verifyResult(String seriesFile, String expResultFile, int window, b
concurrent ? concurrentMP.stmp(series, window) : serialMP.stmp(series, window);

// Uncomment this to export results to excel. Plotting in excel can be very instructive.
//CsvExport.printToCsvFile(series, expectedResultWhenSelfJoin, "perf_" + seriesFile + ".xls");
CsvExport.printToCsvFile(series, pair, "perf_" + seriesFile + ".xls");
//CsvExport.printPairToFile(pair, "perf_" + seriesFile + ".xls");

if (UPDATE_RESULTS) {
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/io/github/ensozos/core/MatrixProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MatrixProfileTest {
new double[]{0.0, 6.0, -1.0, 2.0, 3.0, 1.0, 4.0},
new int[]{1, 7}
);

private INDArray targetSeriesWithPattern = Nd4j.create(
new double[]{0.6, 0.5, 2.00, 1.0, -1.01, -0.5, 1.0, 2.3, 4.0, 5.9, 4.2, 3.1, 3.2,
3.4, 2.9, 3.5, 1.05, -1.0, -0.50, 1.01, 2.41, 3.99, 6.01, 4.7, 3.2, 2.6, 4.1, 4.3, 1.1, 1.7, 3.1, 1.9,
Expand All @@ -26,6 +27,18 @@ public class MatrixProfileTest {
new int[]{1, 69}
);

private INDArray targetSeriesWithoutPattern = Nd4j.create(
new double[]{1.2, 1.5, 1.9, 2.1, 2.0, 1.8, 1.2, 0.2, 2.2, 2.8},
new int[]{1, 10}
);

// 10 points all the same value
private INDArray targetStraightLine = Nd4j.create(
new double[]{1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.2},
new int[]{1, 10}
);


private INDArray query = Nd4j.create(new double[]{1.0, 2.0, 0.0, 0.0, -1}, new int[]{1, 5});

private Pair<INDArray, INDArray>expectedResultWhenQuery = new Pair<>(
Expand Down Expand Up @@ -99,6 +112,43 @@ public void testMatrixProfileSelfJoinStmpWindow8() {
assertEquals(expectedResultWhenSelfJoin.toString(), pair.toString());
}

@Test
public void testMatrixProfileSelfJoinStmpWindow5() {
int window = 5;

// the length of these arrays is length of the series - window + 1
Pair<INDArray, INDArray> expectedResultWhenSelfJoin = new Pair<>(
Nd4j.create(new double[]{
2.8386, 3.8080, 4.2220, 4.1329, 3.9414, 2.8386
}, new int[]{1, 6}),
Nd4j.create(new double[]{
5.0000, 5.0000, 5.0000, 0, 0, 0
}, new int[]{1, 6})
);

Pair<INDArray, INDArray> pair = matrixProfile.stmp(targetSeriesWithoutPattern, window);
assertEquals(expectedResultWhenSelfJoin.toString(), pair.toString());
}

@Test
public void testMatrixProfileSelfJoinStmpStraightLine() {
int window = 5;

// the length of these arrays is length of the series - window + 1
Pair<INDArray, INDArray> expectedResultWhenSelfJoin = new Pair<>(
Nd4j.create(new double[]{
Double.NaN, Double.NaN, Double.NaN, POSITIVE_INFINITY, 3.1623, POSITIVE_INFINITY
}, new int[]{1, 6}),
Nd4j.create(new double[]{
2.0000, 3.0000, 4.0000, 5.0000, 1.0000, 5.0000
}, new int[]{1, 6})
);

Pair<INDArray, INDArray> pair = matrixProfile.stmp(targetStraightLine, window);
assertEquals(expectedResultWhenSelfJoin.toString(), pair.toString());
}


@Test
public void testMatrixProfileSelfJoinStmpWindow4() {
int window = 4;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/test/resources/results/repeat_4_profile_pair.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1.9782, 0.8371, 0.4547, 0.0873, 0.1701, 0.4099, 0.6994, 1.4519, 1.3319, 0.9451, 1.8153, 1.9904, 1.1876, 1.0813, 0.5912, 0.1653, 0.0022, 0.1701, 0.4099, 0.6994, 1.4519, 2.0698, 1.4597, 1.9393, 2.2886, 1.8086, 1.6974, 2.0345, 2.1472, 1.9444, 1.9850, 2.5536, 1.9782, 0.8371, 0.4881, 0.0872, 0.3965, 0.7431, 1.1167, 1.3549, 1.3319, 1.1393, 0.9451, 1.6974, 1.9328, 1.3300, 1.5756, 2.0810, 1.8508, 1.1167, 1.1876, 1.0813, 0.5912, 0.1653, 0.0022, 0.5018, 0.6485, 1.3795, 1.7919, 1.4695, 1.1392, 1.3864
32.0000, 33.0000, 53.0000, 35.0000, 17.0000, 18.0000, 19.0000, 20.0000, 40.0000, 42.0000, 42.0000, 49.0000, 50.0000, 51.0000, 52.0000, 53.0000, 54.0000, 4.0000, 5.0000, 6.0000, 7.0000, 40.0000, 42.0000, 43.0000, 50.0000, 61.0000, 43.0000, 44.0000, 0, 61.0000, 22.0000, 23.0000, 0, 1.0000, 2.0000, 3.0000, 4.0000, 18.0000, 49.0000, 50.0000, 8.0000, 60.0000, 9.0000, 26.0000, 13.0000, 33.0000, 2.0000, 36.0000, 37.0000, 38.0000, 12.0000, 13.0000, 14.0000, 15.0000, 16.0000, 17.0000, 5.0000, 6.0000, 7.0000, 40.0000, 41.0000, 42.0000
1.978220820426941,0.8370792865753174,0.4546787440776825,0.08726994693279266,0.1700817495584488,0.4098934233188629,0.6994492411613464,1.4518600702285767,1.3318941593170166,0.9451253414154053,1.8153070211410522,1.9904367923736572,1.1875959634780884,1.0812915563583374,0.5911672711372375,0.16531619429588318,0.002183660166338086,0.1700761467218399,0.40988412499427795,0.6994478702545166,1.4518624544143677,2.0698282718658447,1.4597182273864746,1.9393233060836792,2.2885994911193848,1.808644413948059,1.697424054145813,2.034470558166504,2.1472036838531494,1.9444102048873901,1.985047698020935,2.553644895553589,1.9782203435897827,0.8370838165283203,0.4880507290363312,0.08724261820316315,0.3964867889881134,0.7430973052978516,1.1167277097702026,1.354939579963684,1.331898808479309,1.1392788887023926,0.9451137185096741,1.6974308490753174,1.9327597618103027,1.330040454864502,1.575606346130371,2.081027030944824,1.8508388996124268,1.116721749305725,1.1875971555709839,1.0812915563583374,0.5911785364151001,0.16531331837177277,0.002183660166338086,0.5018125176429749,0.6484558582305908,1.379483938217163,1.791913390159607,1.469473123550415,1.1392462253570557,1.386409878730774
32.0,33.0,53.0,35.0,17.0,18.0,19.0,20.0,40.0,42.0,42.0,49.0,50.0,51.0,52.0,53.0,54.0,4.0,5.0,6.0,7.0,40.0,42.0,43.0,50.0,61.0,43.0,44.0,0.0,61.0,22.0,23.0,0.0,1.0,2.0,3.0,4.0,18.0,49.0,50.0,8.0,60.0,9.0,26.0,13.0,33.0,2.0,36.0,37.0,38.0,12.0,13.0,14.0,15.0,16.0,17.0,5.0,6.0,7.0,40.0,41.0,42.0

0 comments on commit 3ce677e

Please sign in to comment.