//numeroDimensiones: integer value, 95 as the number of principal components
//numeroClases: integer value, 10, as the number of classes in the database [0-9]
public override void CrossValidation(double[][] inputs, int[] outputs, out CrossValidationStatistics trainingErrors, out CrossValidationStatistics validationErrors){ var crossvalidation = new CrossValidation<MulticlassSupportVectorMachine>(size: inputs.Length, folds: 10); crossvalidation.Fitting = (index, indicesTrain, indicesValidation) => { double trainingError = 0, validationError = 0;
// Lets now grab the training data: double[][] trainingInputs = inputs.Submatrix(indicesTrain); int[] trainingOutputs = outputs.Submatrix(indicesTrain);
// And now the validation data: double[][] validationInputs = inputs.Submatrix(indicesValidation); int[] validationOutputs = outputs.Submatrix(indicesValidation);
// Create a new kernel IKernel kernel = Gaussian.Estimate(trainingInputs);
// Complexity //var complexity = SequentialMinimalOptimization.EstimateComplexity(kernel, trainingInputs);
// Create a new Multi-class Support Vector Machine var model = new MulticlassSupportVectorMachine(numeroDimensiones, kernel, numeroClases);
// Create the Multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning(model, trainingInputs, trainingOutputs);
// Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. teacher.Algorithm = (svm, classInputs, classOutputs, i, j) => new SequentialMinimalOptimization(svm, classInputs, classOutputs);
// Run the learning algorithm trainingError = teacher.Run();
// Get the validation errors validationError = teacher.ComputeError(validationInputs, validationOutputs);
// Return a new information structure containing the model and the errors achieved. return new CrossValidationValues<MulticlassSupportVectorMachine>(model, trainingError, validationError); };
// Compute the cross-validation var result = crossvalidation.Compute(); result.Save(SVMResultsFile);
// Finally, access the measured performance. result.Training.Tag = "Training results"; result.Validation.Tag = "Validation results"; trainingErrors = result.Training; validationErrors = result.Validation;
var minIndex = result.Validation.Values.Find(v => v == result.Training.Values.Min()).FirstOrDefault(); var minModelValues = result.Models[minIndex]; this.model = minModelValues.Model;}
public static int[] RandomGroups(int[] labels, int classes, int groups)
{
int size = labels.Length;
var buckets = new List<Tuple<int, int>>[classes];
for (int i = 0; i < buckets.Length; i++)
buckets[i] = new List<Tuple<int, int>>();
for (int i = 0; i < labels.Length; i++)
buckets[labels[i]].Add(Tuple.Create(i, labels[i]));
for (int i = 0; i < buckets.Length; i++)
Accord.Statistics.Tools.Shuffle(buckets);
var partitions = new List<Tuple<int, int>>[groups];
for (int i = 0; i < partitions.Length; i++)
partitions[i] = new List<Tuple<int, int>>();
// We are going to take samples from the buckets and assign to
// groups. For this, we will be following the buckets in order,
// such that new samples are drawn equally from each bucket.
bool allEmpty = true;
int bucketIndex = 0;
int partitionIndex = 0;
do
{
for (int i = 0; i < partitions.Length; i++)
{
allEmpty = true;
var currentPartition = partitions[partitionIndex];
partitionIndex = (partitionIndex + 1) % partitions.Length;
for (int j = 0; j < buckets.Length; j++)
{
var currentBucket = buckets[bucketIndex];
bucketIndex = (bucketIndex + 1) % buckets.Length;
if (currentBucket.Count == 0)
continue;
allEmpty = false;
var next = currentBucket[currentBucket.Count - 1];
currentBucket.RemoveAt(currentBucket.Count - 1);
currentPartition.Add(next);
}
}
} while (!allEmpty);
for (int i = 0; i < partitions.Length; i++)
Accord.Statistics.Tools.Shuffle(partitions[i]);
int[] splittings = new int[labels.Length];
for (int i = 0; i < partitions.Length; i++)
foreach (var index in partitions[i])
splittings[index.Item1] = i;
return splittings;
}
Thank you also for confirming some of my doubts and even answering to other questions i had. In fact, my problem for now is quite simpler: get more Data ;)
Was simply "messing" around with the cross validation to start to see some actual numbers and kinda forgot that the amount of data could be an issue (like we just verified). At least this way we conclude the obvious thing -> need more samples.
Also thought that probably it would be the best to expose minimally my problem.
I am trying to recognize hand movements (as in sign language) with the actual position of both hands. Firstly i was using an MultiClass SVM and a simple HMM to classify the movements. I was using the 6 dimensions (3 for each hand) and realized that this could be an issue so was thinking in using a machine for each hand... Is this feasible? I mean, i can obviously classify each hand separately... but i can't see how i could correlate the results after. I say this cause in some cases, using the 6 dimensions was costly for the teaching process...
But for now, my main problem is to fix something i thought it was correct... that has nothing to do with machine learning, which is the depth Data from my hands needs to be normalized, so i can compare movements done 1m for the sensor or 2m or 3m.
So, ill keep up working on this issues, and ill let you know about the answers you provided :D
Lastly, a minor fix because i couldn't compile your function (RandomGroups) because of this line...
for (int i = 0; i < partitions.Length; i++)
Accord.Statistics.Tools.Shuffle(partitions[i]);
adding the .ToArray() method fixed it ;) :
Accord.Statistics.Tools.Shuffle.ToArray()(partitions[i]);
PS: how can i edit my message like you are doing? putting the code like that and bold, italic and other stuff? can't find a way to do that :(
By simply reading the title of your article i realized those words describe precisely my thesis --' . "Going from Fingerspelling to Natural Articulated Words"
Almeida did exactly the part of the FingerSpelling for Portuguese Sign Language and I'm continuing his work to achieve the Natural Articulated Word (with the hand postures merged with the hand movement).
I just feel i should've talked to you like 2 months ago --'
PS: I wasn't able to find your contact, in order to not extend our talk in this topic, cause it is becoming a little off topic...