-
Notifications
You must be signed in to change notification settings - Fork 67
/
SFAWordsTest.java
70 lines (55 loc) · 2.24 KB
/
SFAWordsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2016 - Patrick Schäfer (patrick.schaefer@zib.de)
// Distributed under the GLP 3.0 (See accompanying file LICENSE)
package sfa;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import sfa.timeseries.TimeSeries;
import sfa.timeseries.TimeSeriesLoader;
import sfa.transformation.SFA;
import sfa.transformation.SFA.HistogramType;
/**
* Tests the SFA transformation
*/
@RunWith(JUnit4.class)
public class SFAWordsTest {
@Test
public void testSFAWords() throws IOException {
int symbols = 8;
int wordLength = 16;
boolean normMean = true;
SFA sfa = new SFA(HistogramType.EQUI_DEPTH);
// Load the train/test splits
ClassLoader classLoader = SFAWordsTest.class.getClassLoader();
TimeSeries[] train = TimeSeriesLoader.loadDataset(classLoader.getResource("datasets/univariate/CBF/CBF_TRAIN").getFile());
TimeSeries[] test = TimeSeriesLoader.loadDataset(classLoader.getResource("datasets/univariate/CBF/CBF_TEST").getFile());
// train SFA representation
sfa.fitTransform(train, wordLength, symbols, normMean);
// outout discretization bins
// sfa.printBins();
// check discretization bins
Assert.assertTrue("Wrong word queryLength of SFA transformation detected", sfa.bins.length == wordLength);
for (int i = 0; i < sfa.bins.length; i++) {
for (int j = 0; j < sfa.bins[i].length-1; j++) {
Assert.assertTrue("SFA bins should be monotonically increasing.", sfa.bins[i][j] <= sfa.bins[i][j+1]);
}
}
// transform
for (int q = 0; q < test.length; q++) {
short[] wordQuery = sfa.transform(test[q]);
Assert.assertTrue("SFA word queryLength does not match actual queryLength.", wordQuery.length == wordLength);
// System.out.println(q + "-th transformed time series SFA word " + "\t" + toSfaWord(wordQuery, symbols));
}
}
public static String toSfaWord(short[] word, int symbols) {
StringBuilder sfaWord = new StringBuilder();
for (short c : word) {
sfaWord.append((char) (Character.valueOf('a') + c));
Assert.assertTrue("Wrong symbols used ", c < symbols && c >= 0);
}
sfaWord.append("\t... OK");
return sfaWord.toString();
}
}