-
Notifications
You must be signed in to change notification settings - Fork 2k
Multiclass SVM and DTW System.AggregateException #470
Description
Hi cesarouza,
I tried to use multiclass SVM with DTW with the following code but have the following error:
System.AggregateException: One or more errors occurred. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Accord.MachineLearning.VectorMachines.MulticlassSupportVectorMachine3.<>c__DisplayClass21_0.<distance>b__1(Int32 i, ParallelLoopState state, Tuple
3 partial)
at System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.b__1()
at System.Threading.Tasks.Task.InnerInvoke()
...
The code I used is given below. The data for the sequences is attached.
The data Shapes.csv contains (SequenceID,ClassID,ClassName,X,Y). There are only 3 classes (Circle, Triangle and Rectangle) with lots of sequences.
The code works fine when I have a few sequences. If I have this many sequences, I get that described error.
Do you know what is causing this?
double[][] inputs = new double[Sequences.Count][]; //X,Y values sequences from attached file.
int[] outputs = new int[Sequences.Count]; //Class 0,1,2
int dimension = 2;
int ClassCount = 3;
for (int i = 0; i < Sequences.Count; i++)
{
outputs[i] = Sequences[i].ClassID;
double[][] sequence = Preprocess(Sequences[i].ToArray());
inputs[i] = Matrix.Concatenate(sequence);
}
var gkernel = new DynamicTimeWarping(length: dimension);
svm = new MulticlassSupportVectorMachine <DynamicTimeWarping>(0, gkernel, ClassCount);
// Create the learning algorithm to teach the multiple class classifier
var teacher = new MulticlassSupportVectorLearning<DynamicTimeWarping>()
{
Learner = (param) => new SequentialMinimalOptimization<DynamicTimeWarping>()
{
Kernel = new DynamicTimeWarping(dimension),
}
};
this.svm = teacher.Learn(inputs, outputs);
int[] predicted = this.svm.Decide(inputs); //This one runs ok
try
{
for (int i = 0; i < Sequences.Count; i++)
{
double[][] sequence = Preprocess(Sequences[i].ToArray());
double[] seq = Matrix.Concatenate(sequence);
int outClass = this.svm.Decide(seq); //Error at this point here.
Console.WriteLine(outClass);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}