Data Structures | Defines | Enumerations | Functions

src/warping.h File Reference

STATUS: stable Warping functions. More...

#include "mathadd.h"
#include "definitions.h"
#include "time_frequency.h"
#include "regularization.h"
#include "eeg.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WarpPath

Defines

#define warppath_CHECK(flag, w)
 is w a warppath?

Enumerations

enum  SlopeConstraint { SLOPE_CONSTRAINT_NONE = 0, SLOPE_CONSTRAINT_LAX, SLOPE_CONSTRAINT_MEDIUM, SLOPE_CONSTRAINT_SEVERE }
 

Severity of the slope constraint in the Dynamic Time-Warping Alg.

More...

Functions

Arraydtw_add_signals (const Array *s1, const Array *s2, const Array *path, OptArgList *opts)
 Add signals according to a warppath.
WarpPathdtw_backtrack (const double **d, int M, int N, WarpPath *P)
void dtw_cumulate_matrix (double **d, int M, int N, OptArgList *opts)
EEGeeg_dtw_hierarchical (EEG *eeg_in, const double **distmatrix, EEG *out, OptArgList *optargs)
EEGeeg_gibbons (EEG *eeg, int stimulus_marker, int response_marker, double k)
void free_warppath (WarpPath *p)
WarpPathinit_warppath (WarpPath *path, int n1, int n2)
Arraymatrix_dtw_backtrack (const Array *d)
 calculate the warping path.
Arraymatrix_dtw_cumulate (Array *mat, bool alloc, OptArgList *optargs)
 cumulate a distance matrix d for Dynamic Time-Warping.
void print_warppath (FILE *out, WarpPath *P)
void reset_warppath (WarpPath *P, int n1, int n2)

Detailed Description

STATUS: stable Warping functions.

Example for warping 2D data:

2dwarping.jpg
pardtw Dynamic Time Warping

Dynamic Time-Warping is a method to account for temporal distortion when comparing two signals. It is done by finding a function that minimizes the sum of entries through a distance matrix, such that

\[ \mbox{argmin}_\phi \int d(s_1(t_1),s_2(\phi(t_2))) \]

for a given pointwise distance between two signals. Such distances can be computed using the functions in distances.h.

The minimization is done by cumulating the matrix

\[ D_{jk} = \mathbf{d}_{jk}+min{\{D_{j,k-1}, D_{j-1,k}, D_{j-1, k-1}\}} \]

and backtracking via the minimum of the three neighboring entries (down, down-right, right) from$D_{J,K}$ to$D_{1,1}$. Here, the functions dtw_cumulate_matrix() and dtw_backtrack() do that.

Finally, the signals need to be mapped to one another to get time-amplitude averaging with

\[ s'(t)=\frac{\omega_1 s_1(p_1^t) + \omega_2 s_2(p_2^t)}{\omega_1 + \omega_2} \]

using weights$\omega_1,\omega_2$. Here, you can use warp_add_signals_by_path().

Definition in file warping.h.


Function Documentation

WarpPath* dtw_backtrack ( const double **  d,
int  M,
int  N,
WarpPath P 
)

Definition at line 526 of file warping.c.

void dtw_cumulate_matrix ( double **  d,
int  M,
int  N,
OptArgList optargs 
)

GOING TO BE OBSOLETE

cumulate a distance matrix d to give

\[ D_{jk} = d_{jk}+\min{\{D_{j,k-1}, D_{j-1,k}, D_{j-1, k-1}\}} \]

Parameters:
d input/output matrix
M,N dimensions of d
optargs may contain:

  • "slope_constraint=int" slope constraint, one of SLOPE_CONSTRAINT_*; default=SLOPE_CONSTRAINT_NONE

Definition at line 488 of file warping.c.

EEG* eeg_dtw_hierarchical ( EEG eeg_in,
const double **  distmatrix,
EEG out,
OptArgList optargs 
)
EEG* eeg_gibbons ( EEG eeg,
int  stimulus_marker,
int  response_marker,
double  k 
)

Warp-average according to Gibbons+Stahl 2007. They proposed to stretch or compress the single signals in order to match the average reaction time, by simply moving the sampling points in time according to a linear, quadratic, cubic or to-the-power-of-four function. Formally, they adjusted the time-axis by letting

\[ \phi_t^{-1}(t) = t + \frac{t^k}{R^k_t}(E(R) - R_t) \]

where$ R_t $ denotes the reaction time of the current trial and E is the expected value (the mean reaction time across trials). In their work, Gibbons et al. studied this approach for$ k \in \{1,2,3,4\} $.

Individual trials are warped according to$ \phi $ and also the averages obtained from different individuals. Warping takes place between stimulus-onset-marker and response-marker

Parameters:
eeg_in input
stmulus_marker gives the index indicating which of the markers within eeg_in is the stimulus-onset
response_marker gives the index indicating which of the markers within eeg_in is the response-onset
k parameter for gibbon's method
Returns:
pointer to newly allocated memory

Definition at line 318 of file warping.c.

void free_warppath ( WarpPath p  ) 

Definition at line 450 of file warping.c.

WarpPath* init_warppath ( WarpPath path,
int  n1,
int  n2 
)

Definition at line 419 of file warping.c.

void print_warppath ( FILE *  out,
WarpPath P 
)

Definition at line 456 of file warping.c.

void reset_warppath ( WarpPath P,
int  n1,
int  n2 
)

Definition at line 441 of file warping.c.