This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More tests.
- Loading branch information
FlorianLautenschlager
committed
Feb 23, 2016
1 parent
8866090
commit c2c047f
Showing
23 changed files
with
140 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 QAware GmbH | ||
Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/de/qaware/chronix/distance/DistanceFunctionEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/de/qaware/chronix/distance/DistanceFunctionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/de/qaware/chronix/distance/EuclideanDistance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/de/qaware/chronix/distance/ManhattanDistance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -105,7 +105,7 @@ private static TimeWarpInfo dynamicTimeWarp(MultivariateTimeSeries tsI, Multivar | |
final WarpPath minCostPath = new WarpPath(maxI + maxJ - 1); | ||
int i = maxI; | ||
int j = maxJ; | ||
minCostPath.addFirst(i, j); | ||
minCostPath.add(i, j); | ||
while ((i > 0) || (j > 0)) { | ||
// Find the costs of moving in all three possible directions (left, | ||
// down, and diagonal (down and left at the same time). | ||
|
@@ -143,7 +143,7 @@ else if (i <= j) // leftCost==rightCost > diagCost | |
i--; | ||
|
||
// Add the current step to the warp path. | ||
minCostPath.addFirst(i, j); | ||
minCostPath.add(i, j); | ||
} | ||
|
||
return new TimeWarpInfo(minimumCost, minCostPath, tsI.size(), tsJ.size()); | ||
|
@@ -209,7 +209,7 @@ private static TimeWarpInfo constrainedTimeWarp(MultivariateTimeSeries tsI, Mult | |
final WarpPath minCostPath = new WarpPath(maxI + maxJ - 1); | ||
int i = maxI; | ||
int j = maxJ; | ||
minCostPath.addFirst(i, j); | ||
minCostPath.add(i, j); | ||
while ((i > 0) || (j > 0)) { | ||
// Find the costs of moving in all three possible directions (left, | ||
// down, and diagonal (down and left at the same time). | ||
|
@@ -247,7 +247,7 @@ else if (i <= j) // leftCost==rightCost > diagCost | |
i--; | ||
|
||
// Add the current step to the warp path. | ||
minCostPath.addFirst(i, j); | ||
minCostPath.add(i, j); | ||
} // end while loop | ||
|
||
return new TimeWarpInfo(minimumCost, minCostPath, tsI.size(), tsJ.size()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -26,6 +26,8 @@ | |
|
||
import de.qaware.chronix.dt.IntList; | ||
import de.qaware.chronix.matrix.ColMajorCell; | ||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
|
@@ -34,96 +36,67 @@ | |
* @author f.lautenschlager | ||
*/ | ||
public final class WarpPath { | ||
private final IntList tsIindexes; // ArrayList of Integer | ||
private final IntList tsJindexes; // ArrayList of Integer | ||
|
||
public WarpPath() { | ||
tsIindexes = new IntList(); | ||
tsJindexes = new IntList(); | ||
} | ||
private final IntList tsIindexes; | ||
private final IntList tsJindexes; | ||
|
||
|
||
public WarpPath(int initialCapacity) { | ||
tsIindexes = new IntList(initialCapacity); | ||
tsJindexes = new IntList(initialCapacity); | ||
} | ||
|
||
|
||
/** | ||
* @return the size of the warp path | ||
*/ | ||
public int size() { | ||
return tsIindexes.size(); | ||
} | ||
|
||
/** | ||
* @return the min i index (last element), -1 if empty | ||
*/ | ||
public int minI() { | ||
return tsIindexes.get(tsIindexes.size() - 1); | ||
if (tsIindexes.size() > 0) { | ||
return tsIindexes.get(tsIindexes.size() - 1); | ||
} | ||
return -1; | ||
} | ||
|
||
/** | ||
* @return the min j index | ||
*/ | ||
public int minJ() { | ||
return tsJindexes.get(tsJindexes.size() - 1); | ||
if (tsJindexes.size() > 0) { | ||
return tsJindexes.get(tsJindexes.size() - 1); | ||
} | ||
return -1; | ||
} | ||
|
||
/** | ||
* @return max i index (first element), -1 if empty | ||
*/ | ||
public int maxI() { | ||
return tsIindexes.get(0); | ||
if (tsIindexes.size() > 0) { | ||
return tsIindexes.get(0); | ||
} | ||
return -1; | ||
} | ||
|
||
/** | ||
* @return max j index (first element), -1 if empty | ||
*/ | ||
public int maxJ() { | ||
return tsJindexes.get(0); | ||
if (tsJindexes.size() > 0) { | ||
return tsJindexes.get(0); | ||
} | ||
return -1; | ||
} | ||
|
||
public void addFirst(int i, int j) { | ||
public void add(int i, int j) { | ||
tsIindexes.add(i); | ||
tsJindexes.add(j); | ||
} | ||
|
||
public void addLast(int i, int j) { | ||
tsIindexes.add(0, i); | ||
tsJindexes.add(0, j); | ||
} | ||
|
||
|
||
public IntList getMatchingIndexesForI(int i) { | ||
int index = tsIindexes.indexOf(i); | ||
if (index < 0) | ||
throw new InternalError("ERROR: index '" + i + " is not in the " + "warp path."); | ||
final IntList matchingJs = new IntList(tsIindexes.size()); | ||
while (index < tsIindexes.size() && tsIindexes.get(index) == i) | ||
matchingJs.add(tsJindexes.get(index++)); | ||
|
||
return matchingJs; | ||
} | ||
|
||
|
||
public IntList getMatchingIndexesForJ(int j) { | ||
int index = tsJindexes.indexOf(j); | ||
if (index < 0) | ||
throw new InternalError("ERROR: index '" + j + " is not in the " + "warp path."); | ||
final IntList matchingIs = new IntList(tsJindexes.size()); | ||
while (index < tsJindexes.size() && tsJindexes.get(index) == j) | ||
matchingIs.add(tsIindexes.get(index++)); | ||
|
||
return matchingIs; | ||
} | ||
|
||
|
||
// Create a new WarpPath that is the same as THIS WarpPath, but J is the reference template, rather than I. | ||
public WarpPath invertedCopy() { | ||
final WarpPath newWarpPath = new WarpPath(); | ||
for (int x = 0; x < tsIindexes.size(); x++) | ||
newWarpPath.addLast(tsJindexes.get(x), tsIindexes.get(x)); | ||
|
||
return newWarpPath; | ||
} | ||
|
||
|
||
// Swap I and J so that the warp path now indicates that J is the template rather than I. | ||
public void invert() { | ||
for (int x = 0; x < tsIindexes.size(); x++) { | ||
final int temp = tsIindexes.get(x); | ||
tsIindexes.set(x, tsJindexes.get(x)); | ||
tsJindexes.set(x, temp); | ||
} | ||
} | ||
|
||
|
||
public ColMajorCell get(int index) { | ||
if ((index > this.size()) || (index < 0)) | ||
throw new NoSuchElementException(); | ||
|
@@ -132,6 +105,7 @@ public ColMajorCell get(int index) { | |
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
StringBuilder outStr = new StringBuilder("["); | ||
for (int x = 0; x < tsIindexes.size(); x++) { | ||
|
@@ -145,6 +119,7 @@ public String toString() { | |
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if ((obj instanceof WarpPath)) // trivial false test | ||
{ | ||
|
@@ -163,9 +138,11 @@ public boolean equals(Object obj) { | |
return false; | ||
} | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
return tsIindexes.hashCode() * tsJindexes.hashCode(); | ||
return new HashCodeBuilder() | ||
.append(tsIindexes) | ||
.append(tsJindexes) | ||
.toHashCode(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/de/qaware/chronix/timeseries/MultivariateTimeSeries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 QAware GmbH | ||
* Copyright (c) 2016 Stan Salvador ([email protected]), Philip Chan ([email protected]), QAware GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
Oops, something went wrong.