divyang4481 / accord

Automatically exported from code.google.com/p/accord
0 stars 0 forks source link

MulticlassSupportVectorMachine.createCache throws NullReferenceException in multithreaded environment #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

I'm using Accord.NET framework to recognize some patterns using 
MulticlassSupportVectorMachine class.

Here is my code:

Parallel.For(0, list.Length, i =>
            {

                // .. load some stuff ..
                // here we get a NullReferenceException inside createCache() method.
                int num = SupportVectorMachine.Compute(data, config.ComputeMethod, out responses);

                if (!SupportVectorMachine.IsProbabilistic)
                {
                    // Normalize responses
                    double max = responses.Max();
                    double min = responses.Min();

                    responses = Accord.Math.Tools.Scale(min, max, 0, 1, responses);
                }
                // .. do something ..
                }
            });

If I run this Parallel.For loop in a normal way (e.g using for or foreach), the 
methods runs fine.

Can anyone help me, please?

Original issue reported on code.google.com by cirelli....@gmail.com on 22 Oct 2012 at 7:49

GoogleCodeExporter commented 9 years ago
First of all, many thanks for reporting the issue. However, I have not been 
able to reproduce the issue yet. What is the value of config.ComputeMethod 
variable, and what else are you loading previous to computing the decision? How 
are you learning the machines?

Original comment by cesarso...@gmail.com on 2 Nov 2012 at 2:53

GoogleCodeExporter commented 9 years ago
The ComputeMethod is set to 0 (Voting).
The data Im loading is a double[] which contains a serialized finger's gesture 
in a touch screen (Im tring to recognize some gestures). This serialized data 
is something like this:
[P1.x, P1.y, P1.speedx, P1.speedy, P1.acceleration, P1.time, P2.x, P2.y ...]
Where P1, P2, etc, are touch points.
Do, I load variable "data" with this double[] and initialized an empty double 
array for the "responses" variable. Its pretty much the same you have provided 
with the SVM Handwritting recognition sample, but Im using a serialized 
finger's gesture instead of a serialized binary image.

Im learning the machines with some touch gestures I record from an application 
I've built. It just detects touch points data (x, y, speed, accel, etc), 
serializes this stuff and creates the machine.

Here is my code for learning:

public static MulticlassSupportVectorMachine CreateAndTrain(
            IKernel kernel, double[][] input, int[] output, 
            int inputs, int classes, SelectionStrategy strategy, 
            double complexity, double tolerance, int cacheSize, out double error)
        {
            // Create the Multi-class Support Vector Machine using the selected Kernel
            MulticlassSupportVectorMachine ksvm = new MulticlassSupportVectorMachine(inputs, kernel, classes);

            // Create the learning algorithm using the machine and the training data
            MulticlassSupportVectorLearning ml = new MulticlassSupportVectorLearning(ksvm, input, output);

            // Configure the learning algorithm
            ml.Algorithm = (svm, classInputs, classOutputs, i, j) =>
            {
                var smo = new SequentialMinimalOptimization(svm, classInputs, classOutputs);
                smo.Complexity = complexity;
                smo.Tolerance = tolerance;
                smo.CacheSize = cacheSize;
                smo.Strategy = strategy;
                if (kernel is Linear) smo.Compact = true;
                return smo;
            };

            // Executes the training algorithm
            error = ml.Run();
            return ksvm;
        }

Im using a Gaussian Kernel, Voting compute method, Sequential Selection 
Strategy..
Do you need more information?

I can provide you a video where I learn the machine. If you would like, please, 
send me an e-mail. Im from Brazil, if you are a portuguese-speaker, it would 
help our communication.

Thanks a lot for this great framework.

Original comment by cirelli....@gmail.com on 5 Nov 2012 at 4:47

GoogleCodeExporter commented 9 years ago
Fixed on Accord.NET 2.8.

Original comment by cesarso...@gmail.com on 6 Nov 2012 at 5:23