DTW Windows

class darts.dataprocessing.dtw.window.CRWindow(n, m, ranges=None)[source]

Bases: Window

Compressed row representation window. Stores the range of active grid cells in each column. Any window with contiguous columns can be expressed as a CRWindow. Supports efficient iterative construction and updates.

Methods

add(elem)

Marks a grid cell as active.

add_range(column, start, end)

Extends the active cells in the column by the range (start,end).

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

Parameters
  • n (int) – The width of the window, must be equal to the length of series1

  • m (int) – The height of the window, must be equal to the length of series2

  • ranges (Optional[ndarray]) – The ranges of active cells within a column [[start_column0, end_column0], …] with shape (n, 2) and where start >= 0 and end <= m.

Methods

add(elem)

Marks a grid cell as active.

add_range(column, start, end)

Extends the active cells in the column by the range (start,end).

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

add(elem)[source]

Marks a grid cell as active.

Parameters

elem (Tuple[int, int]) – Tuple of grid cell index (column, row)

add_range(column, start, end)[source]

Extends the active cells in the column by the range (start,end). Ranges smaller than the current one are ignored. Note (1, m+1), not (0,m) corresponds to an entire column.

Parameters
  • column (int) – Column int index

  • start (int) – Row element int index where start >= 1 and start <= end

  • end (int) – Row element int index where end >= 1 and end <= m+1

column_index(elem)[source]

Gives the number of active grid cells before row element j, in column i.

Parameters

elem (Tuple[int, int]) – (i,j) index, where i indexes columns and j rows

Returns

The number of active grid cells before row element j, in column i, If (i,j) is not an active grid cell returns -1

Return type

int

column_length(column)[source]

Gives the number of active grid cells in a column.

Parameters

column (int) – A column in the window, must be within 0 < column < n+1

Returns

The number of active grid cells in a column.

Return type

int

column_lengths()[source]

Gives the number of activate grid cells in each column.

Returns

The number of active grid cells in each column.

Return type

np.ndarray of shape (n+1,)

column_ranges: array
init_size(n, m)

Called by dtw to initialize the window to a certain size.

Parameters
  • n (int) – The width of the window, must be equal to the length of series1 used for DTW

  • m (int) – The height of the window, must be equal to the length of series2 used for DTW

length: int
m: int
n: int
class darts.dataprocessing.dtw.window.Itakura(max_slope)[source]

Bases: CRWindow

Forms the Itakura parallelogram, where max_slope determines the slope of the steeper side.

Examples

>>>                                      x
>>>                                  xxxx
>>>                   B           xxxxxx
>>>                         xxxxxxxxxxx
>>>                     xxxxxxxxxxxxxx
>>>                 xxxxxxxxxxxxxxxxx
>>>              xxxxxxxxxxxxxxxxxxxx     C
>>>            xxxxxxxxxxxxxxxxxxxxx
>>>           xxxxxxxxxxxxxxxxxxxxx
>>>          xxxxxxxxxxxxxxxxxxxxx
>>>     A   xxxxxxxxxxxxxxxxxxxxx
>>>        xxxxxxxxxxxxxxxxxxxxx
>>>       xxxxxxxxxxxxxxxxxxxxx
>>>      xxxxxxxxxxxxxxxxxxxx
>>>     xxxxxxxxxxxxxxxx       D
>>>     xxxxxxxxxxxx
>>>    xxxxxxxxx
>>>   xxxxxx
>>>  xxx
>>> x

Methods

add(elem)

Marks a grid cell as active.

add_range(column, start, end)

Extends the active cells in the column by the range (start,end).

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

Parameters

max_slope (float) – The slope of the steeper parallelogram side.

Methods

add(elem)

Marks a grid cell as active.

add_range(column, start, end)

Extends the active cells in the column by the range (start,end).

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

add(elem)

Marks a grid cell as active.

Parameters

elem (Tuple[int, int]) – Tuple of grid cell index (column, row)

add_range(column, start, end)

Extends the active cells in the column by the range (start,end). Ranges smaller than the current one are ignored. Note (1, m+1), not (0,m) corresponds to an entire column.

Parameters
  • column (int) – Column int index

  • start (int) – Row element int index where start >= 1 and start <= end

  • end (int) – Row element int index where end >= 1 and end <= m+1

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

Parameters

elem (Tuple[int, int]) – (i,j) index, where i indexes columns and j rows

Returns

The number of active grid cells before row element j, in column i, If (i,j) is not an active grid cell returns -1

Return type

int

column_length(column)

Gives the number of active grid cells in a column.

Parameters

column (int) – A column in the window, must be within 0 < column < n+1

Returns

The number of active grid cells in a column.

Return type

int

column_lengths()

Gives the number of activate grid cells in each column.

Returns

The number of active grid cells in each column.

Return type

np.ndarray of shape (n+1,)

column_ranges: array
init_size(n, m)[source]

Called by dtw to initialize the window to a certain size.

Parameters
  • n (int) – The width of the window, must be equal to the length of series1 used for DTW

  • m (int) – The height of the window, must be equal to the length of series2 used for DTW

length: int
m: int
n: int
class darts.dataprocessing.dtw.window.NoWindow[source]

Bases: Window

Window covers the entire grid, meaning every possible alignment between series1 and series2 is considered.

Methods

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

column_index(elem)[source]

Gives the number of active grid cells before row element j, in column i.

Parameters

elem (Tuple[int, int]) – (i,j) index, where i indexes columns and j rows

Returns

The number of active grid cells before row element j, in column i, If (i,j) is not an active grid cell returns -1

Return type

int

column_length(column)[source]

Gives the number of active grid cells in a column.

Parameters

column (int) – A column in the window, must be within 0 < column < n+1

Returns

The number of active grid cells in a column.

Return type

int

column_lengths()[source]

Gives the number of activate grid cells in each column.

Returns

The number of active grid cells in each column.

Return type

np.ndarray of shape (n+1,)

init_size(n, m)

Called by dtw to initialize the window to a certain size.

Parameters
  • n (int) – The width of the window, must be equal to the length of series1 used for DTW

  • m (int) – The height of the window, must be equal to the length of series2 used for DTW

m: int
n: int
class darts.dataprocessing.dtw.window.SakoeChiba(window_size)[source]

Bases: CRWindow

Forms a diagonal window where window_size controls the maximum allowed shift between the two series. If both time-series have the same time axis, window_size corresponds to the maximum number of time periods

Methods

add(elem)

Marks a grid cell as active.

add_range(column, start, end)

Extends the active cells in the column by the range (start,end).

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

Parameters

window_size (int) – The maximum allowed shift between the two series used in DTW.

Methods

add(elem)

Marks a grid cell as active.

add_range(column, start, end)

Extends the active cells in the column by the range (start,end).

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

add(elem)

Marks a grid cell as active.

Parameters

elem (Tuple[int, int]) – Tuple of grid cell index (column, row)

add_range(column, start, end)

Extends the active cells in the column by the range (start,end). Ranges smaller than the current one are ignored. Note (1, m+1), not (0,m) corresponds to an entire column.

Parameters
  • column (int) – Column int index

  • start (int) – Row element int index where start >= 1 and start <= end

  • end (int) – Row element int index where end >= 1 and end <= m+1

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

Parameters

elem (Tuple[int, int]) – (i,j) index, where i indexes columns and j rows

Returns

The number of active grid cells before row element j, in column i, If (i,j) is not an active grid cell returns -1

Return type

int

column_length(column)

Gives the number of active grid cells in a column.

Parameters

column (int) – A column in the window, must be within 0 < column < n+1

Returns

The number of active grid cells in a column.

Return type

int

column_lengths()

Gives the number of activate grid cells in each column.

Returns

The number of active grid cells in each column.

Return type

np.ndarray of shape (n+1,)

column_ranges: array
init_size(n, m)[source]

Called by dtw to initialize the window to a certain size.

Parameters
  • n (int) – The width of the window, must be equal to the length of series1 used for DTW

  • m (int) – The height of the window, must be equal to the length of series2 used for DTW

length: int
m: int
n: int
class darts.dataprocessing.dtw.window.Window[source]

Bases: ABC

Methods

column_index(elem)

Gives the number of active grid cells before row element j, in column i.

column_length(column)

Gives the number of active grid cells in a column.

column_lengths()

Gives the number of activate grid cells in each column.

init_size(n, m)

Called by dtw to initialize the window to a certain size.

abstract column_index(elem)[source]

Gives the number of active grid cells before row element j, in column i.

Parameters

elem (Tuple[int, int]) – (i,j) index, where i indexes columns and j rows

Returns

The number of active grid cells before row element j, in column i, If (i,j) is not an active grid cell returns -1

Return type

int

abstract column_length(column)[source]

Gives the number of active grid cells in a column.

Parameters

column (int) – A column in the window, must be within 0 < column < n+1

Returns

The number of active grid cells in a column.

Return type

int

column_lengths()[source]

Gives the number of activate grid cells in each column.

Returns

The number of active grid cells in each column.

Return type

np.ndarray of shape (n+1,)

init_size(n, m)[source]

Called by dtw to initialize the window to a certain size.

Parameters
  • n (int) – The width of the window, must be equal to the length of series1 used for DTW

  • m (int) – The height of the window, must be equal to the length of series2 used for DTW

m: int
n: int
darts.dataprocessing.dtw.window.gtz(value)[source]