Dynamic Time Warping (DTW)

This page describes the parameters for the Dynamic Time Warping (DTW) algorithm as part of AI libs.

.ai.dtw.filterSearch

The .ai.dtw.filterSearch function returns the k best matches for q from ts under cutoff distance.

Parameters

Name

Type(s)

Description

ts

float[]

The timeseries ts to search on

q

float[]

The pattern to search for

k

int | long

The number of best matches to return

window

real | float

The ratio of query size allowed in warping

cutoff

real | float

The maximum distance (exclusive)

opts

dict

Advanced options (optional):

  • ignoreErrors (default false): if true, allows q longer than ts (returns empty)

  • returnMatches (default false): if true, returns a list of distances, indexes, and matched patterns

Returns

Type

Description

(float[]; long[])

A list of distances and ids for nearest matches

Example

q

Copy
 ts: neg[5.0] + 1000?10.0;
 q:neg[5.0] + 10?10.0;
 .ai.dtw.filterSearch[ts;q;4;0.3;1.4;::]
 1.336535 1.376232 1.39632
 492      848      875 

.ai.dtw.search

The .ai.dtw.search function returns k best matches for q from ts.

Parameters

Name

Type(s)

Description

ts

float[]

The timeseries to search on

q

float[]

The pattern to search for

k

int | long

The number of best matches to return

window

real | float

The ratio of query size allowed in warping

opts

dict

Advanced options (optional):

  • ignoreErrors (default false): if true, allows q longer than ts (returns empty)

  • returnMatches (default false): if true, returns a list of distances, indexes, and matched patterns

Returns

Type

Description

(float[]; long[])

A list of distances and ids for nearest matches

Example

q

Copy
 ts: neg[5.0] + 1000?10.0;
 q:neg[5.0] + 10?10.0;
 .ai.dtw.search[ts;q;4;0.3;::]
 1.336535 1.376232 1.39632 1.41458
 492      848      875     295

.ai.dtw.searchRange

The .ai.dtw.searchRange function returns the best matches for q from ts under cutoff distance.

Parameters

Name

Type(s)

Description

ts

float[]

The timeseries to search on

q

float[]

The pattern to search for

window

real | float

The ratio of query size allowed in warping

cutoff

real | float

The maximum distance (exclusive)

opts

dict

Advanced options (optional):

  • ignoreErrors (default false): if true, allows q longer than ts (returns empty)

  • returnMatches (default false): if true, returns a list of distances, indexes, and matched patterns

Returns

Type

Description

(float[]; long[])

A list of distances and ids for nearest matches

Example

q

Copy
 ts: neg[5.0] + 1000?10.0;
 q:neg[5.0] + 10?10.0;
 .ai.dtw.searchRange[ts;q;0.3;1.4;::]
 1.336535 1.376232 1.39632
 492      848      875