Beispiel #1
0
        private static void Train(string prefix)
        {
            SVMProblem trainingSet = SVMProblemHelper.Load(MnistDataPath + prefix + ".txt");

            trainingSet = trainingSet.Normalize(SVMNormType.L2);

            SVMParameter parameter = new SVMParameter();

            parameter.Type   = SVMType.C_SVC;
            parameter.Kernel = SVMKernelType.RBF;
            parameter.C      = 1;
            parameter.Gamma  = 1;

            double[] crossValidationResults;
            int      nFold = 5;

            trainingSet.CrossValidation(parameter, nFold, out crossValidationResults);
            double crossValidationAccuracy = trainingSet.EvaluateClassificationProblem(crossValidationResults);

            Console.WriteLine("\n\nCross validation accuracy: " + crossValidationAccuracy);

            SVMModel model = trainingSet.Train(parameter);

            SVM.SaveModel(model, MnistDataPath + "model.txt");
            Console.WriteLine("\n\nModel ok!");
        }
Beispiel #2
0
        // for training the face,
        public void face_training(SVMProblem f_training)
        {
            SVMProblem trainingSet = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\0921_towp.txt");
            SVMProblem testSet     = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\0921_towpt.txt");

            trainingSet = trainingSet.Normalize(SVMNormType.L2);
            testSet     = testSet.Normalize(SVMNormType.L2);

            SVMParameter parameter = new SVMParameter();

            parameter.Type        = SVMType.NU_SVC;
            parameter.Kernel      = SVMKernelType.SIGMOID;
            parameter.C           = 1;
            parameter.Gamma       = 1;
            parameter.Probability = true;
            double[] crossValidationResults;
            int      nFold = 10;

            trainingSet.CrossValidation(parameter, nFold, out crossValidationResults);
            double   crossValidationAccuracy = trainingSet.EvaluateClassificationProblem(crossValidationResults);
            SVMModel model = trainingSet.Train(parameter);


            double[] testResults = testSet.Predict(model);
            int[,] confusionMatrix;
            double testAccuracy = testSet.EvaluateClassificationProblem(testResults, model.Labels, out confusionMatrix);

            Training_result.Content    = "testAccuracy:" + testAccuracy + "\nCross validation accuracy: " + crossValidationAccuracy + "\nCount " + trainingSet.Y.Count;
            Training_result.FontSize   = 14;
            Training_result.FontStyle  = FontStyles.Normal;
            Training_result.Foreground = Brushes.Red;
            Training_result.Background = Brushes.Black;
            index++;
        }
        public void face_training(SVMProblem f_training)
        {
            SVMProblem trainingSet = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\0921_towp.txt");
            SVMProblem testSet     = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\0921_towpt.txt");

            // f_training.Save(@"C:\Users\temp\Desktop\1005f.txt");
            //  trainingSet.Insert(index, f_training.X[0], 2);
            trainingSet.Add(f_training.X[0], 1);
            trainingSet.Save(@"C:\Users\temp\Desktop\flag.txt");
            //   trainingSet.Save(@"C:\Users\temp\Desktop\1005.txt");
            // Console.WriteLine();
            //   SVMNode node = new SVMNode();
            //  node.Index = Convert.ToInt32(o);
            //  node.Value = Convert.ToDouble(f_training.X);
            //  nodes.Add(node);
            //  trainingSet.Add(nodes.ToArray(), 1);
            //  int number = randon.Next(0, trainingSet.X.Count);
            //  int trainingsample = Convert.ToInt32(trainingSet.X.Count * 2 / 3);
            //  int testingsample = Convert.ToInt32(trainingSet.X.Count / 3);

            trainingSet = trainingSet.Normalize(SVMNormType.L2);
            testSet     = testSet.Normalize(SVMNormType.L2);

            SVMParameter parameter = new SVMParameter();

            parameter.Type        = SVMType.NU_SVC;
            parameter.Kernel      = SVMKernelType.SIGMOID;
            parameter.C           = 1;
            parameter.Gamma       = 1;
            parameter.Probability = true;
            int        nFold = 10;
            MainWindow main  = new MainWindow();

            double[] crossValidationResults; // output labels
            trainingSet.CrossValidation(parameter, nFold, out crossValidationResults);
            double   crossValidationAccuracy = trainingSet.EvaluateClassificationProblem(crossValidationResults);
            SVMModel model = SVM.Train(trainingSet, parameter);

            // SVMModel model = trainingSet.Train(parameter);

            SVM.SaveModel(model, @"C:\Users\temp\Desktop\1005.txt");

            double[] testResults = testSet.Predict(model);
            //     Console.WriteLine("");
            int[,] confusionMatrix;
            double testAccuracy = testSet.EvaluateClassificationProblem(testResults, model.Labels, out confusionMatrix);

            // Console.WriteLine("\n\nCross validation accuracy: " + crossValidationAccuracy);
            //  Console.WriteLine("testAccuracy:" + testAccuracy);
            //  Console.WriteLine(Convert.ToString(trainingSet.X.Count));
            main.Training_result.Content    = "testAccuracy:" + testAccuracy + "\nCross validation accuracy: " + crossValidationAccuracy + "\nCount " + trainingSet.X.Count;
            main.Training_result.FontSize   = 14;
            main.Training_result.FontStyle  = FontStyles.Normal;
            main.Training_result.Foreground = Brushes.Red;
            main.Training_result.Background = Brushes.Black;
            // Console.WriteLine(trainingSet1.Length);
            //  trainingSet.Save(@"C:\Users\temp\Desktop\1005.txt");
            index++;
        }
Beispiel #4
0
        private static void TestOne(string prefix)
        {
            SVMModel   model   = SVM.LoadModel(MnistDataPath + "model.txt");
            SVMProblem testSet = SVMProblemHelper.Load(MnistDataPath + prefix + ".txt");

            testSet = testSet.Normalize(SVMNormType.L2);
            double[] testResults = testSet.Predict(model);
            Console.WriteLine("\nTest result: " + testResults[0].ToString());
        }
Beispiel #5
0
        private static void Test(string prefix)
        {
            SVMModel   model   = SVM.LoadModel(MnistDataPath + "model.txt");
            SVMProblem testSet = SVMProblemHelper.Load(MnistDataPath + prefix + ".txt");

            testSet = testSet.Normalize(SVMNormType.L2);
            double[] testResults = testSet.Predict(model);
            int[,] confusionMatrix;
            double testAccuracy = testSet.EvaluateClassificationProblem(testResults, model.Labels, out confusionMatrix);

            Console.WriteLine("\nTest accuracy: " + testAccuracy);
        }
Beispiel #6
0
        //인식 하기
        public static int SVM_Classification(SVMModel md)
        {
            int result = 0;

            SVMProblem testSet = SVMProblemHelper.Load("tmp.txt");    //인식데이터셋 열기

            testSet = testSet.Normalize(SVMNormType.L2);
            double[] testResults = testSet.Predict(md);

            result = (int)testResults[0];

            return(result);
        }
Beispiel #7
0
        //학습모델 생성
        public static SVMModel SVM_GenModel(String dataset)
        {
            SVMProblem trainingSet = SVMProblemHelper.Load(dataset); //학습데이터셋 열기

            trainingSet = trainingSet.Normalize(SVMNormType.L2);

            SVMParameter parameter = new SVMParameter();

            parameter.Type   = SVMType.C_SVC;
            parameter.Kernel = SVMKernelType.RBF;
            parameter.C      = 1;
            parameter.Gamma  = 1;

            double[] crossValidationResults;
            int      nFold = 5;

            trainingSet.CrossValidation(parameter, nFold, out crossValidationResults);
            double crossValidationAccuracy = trainingSet.EvaluateClassificationProblem(crossValidationResults);

            SVMModel model = trainingSet.Train(parameter);  // 학습된 모델 생성

            SVM.SaveModel(model, "model_" + dataset);       // 모델 저장
            return(model);
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            // Load the datasets: In this example I use the same datasets for training and testing which is not suggested
            SVMProblem trainingSet = SVMProblemHelper.Load(@"Dataset\wine.txt");
            SVMProblem testSet     = SVMProblemHelper.Load(@"Dataset\wine2.txt");

            // Normalize the datasets if you want: L2 Norm => x / ||x||
            trainingSet = trainingSet.Normalize(SVMNormType.L2);
            testSet     = testSet.Normalize(SVMNormType.L2);

            // Select the parameter set
            SVMParameter parameter = new SVMParameter();

            parameter.Type   = SVMType.C_SVC;
            parameter.Kernel = SVMKernelType.RBF;
            parameter.C      = 1;
            parameter.Gamma  = 1;

            // Do cross validation to check this parameter set is correct for the dataset or not
            double[] crossValidationResults; // output labels
            int      nFold = 5;

            trainingSet.CrossValidation(parameter, nFold, out crossValidationResults);

            // Evaluate the cross validation result
            // If it is not good enough, select the parameter set again
            double crossValidationAccuracy = trainingSet.EvaluateClassificationProblem(crossValidationResults);

            // Train the model, If your parameter set gives good result on cross validation
            SVMModel model = trainingSet.Train(parameter);

            // Save the model
            SVM.SaveModel(model, @"Model\wine_model.txt");

            // Predict the instances in the test set
            double[] testResults = testSet.Predict(model);

            Console.WriteLine("aaa:" + testResults[0] + "\n");

            /*
             * // Evaluate the test results
             * int[,] confusionMatrix;
             * double testAccuracy = testSet.EvaluateClassificationProblem(testResults, model.Labels, out confusionMatrix);
             *
             *
             *
             *
             * // Print the resutls
             * Console.WriteLine("\n\nCross validation accuracy: " + crossValidationAccuracy);
             * Console.WriteLine("\nTest accuracy: " + testAccuracy);
             * Console.WriteLine("\nConfusion matrix:\n");
             *
             * // Print formatted confusion matrix
             * Console.Write(String.Format("{0,6}", ""));
             * for (int i = 0; i < model.Labels.Length; i++)
             *  Console.Write(String.Format("{0,5}", "(" + model.Labels[i] + ")"));
             * Console.WriteLine();
             * for (int i = 0; i < confusionMatrix.GetLength(0); i++)
             * {
             *  Console.Write(String.Format("{0,5}", "(" + model.Labels[i] + ")"));
             *  for (int j = 0; j < confusionMatrix.GetLength(1); j++)
             *      Console.Write(String.Format("{0,5}", confusionMatrix[i,j]));
             *  Console.WriteLine();
             * }
             *
             * Console.WriteLine("\n\nPress any key to quit...");
             * Console.ReadLine();*/
        }
Beispiel #9
0
        public int SVM_face_recognition()
        {
            SVMProblem face_data = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\Face_feature.txt");

            face_data = face_data.Normalize(SVMNormType.L2);


            //using Libsvm package which has api to calculate the probabilty
            face_data.PredictProbability(face_recognition_model, out prolist);

            var ok = prolist.ToArray();
            var v  = ok[0];
            // we have 13 person

            int    maxconfidenceindex = 0;
            double maxconfidence      = v[maxconfidenceindex];
            double threshold          = 0.25;

            for (int i = 0; i < v.Count(); i++)
            {
                if (v[i] > maxconfidence)
                {
                    maxconfidenceindex = i;
                    maxconfidence      = v[i];
                }
            }
            if (threshold < maxconfidence)
            {
                f1 = v[0];
                f2 = v[1];
                f3 = v[2];
                f4 = v[3];
                f5 = v[4];

                /*
                 *    f6 = v[5];
                 *    f7 = v[6];
                 *    f8 = v[7];
                 *    f9 = v[8];
                 *    f10 = v[9];
                 *    f11 = v[10];
                 *    f12 = v[11];
                 *    f13 = v[12];
                 */
                double[] faceresult = face_data.Predict(face_recognition_model);
                facename = Convert.ToInt16(faceresult[0]);
                //  facename =facemodel.Labels[maxconfidenceindex];
                faceshow++;
            }

            int labelnum = face_recognition_model.Labels[maxconfidenceindex];

            if (threshold > maxconfidence)
            {
                // Console.WriteLine("Unknow");
                facename        = 0;
                display.Content = "Unknow";
                facefail++;
            }



            return(facename);
        }
Beispiel #10
0
        // activity classification
        public void SVM_Classification()
        {
            testSet1 = SVMProblemHelper.Load(@"Dataset\ADLfall_test1.txt");

            testSet1 = testSet1.Normalize(SVMNormType.L2);

            float sum;

            if (testSet1.Length != 0)
            {
                try
                {
                    //var resut = model.Predict(testSet1.X[testSet1.Length - 1]);
                    //  p = Convert.ToInt16(resut);
                    //predict the result using model, return result
                    var result = testSet1.Predict(activity_model);
                    p = Convert.ToInt16(result[0]);
                    //put the result into enqueue
                    myq.Enqueue(p);

                    switch (p)
                    {
                    case 1:
                        q++;

                        break;

                    case 2:
                        w++;

                        break;

                    case 3:
                        e++;

                        break;

                    case 4:
                        r++;

                        break;
                    }
                }
                catch
                {
                }
                // if the collected data is larger than 30
                if (myq.Count > 30)
                {
                    //  dequeue the old one
                    myq.TryDequeue(out p);
                    switch (p)
                    {
                    case 1:
                        q--;

                        break;

                    case 2:
                        w--;

                        break;

                    case 3:
                        e--;

                        break;

                    case 4:
                        r--;

                        break;
                    }
                    // proportional
                    sum = q + w + e + r;

                    //   activity.Content = ("Sit down:" + sit_down + "\n" + "Walking" + walkig + "\n" + "Standing" + standing + "\n" + "Fall event" + fallevent);
                    activity.Content = ("Sit down: " + Math.Round(e / sum, 2) * 100 + "%" + "\n" + "Walking: " + Math.Round(q / sum, 2) * 100 + "%" + "\n" + "Standing: " + Math.Round(w / sum, 2) * 100 + "%" + "\n" + "Fall event: " + Math.Round(r / sum, 2) * 100 + "%");
                    //  activity.Content = ("Sit down:" + Math.Round(h / sum, 2) + "\n" + "Walking" + Math.Round(w / sum, 2) + "\n" + "Standing" + Math.Round(q / sum, 2) + "\n" + "Fall event" + Math.Round(r / sum, 2));
                    if (e / sum > 0.5)
                    {
                        label.Content = ("You have sit down"); label.Foreground = Brushes.Red;
                    }
                    else if (q / sum > 0.5)
                    {
                        label.Content = "You are walking"; label.Foreground = Brushes.Red;
                    }
                    else if (w / sum > 0.5)
                    {
                        label.Content = "You are standing"; label.Foreground = Brushes.Red;
                    }
                    else if (r / sum > 0.5)
                    {
                        label.Content = "You fell down"; label.Foreground = Brushes.Red;
                    }

                    activity.FontSize   = 20;
                    activity.FontStyle  = FontStyles.Normal;
                    activity.Foreground = Brushes.Red;
                    activity.Background = Brushes.Black;
                }
            }
        }
Beispiel #11
0
        static void wordsSvm()
        {//http://www.svm-tutorial.com/2014/10/svm-tutorial-classify-text-csharp/
            var index   = 11;
            var rooms11 = File.ReadAllText(string.Format("../../room{0}.txt", index));
            var rooms22 = File.ReadAllText(string.Format("../../room{0}.txt", ++index));

            var rooms1 = rooms11.Split(';');
            var rooms2 = rooms22.Split(';');

            var termFreqWeight = new PanGuTermFreqWeight();

            termFreqWeight.computerFW(rooms1, rooms2);

            var problem = new SVMProblem(); //SVM.SetPrintStringFunction(mySVMPrintFunction);

            var lableFeaturesBuilder = new LableFeaturesBuilder();
            var segment = new PanGuSegment();

            foreach (var room in rooms2)
            {
                var words = termFreqWeight.TermsByDoc[1, room];
                words = words.Where(t => t.Length > 1 && termFreqWeight.TermFWByGlobal.ContainsKey(t) && termFreqWeight.TermFWByType.ContainsKey(0, t)).ToArray();
                //lableFeaturesBuilder.AddToProblem(problem, room, words.Select(t => new KeyValuePair<string, double>(t,termFreqWeight.TermFWByDoc[1, room, t].Freq*GetW(t))));
                lableFeaturesBuilder.AddToProblem(problem, room, words.Select(t => new KeyValuePair <string, double>(t, Math.Max(termFreqWeight.TermFWByType[0, t].Freq, termFreqWeight.TermFWByType[1, t].Freq))));
            }

            SVMParameter parameter = new SVMParameter();

            parameter.Type        = SVMType.C_SVC;
            parameter.Kernel      = SVMKernelType.LINEAR;
            parameter.C           = 1;
            parameter.Probability = true;
            //parameter.
            //parameter.WeightLabels = lableFeaturesBuilder.CreateWeightFeatures("大", "双", "套", "大床", "双床").ToArray();
            //parameter.Weights = new double[] { 1.90, 1.90, 1.90, 1.99, 1.99 };

            //parameter.WeightLabels = lableFeaturesBuilder.CreateWeightLables<int>("行政湖景双床房").ToArray();
            //parameter.Weights = new double[] { 1.90, 1.90, 1.90, 1.99, 1.99 };

            problem = problem.Normalize(SVMNormType.L1);
            problem.CheckParameter(parameter);

            var model2 = LibSVMsharp.SVM.Train(problem, parameter);

            model2.SaveModel("roomMatching.model");

            var model = LibSVMsharp.SVM.LoadModel("roomMatching.model");

            foreach (var room in rooms1)
            {
                var words = termFreqWeight.TermsByDoc[0, room];
                words = words.Where(t => t.Length > 1 && termFreqWeight.TermFWByGlobal.ContainsKey(t) && termFreqWeight.TermFWByType.ContainsKey(1, t)).ToArray();

                //var nodes = lableFeaturesBuilder.CreateNodes(words.Select(t => new KeyValuePair<string, double>(t, termFreqWeight.TermFWByDoc[0, room, t].Freq * GetW(t))));
                var nodes = lableFeaturesBuilder.CreateNodes(words.Select(t => new KeyValuePair <string, double>(t, Math.Max(termFreqWeight.TermFWByType[0, t].Freq, termFreqWeight.TermFWByType[1, t].Freq))));
                if (nodes.Length > 0)
                {
                    nodes = nodes.Normalize(SVMNormType.L1);

                    double predictedY = 0;
                    predictedY = LibSVMsharp.SVM.Predict(model, nodes);

                    double[] values = null; double probabilityValue = 0;
                    probabilityValue = LibSVMsharp.SVM.PredictValues(model, nodes, out values);

                    double[] est = null; double probability = 0;
                    probability = LibSVMsharp.SVM.PredictProbability(model, nodes, out est);

                    Console.WriteLine("{0,22}\t{1},{2},{3},{4},{5}", room, lableFeaturesBuilder.GetLable(predictedY), predictedY, probabilityValue, probability, string.Empty);
                }
            }

            Console.WriteLine(new string('=', 80));
        }
        static void Main(string[] args)
        {
            // Load the datasets: In this example I use the same datasets for training and testing which is not suggested
            SVMProblem trainingSet = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\ADLfall_train.txt");
            //    SVMProblem testSet = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\ADLfall_test.txt");
            SVMProblem testSet1 = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\ADLfall_test1.txt");

            // SVMProblem testSet1 = SVMProblemHelper.Load(@"C:\Users\temp\Desktop\result.txt");

            // Normalize the datasets if you want: L2 Norm => x / ||x||
            trainingSet = trainingSet.Normalize(SVMNormType.L2);
            //   testSet = testSet.Normalize(SVMNormType.L2);
            testSet1 = testSet1.Normalize(SVMNormType.L2);
            // Select the parameter set

            SVMParameter parameter = new SVMParameter();

            parameter.Type   = SVMType.C_SVC;
            parameter.Kernel = SVMKernelType.RBF;
            parameter.C      = 32768.0;
            parameter.Gamma  = 8.0;


            // Do cross validation to check this parameter set is correct for the dataset or not
            double[] crossValidationResults; // output labels
            int      nFold = 5;
            //  trainingSet1.CrossValidation(parameter, nFold, out crossValidationResults);

            // Evaluate the cross validation result
            // If it is not good enough, select the parameter set again
            //  double crossValidationAccuracy = trainingSet.EvaluateClassificationProblem(crossValidationResults);

            // Train the model, If your parameter set gives good result on cross validation
            //   SVMModel model = trainingSet.Train(parameter);


            // Save the model
            //   SVM.SaveModel(model, @"Model\activity_recognition.txt");
            SVMModel model = SVM.LoadModel(@"Model\activity_recognition.txt");

            int    p, q, w, e, r, ok = 0;
            double sum;

            q = 0;
            w = 0;
            e = 0;
            r = 0;
            // Predict the instances in the test set
            double[] testResults = testSet1.Predict(model);

            while (ok < testSet1.Length)
            {
                var resut = model.Predict(testSet1.X[ok]);
                //    Console.WriteLine("resut111:" + resut);
                p = Convert.ToInt16(resut);
                switch (p)

                {
                case 1:
                    q++;
                    break;

                case 2:
                    w++;
                    break;

                case 3:
                    e++;
                    break;

                case 4:
                    r++;
                    break;
                }

                ok++;
            }
            sum = q + w + e + r;


            Console.WriteLine("result:" + Math.Round(q / sum, 2) + "," + Math.Round(w / sum, 2) + "," + Math.Round(e / sum, 2) + "," + Math.Round(r / sum, 2));
            // Evaluate the test results

            int[,] confusionMatrix;
            double testAccuracy = testSet1.EvaluateClassificationProblem(testResults, model.Labels, out confusionMatrix);

            // Print the resutls
            //  Console.WriteLine("\n\nCross validation accuracy: " + crossValidationAccuracy);
            Console.WriteLine("\nTest accuracy: " + testAccuracy);
            Console.WriteLine("\nConfusion matrix:\n");

            // Print formatted confusion matrix
            Console.Write(String.Format("{0,6}", ""));
            for (int i = 0; i < model.Labels.Length; i++)
            {
                Console.Write(String.Format("{0,5}", "(" + model.Labels[i] + ")"));
            }
            Console.WriteLine();
            for (int i = 0; i < confusionMatrix.GetLength(0); i++)
            {
                Console.Write(String.Format("{0,5}", "(" + model.Labels[i] + ")"));
                for (int j = 0; j < confusionMatrix.GetLength(1); j++)
                {
                    Console.Write(String.Format("{0,5}", confusionMatrix[i, j]));
                }
                Console.WriteLine();
            }

            Console.WriteLine("\n\nPress any key to quit...");
            Console.ReadLine();
        }
        private async Task PerformAnalysis(String path, Rectangle rectangle)
        {
            UShortArrayAsImage image = null;

            double[] pcaComponents = null;
            int      tasksComplete = 0;

            UpdateStatus(path, startingImageStatusStr);
            List <Task> tasks = new List <Task>()
            {
                new Task(() =>
                {
                    var file = db.FileStorage.FindById($"images/{path}");
                    var ms   = new MemoryStream();
                    file.CopyTo(ms);
                    ms.Seek(0, 0);
                    image = DicomFile.Open(ms).GetUshortImageInfo();

                    UpdateStatus(path, loadedImageStatusStr);
                }),
                new Task(() =>
                {
                    image = Normalization.GetNormalizedImage(image, rectangle,
                                                             int.Parse(Configuration.Get("sizeImageToAnalyze")));
                    db.FileStorage.Upload($"images/{path}-cropped", $"{path}-cropped",
                                          image.GetPngAsMemoryStream());

                    UpdateStatus(path, croppedImageStatusStr);
                }),
                new Task(() =>
                {
                    image = Contrast.ApplyHistogramEqualization(image);

                    db.FileStorage.Upload($"images/{path}-croppedContrast", $"{path}-croppedContrast",
                                          image.GetPngAsMemoryStream());

                    UpdateStatus(path, contrastImageStatusStr);
                }),
                new Task(() =>
                {
                    //PCA
                    PCA pca = PCA.LoadModelFromFile(Configuration.Get("PcaModelLocation"));

                    if (!int.TryParse(Configuration.Get("componentsToUse"), out int components))
                    {
                        components = pca.Eigenvalues.Length;
                    }
                    pcaComponents = pca.GetComponentsFromImage(image, components);
                    UpdateStatus(path, pcaImageStatusStr);
                }),
                new Task(() =>
                {
                    //SVM
                    SVMProblem svmProblem = new SVMProblem();

                    // add all the components to an SVMNode[]
                    SVMNode[] nodes = new SVMNode[pcaComponents.Length];
                    for (int i = 0; i < pcaComponents.Length; i++)
                    {
                        nodes[i] = new SVMNode(i + 1, pcaComponents[i]);
                    }

                    svmProblem.Add(nodes, 0);

                    svmProblem = svmProblem.Normalize(SVMNormType.L2);

                    SVMModel svmModel = SVM.LoadModel(Configuration.Get("ModelLocation"));

                    double[] results = svmProblem.PredictProbability(svmModel, out var probabilities);

                    var analysis              = db.GetCollection <Analysis>("analysis");
                    Analysis currentAnalysis  = analysis.FindOne(x => x.Id.ToString().Equals(path));
                    currentAnalysis.Certainty = results[0] == 0 ? probabilities[0][1] * 100 : probabilities[0][0] * 100;
                    currentAnalysis.Diagnosis = results[0] == 0
                        ? DdsmImage.Pathologies.Benign
                        : DdsmImage.Pathologies
                                                .Malignant;
                    analysis.Update(currentAnalysis);


                    UpdateStatus(path, svmImageStatusStr);
                })
            };

            foreach (Task task in tasks)
            {
                task.Start();
                await task;

                // lets set percentage done:
                var      analysis        = db.GetCollection <Analysis>("analysis");
                Analysis currentAnalysis = analysis.FindOne(x => x.Id.ToString().Equals(path));
                currentAnalysis.PercentageDone = (++tasksComplete * 100) / tasks.Count;
                analysis.Update(currentAnalysis);
            }

            UpdateStatus(path, doneStatusStr);
        }