public void DynamicalTimeWarpingConstructorTest2()
{
// Declare some testing data
double[][] inputs =
{
// Class -1
new double[] { 0,1,1,0 },
new double[] { 0,0,1,0 },
new double[] { 0,1,1,1,0 },
new double[] { 0,1,0 },
// Class +1
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 =
{
-1,-1,-1,-1, // First four sequences are of class -1
1, 1, 1, 1, 1 // Last five sequences are of class +1
};
// Set the parameters of the kernel
double alpha = 1.0;
int degree = 1;
int innerVectorLength = 1;
// Create the kernel. Note that the input vector will be given out automatically
DynamicTimeWarping target = new DynamicTimeWarping(innerVectorLength, alpha, degree);
// When using variable-length kernels, specify 0 as the input length.
KernelSupportVectorMachine svm = new KernelSupportVectorMachine(target, 0);
// Create the Sequential Minimal Optimization as usual
SequentialMinimalOptimization smo = new SequentialMinimalOptimization(svm, inputs, outputs);
smo.Complexity = 1.5;
double error = smo.Run();
// Check if the model has learnt the sequences correctly.
for (int i = 0; i < inputs.Length; i++)
{
int expected = outputs[i];
int actual = System.Math.Sign(svm.Compute(inputs[i]));
Assert.AreEqual(expected, actual);
}
// Testing new sequences
Assert.AreEqual(-1,System.Math.Sign(svm.Compute(new double[] { 0, 1, 1, 0, 0 })));
Assert.AreEqual(+1,System.Math.Sign(svm.Compute(new double[] { 1, 1, 0, 0, 1, 1 })));
}