Skip to content

More appropriate usage of NThreshold #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/net/seninp/jmotif/sax/TSProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,26 @@ public double stDev(double[] series) {

/**
* Z-Normalize routine.
* Single parameter version is for actual distance calculation.
* Double parameter version (include normalizationThreshold) is for SAX.
*
* @param series the input timeseries.
* @param normalizationThreshold the zNormalization threshold value.
* @return Z-normalized time-series.
*/

public double[] znorm(double[] series) {
double[] res = new double[series.length];
double mean = mean(series);
double sd = stDev(series);

for (int i = 0; i < res.length; i++) {
res[i] = (series[i] - mean) / sd;
}
return res;

}

public double[] znorm(double[] series, double normalizationThreshold) {
double[] res = new double[series.length];
double mean = mean(series);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private static DiscordRecord findBestDiscordWithMagic(double[] series, int windo

// fix the current subsequence trace
double[] currentCandidateSeq = tp
.znorm(tp.subseriesByCopy(series, currentPos, currentPos + windowSize), nThreshold);
.znorm(tp.subseriesByCopy(series, currentPos, currentPos + windowSize));

// let the search begin ..
double nearestNeighborDist = Double.MAX_VALUE;
Expand All @@ -254,7 +254,7 @@ private static DiscordRecord findBestDiscordWithMagic(double[] series, int windo
// nextOccurrence + windowSize);
// double dist = ed.distance(currentCandidateSeq, occurrenceSubsequence);
double dist = distance(currentCandidateSeq, series, nextOccurrence,
nextOccurrence + windowSize, nThreshold);
nextOccurrence + windowSize);
distanceCalls++;

// keep track of best so far distance
Expand Down Expand Up @@ -309,8 +309,7 @@ private static DiscordRecord findBestDiscordWithMagic(double[] series, int windo
// double[] randomSubsequence = tp.subseriesByCopy(series, randomPos,
// randomPos + windowSize);
// double dist = ed.distance(currentCandidateSeq, randomSubsequence);
double dist = distance(currentCandidateSeq, series, randomPos, randomPos + windowSize,
nThreshold);
double dist = distance(currentCandidateSeq, series, randomPos, randomPos + windowSize);
distanceCalls++;

// keep track
Expand Down Expand Up @@ -668,16 +667,15 @@ private static ArrayList<FrequencyTableEntry> hashToFreqEntries(
* Calculates the Euclidean distance between two points. Don't use this unless you need that.
*
* @param subseries The first subsequence -- ASSUMED TO BE Z-normalized.
* @param series The second point.
* @param series The second subsequence.
* @param from the initial index of the range to be copied, inclusive
* @param to the final index of the range to be copied, exclusive. (This index may lie outside the
* array.)
* @param nThreshold z-Normalization threshold.
* @return The Euclidean distance between z-Normalized versions of subsequences.
*/
private static double distance(double[] subseries, double[] series, int from, int to,
double nThreshold) throws Exception {
double[] subsequence = tp.znorm(tp.subseriesByCopy(series, from, to), nThreshold);
private static double distance(double[] subseries, double[] series, int from, int to) throws Exception {
double[] subsequence = tp.znorm(tp.subseriesByCopy(series, from, to));
Double sum = 0D;
for (int i = 0; i < subseries.length; i++) {
double tmp = subseries[i] - subsequence[i];
Expand Down