Beispiel #1
0
        /// <summary>
        /// this method is called back in real-time testing and will load a .vdat file
        /// </summary>
        /// <param name="ar"></param>
        public void loadRawDataMultiRun_Pipe(int x, int y, int z, byte[] data, int current, int total)
        {
            if (shouldStop)
            {
                return;
            }

            if (data.Length > 0)
            {
                if (Preferences.Instance.ProblemOriginal.samples == null)
                {
                    Preferences.Instance.ProblemOriginal = new libSVM_ExtendedProblem();
                    GC.Collect();
                    GuiPreferences.Instance.ProgressBarMax = total;
                    Preferences.Instance.ProblemOriginal.PrepareSamplesLabelsSize(total);
                }


                if (current <= Preferences.Instance.events.EventListLastTr)
                {
                    bool corrupted = false;
                    GuiPreferences.Instance.ProgressBarValue = current;
                    ProcessRawBuffer(x, y, z, data, current);
                    RealTimeProcessing.RealTimeProcess();
                    GuiPreferences.Instance.setLog("Processing Vector " + current.ToString());
                }
                else
                {
                    shouldStop = true;
                }
            }

            if (!shouldStop)
            {
                Preferences.Instance.udp.BeginReceive();
            }
        }
Beispiel #2
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();
                }
            }
        }
Beispiel #3
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!");
            }
        }
Beispiel #4
0
        public static Instances WekaPipeline_Unprocessed(libSVM_ExtendedProblem _trialProblem)
        {
            //export to libsvm file
            if (_trialProblem.samples == null)
            {
                GuiPreferences.Instance.setLog("Export Failed: Problem has no samples!");
                return(null);
            }

            string trainFileName = GuiPreferences.Instance.WorkDirectory /*+ GuiPreferences.Instance.FileName*/ + "TrainSet";


            //todo add proper named to saved files, check if null is logical at all.
            if ((_trialProblem.samples != null))
            {
                _trialProblem.Save(trainFileName + ".libsvm");
                GuiPreferences.Instance.setLog("saved Original Problem LibSVM file: " + trainFileName + ".libsvm");
            }

            //separate DS to 3rd and 4th TR
            ////example: ExecuteSelectKthVectorScript(@"TrainSet", @"H:\My_Dropbox\VERE\MRI_data\Tirosh\20120508.Rapid+NullClass.day2\4\rtp\");
            KthExtractionManager.ExecuteSelectKthVectorScript(/*GuiPreferences.Instance.FileName +*/ "TrainSet", GuiPreferences.Instance.WorkDirectory);
            GuiPreferences.Instance.setLog("Created TR3 & TR4 files");

            //normalize 3rd and 4th TR files.
            NormalizationManager.ScaleTrFiles(GuiPreferences.Instance.WorkDirectory);
            GuiPreferences.Instance.setLog("Normalized TR3 & TR4 files");

            //convert tr4 and tr3 to arff + REMOVE 204801 FAKE FEATURE, THAT WAS PLACES TO MAKE SURE WE GET 204800 FEATURES IN THE ARFF FILE.
            if (WekaCommonFileOperation.ConvertLIBSVM2ARFF(GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors_scaledCS.libsvm", 204800))
            {
                GuiPreferences.Instance.setLog("Converted to ARFF: TrainSet_3th_vectors_scaledCS.libsvm");
            }
            if (WekaCommonFileOperation.ConvertLIBSVM2ARFF(GuiPreferences.Instance.WorkDirectory + "TrainSet_4th_vectors_scaledCS.libsvm", 204800))
            {
                GuiPreferences.Instance.setLog("Converted to ARFF: TrainSet_4th_vectors_scaledCS.libsvm");
            }

            //---------------------------------- filter tr3 based on top 1000 from tr4 (the trick) -----------------------------
            //load TR4
            ConverterUtils.DataSource source = new ConverterUtils.DataSource(GuiPreferences.Instance.WorkDirectory + "TrainSet_4th_vectors_scaledCS.libsvm.arff");
            Instances data = source.getDataSet();

            //assign last as index.
            if (data.classIndex() == -1)
            {
                data.setClassIndex(data.numAttributes() - 1);
            }

            //if class not nominal, convert to
            if (!data.classAttribute().isNominal())
            {
                var filter = new weka.filters.unsupervised.attribute.NumericToNominal();

                filter.setOptions(weka.core.Utils.splitOptions("-R last"));
                //filter.setAttributeIndices("last");
                filter.setInputFormat(data);
                data = Filter.useFilter(data, filter);
            }

            //run ig and get top 1000 or up to 1000 bigger than zero, from tr4
            WekaTrainingMethods.useLowLevelInformationGainFeatureSelection(data);

            TrainingTesting_SharedVariables._trainTopIGFeatures = Preferences.Instance.attsel.selectedAttributes();

            //this should be done ONCE
            Preferences.Instance.fastvector = RealTimeProcessing.CreateFastVector(TrainingTesting_SharedVariables._trainTopIGFeatures.Length);
            GuiPreferences.Instance.setLog("created fast vector of length " + TrainingTesting_SharedVariables._trainTopIGFeatures.Length.ToString());

            //serialize (save) topIG indices to file.
            XMLSerializer.serializeArrayToFile(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG_indices.xml", TrainingTesting_SharedVariables._trainTopIGFeatures);
            GuiPreferences.Instance.setLog("saved IG indices to a file (in the same order as IG gave it)");
            //int [] _trainTopIGFeatures_loaded = DeserializeArrayToFile(GuiPreferences.Instance.WorkDirectory + "TrainSet_3th_vectors_scaledCS_filteredIG_indices.xml");

            GuiPreferences.Instance.setLog(TrainingTesting_SharedVariables._trainTopIGFeatures.Length.ToString() + " features above zero value selected (including the Class feature)");

            //load tr3
            source = new ConverterUtils.DataSource(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS.libsvm.arff");
            data   = source.getDataSet();

            //filter top IG
            data = WekaTrainingMethods.useRemoveFilter(data, TrainingTesting_SharedVariables._trainTopIGFeatures, true);

            //after filtering last feature needs to be the class
            if (data.classIndex() == -1)
            {
                data.setClassIndex(data.numAttributes() - 1);
            }

            //save filtered to a file
            WekaCommonFileOperation.SaveLIBSVM(data, GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG");

            return(data);
        }
Beispiel #5
0
        /// <summary>
        /// this method is called back in real-time testing and will load a .vdat file
        /// </summary>
        /// <param name="ar"></param>
        public void loadRawDataMultiRun_UDP(IAsyncResult ar)
        {
            if (shouldStop)
            {
                return;
            }

            byte[] data = Preferences.Instance.udp.EndReceive(ar);

            if (data.Length > 0)
            {
                string text = Encoding.ASCII.GetString(data);
                int    loc1 = text.LastIndexOf("\\");
                int    loc2 = text.LastIndexOf(".");
                int    loc3 = text.LastIndexOf("-");
                int    loc4 = text.LastIndexOf(",");

                if (Preferences.Instance.ProblemOriginal.samples == null)
                {
                    Preferences.Instance.ProblemOriginal = new libSVM_ExtendedProblem();
                    GC.Collect();
                    int totalToProcess = Int32.Parse(text.Substring(loc4 + 1, text.Length - (loc4 + 1)));
                    GuiPreferences.Instance.ProgressBarMax = totalToProcess;
                    //loading just the amount of data we need, so we assign accordingly, not this>Program.mainForm.getMaxAvailableTrs()
                    Preferences.Instance.ProblemOriginal.PrepareSamplesLabelsSize(totalToProcess);
                }

                string path = text.Substring(0, loc1 + 1);
                fileName   = text.Substring(loc1 + 1, loc2 - loc1 - 1);
                last_index = Int32.Parse(text.Substring(loc3 + 1, loc2 - loc3 - 1));

                if (last_index <= Preferences.Instance.events.EventListLastTr)
                {
                    //report progress
                    // DLL GUI Seperation
                    //Program.mainForm.progressBar1.Value = i - GuiPreferences.Instance.FromTR + 1 ;
                    GuiPreferences.Instance.ProgressBarValue = last_index;
                    fileName = GuiPreferences.Instance.WorkDirectory + GuiPreferences.Instance.FileName + last_index.ToString() + ".vdat";
                    loadRawFileName(fileName);
                    //PublicMethods.ProcessMultiRuns(null);
                    RealTimeProcessing.RealTimeProcess();
                    //Preferences.Instance.pipeClient.Send(fileName);
                    GuiPreferences.Instance.setLog("Sending Vector " + last_index.ToString());
                    last_index++;
                }
                else
                {
                    shouldStop = true;
                }


                //updategui();
                // shoot event
                //send the recieved data somewhere
            }

            if (!shouldStop)
            {
                Preferences.Instance.udp.BeginReceive();
            }
        }
Beispiel #6
0
        /// <summary>
        /// quick tests udp classification via weka's SMO
        /// </summary>
        /// <returns></returns>
        public bool testUdpWekaSMO()
        {
            if (UDPListenActive)
            {
                TrainingTesting_SharedVariables.binary.shouldStop = true;
                GuiPreferences.Instance.setLog("Stopping UDP");
            }
            else
            {
                GuiPreferences.Instance.setLog("Starting UDP");
                TrainingTesting_SharedVariables.binary.shouldStop = false;


                //GuiPreferences.Instance.WorkDirectory = @"H:\My_Dropbox\VERE\MRI_data\Tirosh\20113110.short.5th.exp.hands.legs.zscore.thought\6\rtp\";
                //GuiPreferences.Instance.FileName = "tirosh-";
                //GuiPreferences.Instance.FileType = OriBrainLearnerCore.dataType.rawValue;
                //GuiPreferences.Instance.ProtocolFile = @"H:\My_Dropbox\VERE\MRI_data\Tirosh\20113110.short.5th.exp.hands.legs.zscore.thought_LRF.prt";

                // tirosh null movement processed for 204800 features + 1 class = 204801.

                /*GuiPreferences.Instance.WorkDirectory = @"H:\My_Dropbox\VERE\MRI_data\Tirosh\20120508.Rapid+NullClass.day2\1\rtp\";
                 * GuiPreferences.Instance.FileName = "tirosh-";
                 * GuiPreferences.Instance.FileType = OriBrainLearnerCore.dataType.rawValue;
                 * GuiPreferences.Instance.ProtocolFile = @"H:\My_Dropbox\VERE\MRI_data\Tirosh\20120705.NullClass1_zbaseline.prt";
                 */

                // magali classification

                /*GuiPreferences.Instance.WorkDirectory = @"H:\My_Dropbox\VERE\Experiment1\Kozin_Magali\20121231.movement.3.imagery.1\18-classification.movement\rtp\";
                 * GuiPreferences.Instance.FileName = "tirosh-";
                 * GuiPreferences.Instance.FileType = OriBrainLearnerCore.dataType.rawValue;
                 * GuiPreferences.Instance.ProtocolFile = @"H:\My_Dropbox\VERE\MRI_data\Tirosh\20113110.short.5th.exp.hands.legs.zscore.thought_LRF.prt";*/


                /// moshe sherf classification, 4 aggregated to test on 1.
                GuiPreferences.Instance.WorkDirectory = @"H:\My_Dropbox\VERE\Experiment1\Sherf_Moshe\20121010.movement.1\15_classification\rtp\";
                GuiPreferences.Instance.FileName      = "tirosh-";
                GuiPreferences.Instance.FileType      = OriBrainLearnerCore.DataType.rawValue;
                GuiPreferences.Instance.ProtocolFile  = @"H:\My_Dropbox\VERE\MRI_data\Tirosh\20113110.short.5th.exp.hands.legs.zscore.thought_LRF.prt";

                //read prot file
                Preferences.Instance.prot = new ProtocolManager();

                //get all files in the path with this extention
                GuiManager.getFilePaths("*.vdat");

                //update certain info
                GuiManager.updateFilePaths();

                //assigned after we know what to assign from the protocol
                //PublicMethods.setClassesLabels();
                GuiPreferences.Instance.CmbClass1Selected = 1; //left
                GuiPreferences.Instance.CmbClass2Selected = 2; //right

                //NEED TO ADD A VARIABLE FOR EVERY OPTION IN THE GUI. RAW VALUES. UNPROCESSED. MULTI CLASS. CROSS VALD, GRID, FOLDS, ETC...
                //and for every button a function!

                /*PublicMethods.clearProblem() ;
                 * PublicMethods.clearSVM();
                 * PublicMethods.clearJob();
                 * GC.Collect();*/

                //load a model for testing
                GuiPreferences.Instance.TrainType = TrainingType.Weka;
                GuiPreferences.Instance.setLog("Deserializing Model");
                WekaTrainingMethods.loadModel();

                double[][] rankedArray = XMLSerializer.DeserializeFile <double[][]>(GuiPreferences.Instance.WorkDirectory + "TrainSet_" + GuiPreferences.Instance.NudClassifyUsingTR.ToString() + "th_vectors_scaledCS_filteredIG_indices.xml");
                for (int a = 0; a < rankedArray.Length; a++)
                {
                    TrainingTesting_SharedVariables._trainTopIGFeatures[a] = Convert.ToInt32(rankedArray[a][0]);
                }

                //this should be done ONCE - move elsewhere.
                Preferences.Instance.fastvector = RealTimeProcessing.CreateFastVector(TrainingTesting_SharedVariables._trainTopIGFeatures.Length);

                //GuiPreferences.Instance.FromTR = from;// 264;
                //GuiPreferences.Instance.ToTR = 100;// 264;
                Preferences.Instance.currentUDPVector = 0;
                Preferences.Instance.udp.RegisterCallBack(TrainingTesting_SharedVariables.binary.loadRawDataUsing_UDP);

                //finally load
                //PublicMethods.binary.loadRawData();

                /*
                 *  //register this function that deals with loading of the filenames
                 *  //BUT ONLY ONCE!
                 *  Preferences.Instance.pipeServer.registerEvent(PublicMethods.binary.loadRawDataUsingPipes_ReceiveData);
                 *
                 *  //PublicMethods.binary.loadRawDataUsingPipes_SendData();
                 *
                 *  //* to automatically send data ever 2s as a simulation and to test the classes.
                 *  PublicMethods.binary.loadRawDataUsingPipes_SendDataTimer();
                 */
            }

            UDPListenActive = !UDPListenActive;
            return(true);
        }