Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
rapid-mix
RapidLib
Commits
e7a56819
Commit
e7a56819
authored
Nov 28, 2017
by
mzed
Browse files
more pairs, minor bug in constrained dtw
parent
ed2c3dc6
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/dtw.cpp
View file @
e7a56819
...
...
@@ -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
.
min
Max
Values
.
size
();
++
currentX
)
{
for
(
int
currentY
=
window
.
min
Max
Values
[
currentX
]
.
first
;
currentY
<=
window
.
m
inM
axValues
[
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
{
...
...
src/searchWindow.cpp
View file @
e7a56819
...
...
@@ -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
<
min
Max
Values
.
size
();
++
currentX
)
{
for
(
int
currentY
=
min
Max
Values
[
currentX
]
.
first
;
currentY
<=
m
inM
axValues
[
currentX
]
.
second
;
++
currentY
)
{
windowCells
.
push_back
(
std
::
make_pair
(
currentX
,
currentY
));
}
}
int
maxX
=
int
(
minValues
.
size
()
-
1
);
int
maxX
=
int
(
min
Max
Values
.
size
()
-
1
);
for
(
auto
&
currentCell
:
windowCells
)
{
...
...
src/searchWindow.h
View file @
e7a56819
...
...
@@ -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
;
...
...
test/test.js
View file @
e7a56819
...
...
@@ -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
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment