Commit e7a56819 authored by mzed's avatar mzed
Browse files

more pairs, minor bug in constrained dtw

parent ed2c3dc6
......@@ -128,12 +128,12 @@ warpInfo dtw<T>::constrainedDTW(const std::vector<std::vector<T> > &seriesX, con
int maxY = int(seriesY.size()) - 1;
//fill cost matrix cells based on window
for (int currentX = 0; currentX < window.minValues.size(); ++currentX) {
for (int currentY = window.minValues[currentX]; currentY <= window.maxValues[currentX]; ++currentY) { //FIXME: should be <= ?
for (int currentX = 0; currentX < window.minMaxValues.size(); ++currentX) {
for (int currentY = window.minMaxValues[currentX].first; currentY <= window.minMaxValues[currentX].second; ++currentY) { //FIXME: should be <= ?
if (currentX == 0 && currentY == 0) { //bottom left cell
costMatrix[0][0] = distanceFunction(seriesX[0], seriesY[0]);
} else if (currentX == 0) { //first column
costMatrix[0][currentY] = distanceFunction(seriesX[0], seriesY[currentY]) + costMatrix[0][currentY - 0];
costMatrix[0][currentY] = distanceFunction(seriesX[0], seriesY[currentY]) + costMatrix[0][currentY - 1];
} else if (currentY == 0) { //first row
costMatrix[currentX][0] = distanceFunction(seriesX[currentX], seriesY[0]) + costMatrix[currentX - 1][0];
} else {
......
......@@ -9,8 +9,7 @@
#include "searchWindow.h"
template<typename T>
searchWindow<T>::searchWindow(const int seriesXSize, const int seriesYSize, const warpPath &shrunkenWarpPath, const int searchRadius) :
minValues(seriesXSize, -1), maxValues(seriesXSize, 0), minMaxValues(seriesXSize, std::make_pair(-1, 0)), maxY(seriesYSize - 1) {
searchWindow<T>::searchWindow(const int seriesXSize, const int seriesYSize, const warpPath &shrunkenWarpPath, const int searchRadius) : minMaxValues(seriesXSize, std::make_pair(-1, 0)), maxY(seriesYSize - 1) {
//Current location of higher resolution path
std::pair<int, int> currentIndex = shrunkenWarpPath.indices[0];
......@@ -52,18 +51,14 @@ minValues(seriesXSize, -1), maxValues(seriesXSize, 0), minMaxValues(seriesXSize,
template<typename T>
void searchWindow<T>::markVisited(int col, int row) {
if (row <= maxY && col < minValues.size()) { //Don't mark beyond the edge of the window
if (minValues[col] == -1) {
minValues[col] = row;
maxValues[col] = row;
//size++;
} else if (minValues[col] > row) {
//size += minValues[col] - row;
minValues[col] = row;
} else if (maxValues[col] < row) {
//size += row - maxValues[col];
maxValues[col] = row;
if (row <= maxY && col < minMaxValues.size()) { //Don't mark beyond the edge of the window
if (minMaxValues[col].first == -1) {
minMaxValues[col].first = row;
minMaxValues[col].second = row;
} else if (minMaxValues[col].first > row) {
minMaxValues[col].first = row;
} else if (minMaxValues[col].second < row) {
minMaxValues[col].second = row;
}
}
}
......@@ -74,13 +69,13 @@ void searchWindow<T>::expandWindow(int radius) {
//Add all cells in the current window to a vector.
std::vector<std::pair<int, int>> windowCells;
for (int currentX = 0; currentX < minValues.size(); ++currentX) {
for (int currentY = minValues[currentX]; currentY <= maxValues[currentX]; ++currentY) {
for (int currentX = 0; currentX < minMaxValues.size(); ++currentX) {
for (int currentY = minMaxValues[currentX].first; currentY <= minMaxValues[currentX].second; ++currentY) {
windowCells.push_back(std::make_pair(currentX, currentY));
}
}
int maxX = int(minValues.size() - 1);
int maxX = int(minMaxValues.size() - 1);
for (auto &currentCell : windowCells) {
......
......@@ -23,9 +23,7 @@ public:
const warpPath &shrunkenWarpPath,
const int searchRadius);
std::vector<int> minValues;
std::vector<int> maxValues;
std::vector< std::pair<int, int> > minMaxValues;
std::vector< std::pair<int, int> > minMaxValues;
private:
int maxY;
......
......@@ -361,7 +361,7 @@ describe('RapidLib Machine Learning', function () {
});
it('should report costs', function () {
expect(myDTW.getCosts()[0]).to.equal(20.071067811865476);
expect(myDTW.getCosts()[0]).to.equal(14.621232784634294);
expect(myDTW.getCosts()[1]).to.equal(0);
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment