# aeneas.cdtw¶

aeneas.cdtw is a Python C extension for computing the DTW.

`cdtw.``compute_best_path`(mfcc1, mfcc2, delta)

Compute the DTW (approximated) best path for the two audio waves, represented by their MFCCs.

This function implements the Sakoe-Chiba heuristic, that is, it explores only a band of width `2 * delta` around the main diagonal of the cost matrix.

The computation is done in-memory, and it might fail if there is not enough memory to allocate the cost matrix or the list to be returned.

The returned list contains tuples `(i, j)`, representing the best path from `(0, 0)` to `(n-1, m-1)`, where `n` is the length of `mfcc1`, and `m` is the length of `mfcc2`. The returned list has length between `min(n, m)` and `n + m` (it can be less than `n + m` if diagonal steps are selected in the best path).

Parameters: mfcc1 (`numpy.ndarray`) – the MFCCs of the first wave `(n, mfcc_size)` mfcc2 (`numpy.ndarray`) – the MFCCs of the second wave `(m, mfcc_size)` delta (int) – the margin parameter list of tuples
`cdtw.``compute_cost_matrix_step`(mfcc1, mfcc2, delta)

Compute the DTW (approximated) cost matrix for the two audio waves, represented by their MFCCs.

This function implements the Sakoe-Chiba heuristic, that is, it explores only a band of width `2 * delta` around the main diagonal of the cost matrix.

The computation is done in-memory, and it might fail if there is not enough memory to allocate the cost matrix.

The returned tuple `(cost_matrix, centers)` contains the cost matrix (NumPy 2D array of shape (n, delta)) and the row centers (NumPy 1D array of size n).

Parameters: mfcc1 (`numpy.ndarray`) – the MFCCs of the first wave `(n, mfcc_size)` mfcc2 (`numpy.ndarray`) – the MFCCs of the second wave `(m, mfcc_size)` delta (int) – the margin parameter tuple
`cdtw.``compute_accumulated_cost_matrix_step`(cost_matrix, centers)

Compute the DTW (approximated) accumulated cost matrix from the cost matrix and the row centers.

This function implements the Sakoe-Chiba heuristic, that is, it explores only a band of width `2 * delta` around the main diagonal of the cost matrix.

The computation is done in-memory, and the accumulated cost matrix is computed in place, that is, the original cost matrix is destroyed and its allocated memory used to store the accumulated cost matrix. Hence, this call should not fail for memory reasons.

The returned NumPy 2D array of shape `(n, delta)` contains the accumulated cost matrix.

Parameters: cost_matrix (`numpy.ndarray`) – the cost matrix `(n, delta)` centers (`numpy.ndarray`) – the row centers `(n,)` `numpy.ndarray`
`cdtw.``compute_best_path_step`(accumulated_cost_matrix, centers)

Compute the DTW (approximated) best path from the accumulated cost matrix and the row centers.

This function implements the Sakoe-Chiba heuristic, that is, it explores only a band of width `2 * delta` around the main diagonal of the cost matrix.

The computation is done in-memory, and it might fail if there is not enough memory to allocate the list to be returned.

The returned list contains tuples `(i, j)`, representing the best path from `(0, 0)` to `(n-1, m-1)`, where `n` is the length of `mfcc1`, and `m` is the length of `mfcc2`. The returned list has length between `min(n, m)` and `n + m` (it can be less than `n + m` if diagonal steps are selected in the best path).

Parameters: cost_matrix (`numpy.ndarray`) – the accumulated cost matrix `(n, delta)` centers (`numpy.ndarray`) – the row centers `(n, )` list of tuples