DynamicTimeWarping Structure (original) (raw)
|
| |
| --------------------------------------------------------------------- | |
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()())The DynamicTimeWarping type exposes the following members.
Constructors
Properties
| | Name | Description | |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
| Alpha | Gets or sets the hypersphere ratio. Default is 1. |
|
| Degree | Gets or sets the polynomial degree for this kernel. Default is 1. |
|
| Length | Gets or sets the length for the feature vectors contained in each sequence used by the kernel. |
Methods
| | Name | Description | |
| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
|
| Clone | Creates a new object that is a copy of the current instance. |
|
| Distance(Double, Double) | Computes the squared distance in feature space between two points given in input space. |
|
| Distance(Double, Double) | Computes the squared distance in feature space between two points given in input space. |
|
| Equals | Indicates whether this instance and a specified object are equal. (Inherited from ValueType.) |
|
| Function(Double, Double) | Dynamic Time Warping kernel function. |
|
| Function(Double, Double) | Dynamic Time Warping kernel function. |
|
| GetHashCode | Returns the hash code for this instance. (Inherited from ValueType.) |
|
| GetType | Gets the Type of the current instance. (Inherited from Object.) |
|
| ToString | Returns the fully qualified type name of this instance. (Inherited from ValueType.) |
Extension Methods
| | Name | Description | |
| ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 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.) |
|
| HasMethod | Checks whether an object implements a method with the given name. (Defined by ExtensionMethods.) |
|
| IsEqual | Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices. (Defined by Matrix.) |
|
| 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.) |
|
| 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.) |
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.
- V. Wan, J. Carmichael; Polynomial Dynamic Time Warping Kernel Support Vector Machines for Dysarthric Speech Recognition with Sparse Training Data. Interspeech'2005 - Eurospeech - 9th European Conference on Speech Communication and Technology. Lisboa, 2005.
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