Skip to content
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ Default method: `"arzt"`
| `"dixon"` | On-line time warping by Dixon (2005) |
| `"outerhmm"` | Outer-product HMM score follower by Nakamura (2014) |
| `"skf"` | Switching Kalman Filter with hidden tempo by Jiang and Raphael (2020) |
| `"arzt_tempo"` | On-line time warping by Arzt with a tempo model (Arzt and Widmer, 2010) |
| `"arzt_multi_fold"` | Arzt OLTW tracking several unfolded score variants in parallel |

### MIDI (`input_type="midi"`)

Expand Down
2 changes: 2 additions & 0 deletions matchmaker/dp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
OnlineTimeWarpingArzt,
OnlineTimeWarpingArztEvent,
OnlineTimeWarpingArztFrame,
OnlineTimeWarpingArztTempoFrame,
)
from .oltw_dixon import (
OnlineTimeWarpingDixon,
OnlineTimeWarpingDixonEvent,
OnlineTimeWarpingDixonFrame,
)
from .oltw_arzt_multi_fold import OnlineTimeWarpingArztMultiFold
17 changes: 14 additions & 3 deletions matchmaker/dp/dtw_loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def oltw_arzt_loop(
int window_end,
int input_index,
float min_costs,
int min_index
int min_index,
signed char[:] backpointers = None
):
"""
Cythonized main loop for online time warping.
Expand All @@ -46,6 +47,8 @@ def oltw_arzt_loop(
Minimum costs of current window.
min_index: int
Index of minimum costs of current window.
backpointers: numpy.ndarray, optional
1D array of shape (window_end - window_start,) to record predecessor steps.

Returns
-------
Expand All @@ -56,7 +59,7 @@ def oltw_arzt_loop(
min_costs: float
Minimum costs of current window.
"""
cdef float dist1, dist2, dist3, local_dist, norm_cost
cdef float dist1, dist2, dist3, min_dist, local_dist, norm_cost
cdef int idx = 0, score_index = window_start
cdef Py_ssize_t k, wk = window_cost.shape[0]
cdef Py_ssize_t N = global_cost_matrix.shape[0]
Expand Down Expand Up @@ -84,6 +87,14 @@ def oltw_arzt_loop(
min_dist = min(dist1, dist2, dist3)
global_cost_matrix[score_index + 1, 1] = min_dist

if backpointers is not None:
if dist1 <= dist2 and dist1 <= dist3:
backpointers[idx] = 1
elif dist2 <= dist3:
backpointers[idx] = 2
else:
backpointers[idx] = 3

norm_cost = min_dist / (input_index + score_index + 1.0)

# check if new cell has lower costs and might be current position
Expand All @@ -96,7 +107,7 @@ def oltw_arzt_loop(

update_cost_matrix(global_cost_matrix, N)

return global_cost_matrix, min_index, min_costs
return np.asarray(global_cost_matrix), min_index, min_costs

@cython.boundscheck(False)
@cython.wraparound(False)
Expand Down
Loading
Loading