lib/dtw.js
function (options) {
    var state = { distanceCostMatrix: null };
    if (typeof options === 'undefined') {
        state.distance = require('./distanceFunctions/squaredEuclidean').distance;
    } else {
        validateOptions(options);
        if (typeof options.distanceMetric === 'string') {
            state.distance = retrieveDistanceFunction(options.distanceMetric);
        } else if (typeof options.distanceFunction === 'function') {
            state.distance = options.distanceFunction;
        }
    }

    this.compute = function (firstSequence, secondSequence, window) {
        var cost = Number.POSITIVE_INFINITY;
        if (typeof window === 'undefined') {
            cost = computeOptimalPath(firstSequence, secondSequence, state);
        } else if (typeof window === 'number') {
            cost = computeOptimalPathWithWindow(firstSequence, secondSequence, window, state);
        } else {
            throw new TypeError('Invalid window parameter type: expected a number');
        }

        return cost;
    };

    this.path = function () {
        var path = null;
        if (state.distanceCostMatrix instanceof Array) {
            path = retrieveOptimalPath(state);
        }

        return path;
    };
}
function (options) {
    var state = { distanceCostMatrix: null };
    if (typeof options === 'undefined') {
        state.distance = require('./distanceFunctions/squaredEuclidean').distance;
    } else {
        validateOptions(options);
        if (typeof options.distanceMetric === 'string') {
            state.distance = retrieveDistanceFunction(options.distanceMetric);
        } else if (typeof options.distanceFunction === 'function') {
            state.distance = options.distanceFunction;
        }
    }

    this.compute = function (firstSequence, secondSequence, window) {
        var cost = Number.POSITIVE_INFINITY;
        if (typeof window === 'undefined') {
            cost = computeOptimalPath(firstSequence, secondSequence, state);
        } else if (typeof window === 'number') {
            cost = computeOptimalPathWithWindow(firstSequence, secondSequence, window, state);
        } else {
            throw new TypeError('Invalid window parameter type: expected a number');
        }

        return cost;
    };

    this.path = function () {
        var path = null;
        if (state.distanceCostMatrix instanceof Array) {
            path = retrieveOptimalPath(state);
        }

        return path;
    };
}
function ( options ) { var state = { distanceCostMatrix : null } ; if ( typeof options === 'undefined' ) { state . distance = require ( './distanceFunctions/squaredEuclidean' ) . distance ; } else { validateOptions ( options ) ; if ( typeof options . distanceMetric === 'string' ) { state . distance = retrieveDistanceFunction ( options . distanceMetric ) ; } else if ( typeof options . distanceFunction === 'function' ) { state . distance = options . distanceFunction ; } } this . compute = function ( firstSequence , secondSequence , window ) { var cost = Number . POSITIVE_INFINITY ; if ( typeof window === 'undefined' ) { cost = computeOptimalPath ( firstSequence , secondSequence , state ) ; } else if ( typeof window === 'number' ) { cost = computeOptimalPathWithWindow ( firstSequence , secondSequence , window , state ) ; } else { throw new TypeError ( 'Invalid window parameter type: expected a number' ) ; } return cost ; } ; this . path = function ( ) { var path = null ; if ( state . distanceCostMatrix instanceof Array ) { path = retrieveOptimalPath ( state ) ; } return path ; } ; }
Create a DTW object
@class DTW
 
Initializes a new instance of the `DTW`. If no options are provided the squared euclidean distance function is used.
@function DTW
@param {DTWOptions} [options] The options to initialize the dynamic time warping instance with.
 
Computes the optimal match between two provided sequences.
@method compute
@param {number[]} firstSequence The first sequence.
@param {number[]} secondSequence The second sequence.
@param {number} [window] The window parameter (for the locality constraint) to use.
@returns {number} The similarity between the provided temporal sequences.
 
Retrieves the optimal match between two provided sequences.
@method path
@returns {number[]} The array containing the optimal path points.
Create a DTW object