DynamicTimeWarping Structure (original) (raw)

| Accord.NET (logo) | | | --------------------------------------------------------------------- | |

Dynamic Time Warping Sequence Kernel.

Namespace: Accord.Statistics.Kernels
Assembly: Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0

Syntax

[SerializableAttribute] public struct DynamicTimeWarping : IKernel, IKernel<double[]>, IKernel<double[][]>, ICloneable, IDistance, IDistance<double[]>, IDistance<double[], double[]>, IDistance<double[][]>, IDistance<double[][], double[][]>

Public Structure DynamicTimeWarping Implements IKernel, IKernel(Of Double()), IKernel(Of Double()()), ICloneable, IDistance, IDistance(Of Double()), IDistance(Of Double(), Double()), IDistance(Of Double()()), IDistance(Of Double()(), Double()())

Request Example View Source

The DynamicTimeWarping type exposes the following members.

Constructors

Properties

| | Name | Description | | | -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | | Public property | Alpha | Gets or sets the hypersphere ratio. Default is 1. | | Public property | Degree | Gets or sets the polynomial degree for this kernel. Default is 1. | | Public property | Length | Gets or sets the length for the feature vectors contained in each sequence used by the kernel. |

Top

Methods

| | Name | Description | | | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | | Public method | Clone | Creates a new object that is a copy of the current instance. | | Public method | Distance(Double, Double) | Computes the squared distance in feature space between two points given in input space. | | Public method | Distance(Double, Double) | Computes the squared distance in feature space between two points given in input space. | | Public method | Equals | Indicates whether this instance and a specified object are equal. (Inherited from ValueType.) | | Public method | Function(Double, Double) | Dynamic Time Warping kernel function. | | Public method | Function(Double, Double) | Dynamic Time Warping kernel function. | | Public method | GetHashCode | Returns the hash code for this instance. (Inherited from ValueType.) | | Public method | GetType | Gets the Type of the current instance. (Inherited from Object.) | | Public method | ToString | Returns the fully qualified type name of this instance. (Inherited from ValueType.) |

Top

Extension Methods

| | Name | Description | | | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Public Extension Method | Distance | Computes the kernel distance for a kernel function even if it doesn't implement the IDistance interface. Can be used to check the proper implementation of the distance function. (Defined by Tools.) | | Public Extension Method | HasMethod | Checks whether an object implements a method with the given name. (Defined by ExtensionMethods.) | | Public Extension Method | IsEqual | Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices. (Defined by Matrix.) | | Public Extension Method | To(Type) | Overloaded. Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime. (Defined by ExtensionMethods.) | | Public Extension Method | ToT | Overloaded. Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime. (Defined by ExtensionMethods.) |

Top

Remarks

The Dynamic Time Warping Sequence Kernel is a sequence kernel, accepting vector sequences of variable size as input. Despite the sequences being variable in size, the vectors contained in such sequences should have its size fixed and should be informed at the construction of this kernel.

The conversion of the DTW global distance to a dot product uses a combination of a technique known as spherical normalization and the polynomial kernel. The degree of the polynomial kernel and the alpha for the spherical normalization should be given at the construction of the kernel. For more information, please see the referenced papers shown below.

The use of a cache is highly advisable when using this kernel.

Examples

The following example demonstrates how to create and learn a Support Vector Machine (SVM) to recognize sequences of univariate observations using the Dynamic Time Warping kernel.

double[][] inputs = {

new double[] { 0,1,1,0 },
new double[] { 0,0,1,0 },
new double[] { 0,1,1,1,0 },
new double[] { 0,1,0 },    


new double[] { 1,0,0,1 },
new double[] { 1,1,0,1 },
new double[] { 1,0,0,0,1 },
new double[] { 1,0,1 },
new double[] { 1,0,0,0,1,1 }

};

int[] outputs = { 0, 0, 0, 0,
1, 1, 1, 1, 1 };

var smo = new SequentialMinimalOptimization() { Complexity = 1.5,

Kernel = new DynamicTimeWarping(alpha: 1, degree: 1)

};

var svm = smo.Learn(inputs, outputs);

bool[] predicted = svm.Decide(inputs);

double error = new ZeroOneLoss(outputs).Loss(predicted);

Now, instead of having univariate observations, the following example demonstrates how to create and learn a sequences of multivariate (or n-dimensional) observations.

double[][][] sequences = { new double[][] { new double[] { 1, 1, 1 }, new double[] { 1, 2, 1 }, new double[] { 1, 4, 2 }, new double[] { 2, 2, 2 }, },

new double[][] 
{
    new double[] { 1, 1, 1 }, 
    new double[] { 1, 5, 6 }, 
    new double[] { 2, 7, 1 }, 
},

new double[][] 
{
    new double[] { 8, 2, 1 }, 
},

new double[][] 
{
    new double[] { 8, 2, 5 }, 
    new double[] { 1, 5, 4 }, 
}

};

int[] outputs = { 0, 0,
1, 1,
};

var smo = new SequentialMinimalOptimization<DynamicTimeWarping, double[][]>() { Complexity = 1.5,

Kernel = new DynamicTimeWarping(alpha: 1, degree: 1)

};

var svm = smo.Learn(sequences, outputs);

bool[] predicted = svm.Decide(sequences);

double error = new ZeroOneLoss(outputs).Loss(predicted);

double[][] a = { new double[] { 1, 1, 1 }, new double[] { 7, 2, 5 }, new double[] { 2, 5, 1 }, };

double[][] b = { new double[] { 8, 5, 2 }, new double[] { 4, 2, 5 }, };

bool resultA = svm.Decide(a); bool resultB = svm.Decide(b);

See Also

Reference