示例#1
0
        public static void ProcessMultiRuns(List <string> dirList)
        {
            TrainingTesting_SharedVariables._trialProblem = null;

            if (Preferences.Instance.ProblemOriginalMulti == null)
            {
                GuiPreferences.Instance.setLog("Processing Failed: Problem null!");
                return;
            }

            if (Preferences.Instance.ProblemOriginalMulti.Count <= 0)
            {
                GuiPreferences.Instance.setLog("Processing Failed: Problem List is Empty");
                return;
            }

            for (int i = 0; i < Preferences.Instance.ProblemOriginalMulti.Count; i++)
            {
                if (Preferences.Instance.ProblemOriginalMulti[i].samples == null)
                {
                    GuiPreferences.Instance.setLog("Processing problem " + i.ToString() + " Failed: samples empty!");
                    return;
                }
            }

            Preferences.Instance.dirList = dirList;

            //we only clear all memory in offline analysis, and once in the first realtime processing vector - which is done externally in testdll
            if (!Preferences.Instance.RealTimeTestingSingleVector)
            {
                GuiPreferences.Instance.setLog("Starting Processing.");
                clearProblem();
                clearSVM();
                JobManager.clearJob();
                GC.Collect();
            }

            //if unprocessed is UNchecked then process all jobs.
            if (!GuiPreferences.Instance.UnprocessedChecked)
            {
                //NOTE: this is commented out because this is not recoded for multi dirs yet. and not needed in the current pipeline.

                /*
                 * //we only need to add jobs at the beginning and do it once.
                 * if ((!Preferences.Instance.RealTimeTestingSingleVector) || (Preferences.Instance.RealTimeTestingSingleVector && Preferences.Instance.ProblemOriginal.samples[1] == null))
                 * {
                 *  addFeatureJobs();
                 *  calculatePreviousKValues();
                 * }
                 *
                 * //pre for all jobs, future support only
                 * preProcessFeatureJobs();
                 * //here the pre/proc/post is done for every job.
                 * processFeatureJobs();
                 * //post for all jobs, future support only
                 * postProcessFeatureJobs();
                 *
                 *
                 * //TODO: do this each time we get out of processing, or do this just when "Testing" is activated". seems harmless to do it all the time.
                 * _trialProblem = Preferences.Instance.ProblemFinal;
                 *
                 * //we only need to assign to the final problem when we are in offline mode
                 * //in real time we only need to send the classification result and sample weight.
                 * if (!Preferences.Instance.RealTimeTestingSingleVector)
                 * {
                 *  GuiPreferences.Instance.setLog("Processing Finished!");
                 * }
                 * else
                 * {
                 *  if (Preferences.Instance.currentUDPVector >= Preferences.Instance.maxKvectorsToWaitBeforeClassification)
                 *  {
                 *      Preferences.Instance.currentClassifiedVector += 1;
                 *      //allow to predict only if sample is not labeled as baseline - this happens in the beginning of a experiment session
                 *      if (Preferences.Instance.ProblemFinal.labels[Preferences.Instance.currentClassifiedVector - 1] != 1.0)
                 *      {
                 *          //allow to predict
                 *          double pred = 1.0;
                 *          GuiPreferences.Instance.setLog("Single Vector Processing Finished..");
                 *          pred = Preferences.Instance.svmWrapper.GetAccuracyFromTestSingleSample(Preferences.Instance.ProblemFinal, Preferences.Instance.svmModel);
                 *          transmitPrediction(pred);
                 *      }
                 *  }
                 * }*/
            }
            else //process without PROCESSING JOBS, the original problem
            {
                //real-time testing
                if (Preferences.Instance.RealTimeTestingSingleVector)
                {
                    //NOTE: minmax for testing loading moved to form1.cs before pipe async creation.
                    //NOTE: minmax for testing loading moved to form1.cs before pipe async creation.
                    //NOTE: minmax for testing loading moved to form1.cs before pipe async creation.
                    //NOTE: minmax for testing loading moved to form1.cs before pipe async creation.
                    //NOTE: minmax for testing loading moved to form1.cs before pipe async creation.
                    //NOTE: minmax for testing loading moved to form1.cs before pipe async creation.
                    //if you need it here please put it back.

                    if (GuiPreferences.Instance.CbSMOChecked) //real time testing using WEKA AND SMO
                    {
                        RealTimeProcessing.ExecuteRealtimeTest(TrainingTesting_SharedVariables.smo);

                        Preferences.Instance.currentClassifiedVector += 1;

                        //test on self should get 100%
                        //testingEval = new weka.classifiers.Evaluation(data);
                        //testingEval.evaluateModel(smo, data);
                        //printWekaResults(testingEval.toSummaryString("\nResults\n======\n", false));
                        //GuiPreferences.Instance.setLog("RealTime SMO Model Testing on current vector");
                        //pred = (double)testingEval.predictions().elementAt(0);
                        //transmitPrediction(pred);

                        //GuiPreferences.Instance.setLog("Single Vector Processing Finished..");
                    }
                    else if (GuiPreferences.Instance.CbSVMChecked) //weka + SVM, pipeline unfinished.
                    {
                        //NOTE: commented out because this code is not yet finished to support weka and SVM (not SMO)

                        /*
                         * //if (Preferences.Instance.currentUDPVector >= Preferences.Instance.maxKvectorsToWaitBeforeClassification)
                         * {
                         *  Preferences.Instance.currentClassifiedVector += 1;
                         *  //allow to predict only if sample is not labeled as baseline - this happens in the beginning of a experiment session
                         *  //if (Preferences.Instance.ProblemFinal.labels[Preferences.Instance.currentClassifiedVector - 1] != 1.0)
                         *  {
                         *      //allow to predict
                         *      double pred = 1.0;
                         *      pred = Preferences.Instance.svmWrapper.GetAccuracyFromTestSingleSample(Preferences.Instance.ProblemFinal, Preferences.Instance.svmModel);
                         *      transmitPrediction(pred);
                         *      GuiPreferences.Instance.setLog("Single Vector Processing Finished..");
                         *  }
                         * }*/
                    }
                }
                else // TRAINING W/ WEKA + SMO
                {
                    //go over all available and loaded RUNS and run the weka pipeline on them
                    for (int i = 0; i < Preferences.Instance.ProblemOriginalMulti.Count; i++)
                    {
                        TrainingTesting_SharedVariables._trialProblem = Preferences.Instance.ProblemOriginalMulti[i];
                        Preferences.Instance.currentProcessedRun      = i; //0-based index (run 0 is the first run)
                        GuiPreferences.Instance.WorkDirectory         = dirList[i];
                        TrainingTesting_SharedVariables.topIGFeatures = new double[][] { };
                        Instances data;
                        bool      createFiles = false;

                        //if overwrite then delete all non relevant files in the directory (arff/libsvm)
                        if (GuiPreferences.Instance.CbOverwriteProcessedFilesChecked)
                        {
                            foreach (string fileName in Preferences.Instance.deleteFiles)
                            {
                                FileDirectoryOperations.DeleteFile(GuiPreferences.Instance.WorkDirectory + fileName);
                            }
                        }


                        //if overwrite we create new files (after the above deletion)
                        if (GuiPreferences.Instance.CbOverwriteProcessedFilesChecked)
                        {
                            createFiles = true;
                        }
                        else // we check to see if the files are there and only if no we create.
                        {
                            // if files are not here its safe to create them from scratch, if not then we pass.
                            if (!(File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet.libsvm") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors.libsvm") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors_scale_paramCS.libsvm") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors_scaledCS.libsvm") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors_scaledCS.libsvm.arff") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_4th_vectors.libsvm") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_4th_vectors_scale_paramCS.libsvm") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_4th_vectors_scaledCS.libsvm") &&
                                  File.Exists(GuiPreferences.Instance.WorkDirectory + "TrainSet_4th_vectors_scaledCS.libsvm.arff")
                                  ))
                            {
                                createFiles = true;
                            }
                        }

                        if (createFiles)
                        {
                            //files are loaded,thresholded,vectorized (arff),normalized. false means that IG and training are not done here.
                            if (!ProcessSingleRunOffline(ref TrainingTesting_SharedVariables.topIGFeatures, TrainingTesting_SharedVariables._trialProblem))
                            {
                                GuiPreferences.Instance.setLog("Samples are empty");
                            }
                            Preferences.Instance.TrainingBaselineMediansRunningWindow[i].clearMatrixMemory();
                        }
                        else
                        {
                            GuiPreferences.Instance.setLog("Skipped Processing for directory: " +
                                                           GuiPreferences.Instance.WorkDirectory);
                        }
                    }

                    //Concatenate the data
                    WekaProcessingPipelineForMultiRuns(dirList);


                    if (GuiPreferences.Instance.CbSVMChecked)
                    {
                        Preferences.Instance.ProblemOriginal = new libSVM_ExtendedProblem();
                        //here we need to load the filtered DS
                        //Preferences.Instance.svmWrapper.

                        //GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors_scaledCS_filteredIG.libsvm";
                    }
                    TrainingTesting_SharedVariables._trialProblemMulti = Preferences.Instance.ProblemOriginalMulti;
                    GuiPreferences.Instance.setLog("Finished Processing.");

                    Sound.beep(Sound.beepType.Asterisk);
                    //System.Media.SystemSounds.Beep.Play();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Process is the most updated code toward all the classification options, but should be used when doing offline classification as it expects the param file to be located in the test dir
        /// in the online version it should look for the Param file
        /// </summary>
        public static void OfflineProcess()
        {
            TrainingTesting_SharedVariables._trialProblem = null;
            if (Preferences.Instance.ProblemOriginal != null)
            {
                if (Preferences.Instance.ProblemOriginal.samples != null)
                {
                    //we only clear all memory in offline analysis, and once in the first realtime processing vector - which is done externally in testdll
                    if (!Preferences.Instance.RealTimeTestingSingleVector)
                    {
                        GuiPreferences.Instance.setLog("Starting Processing.");
                        Training_MultiRunProcessing.clearProblem();
                        Training_MultiRunProcessing.clearSVM();
                        JobManager.clearJob();
                        GC.Collect();
                    }

                    //if unprocessed is UNchecked then process all jobs.
                    if (!GuiPreferences.Instance.UnprocessedChecked)
                    {
                        //we only need to add jobs at the beginning and do it once.
                        if ((!Preferences.Instance.RealTimeTestingSingleVector) || (Preferences.Instance.RealTimeTestingSingleVector && Preferences.Instance.ProblemOriginal.samples[1] == null))
                        {
                            JobManager.addFeatureJobs();
                            JobManager.calculatePreviousKValues();
                        }

                        //pre for all jobs, future support only
                        JobManager.preProcessFeatureJobs();
                        //here the pre/proc/post is done for every job.
                        JobManager.processFeatureJobs();
                        //post for all jobs, future support only
                        JobManager.postProcessFeatureJobs();


                        //TODO: do this each time we get out of processing, or do this just when "Testing" is activated". seems harmless to do it all the time.
                        TrainingTesting_SharedVariables._trialProblem = Preferences.Instance.ProblemFinal;

                        //we only need to assign to the final problem when we are in offline mode
                        //in real time we only need to send the classification result and sample weight.
                        if (!Preferences.Instance.RealTimeTestingSingleVector)
                        {
                            GuiPreferences.Instance.setLog("Processing Finished!");
                        }
                        else
                        {
                            if (Preferences.Instance.currentUDPVector >= Preferences.Instance.maxKvectorsToWaitBeforeClassification)
                            {
                                Preferences.Instance.currentClassifiedVector += 1;
                                //allow to predict only if sample is not labeled as baseline - this happens in the beginning of a experiment session
                                if (Preferences.Instance.ProblemFinal.labels[Preferences.Instance.currentClassifiedVector - 1] != 1.0)
                                {
                                    //allow to predict
                                    double pred = 1.0;
                                    GuiPreferences.Instance.setLog("Single Vector Processing Finished..");
                                    pred = Preferences.Instance.svmWrapper.GetAccuracyFromTestSingleSample(Preferences.Instance.ProblemFinal, Preferences.Instance.svmModel);
                                    RealTimeProcessing.transmitPrediction(pred);
                                }
                            }
                        }
                    }
                    else //process without PROCESSING JOBS, the original problem
                    {
                        //real-time testing
                        if (Preferences.Instance.RealTimeTestingSingleVector)
                        {
                            // we load the configuration file for min/max for all features - ONCE.
                            if (!TrainingTesting_SharedVariables._svmscaleTraining.ConfigFileLoaded)
                            {
                                //load normalization configuration from training stage.
                                string commandLine = "-l 0 " +
                                                     "-r " + GuiPreferences.Instance.WorkDirectory +
                                                     "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scale_paramCS.libsvm " +
                                                     GuiPreferences.Instance.WorkDirectory + "nofile";

                                TrainingTesting_SharedVariables._svmscaleTraining.initSingleVectorConfig(commandLine.Split(' '), 80 * 80 * 32);
                            }

                            if (GuiPreferences.Instance.CbSMOChecked)
                            {
                                RealTimeProcessing.ExecuteRealtimeTest(TrainingTesting_SharedVariables.smo);

                                Preferences.Instance.currentClassifiedVector += 1;

                                //test on self should get 100%
                                //testingEval = new weka.classifiers.Evaluation(data);
                                //testingEval.evaluateModel(smo, data);
                                //printWekaResults(testingEval.toSummaryString("\nResults\n======\n", false));
                                //GuiPreferences.Instance.setLog("RealTime SMO Model Testing on current vector");
                                //pred = (double)testingEval.predictions().elementAt(0);
                                //transmitPrediction(pred);

                                //GuiPreferences.Instance.setLog("Single Vector Processing Finished..");
                            }
                            else if (GuiPreferences.Instance.CbSVMChecked) //weka + SVM, pipeline unfinished.
                            {
                                //if (Preferences.Instance.currentUDPVector >= Preferences.Instance.maxKvectorsToWaitBeforeClassification)
                                {
                                    Preferences.Instance.currentClassifiedVector += 1;
                                    //allow to predict only if sample is not labeled as baseline - this happens in the beginning of a experiment session
                                    //if (Preferences.Instance.ProblemFinal.labels[Preferences.Instance.currentClassifiedVector - 1] != 1.0)
                                    {
                                        //allow to predict
                                        double pred = 1.0;
                                        pred = Preferences.Instance.svmWrapper.GetAccuracyFromTestSingleSample(Preferences.Instance.ProblemFinal, Preferences.Instance.svmModel);
                                        RealTimeProcessing.transmitPrediction(pred);
                                        GuiPreferences.Instance.setLog("Single Vector Processing Finished..");
                                    }
                                }
                            }
                        }
                        else
                        {
                            TrainingTesting_SharedVariables._trialProblem = Preferences.Instance.ProblemOriginal;

                            //process the data, save files, normalize, filter, pick upto 1000, save etc..
                            TrainingTesting_SharedVariables._trialWekaData = WekaPipeline_Unprocessed(TrainingTesting_SharedVariables._trialProblem);
                            if (TrainingTesting_SharedVariables._trialWekaData != null)
                            {
                                GuiPreferences.Instance.setLog(
                                    "Weka ProcessingFinished! (in UN-Processing code condition)");
                            }
                            else
                            {
                                GuiPreferences.Instance.setLog(
                                    "Processing Failed: Weka Processing (in UN-Processing code condition)");
                            }

                            if (GuiPreferences.Instance.CbSVMChecked)
                            {
                                Preferences.Instance.ProblemOriginal = new libSVM_ExtendedProblem();
                                //here we need to load the filtered DS
                                //Preferences.Instance.svmWrapper.

                                //GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors_scaledCS_filteredIG.libsvm";
                            }
                        }
                    }
                }
                else
                {
                    GuiPreferences.Instance.setLog("Processing Failed: samples empty!");
                }
            }
            else
            {
                GuiPreferences.Instance.setLog("Processing Failed: Problem null!");
            }
        }