private void Actualize()
        {
            // create a corresponding BayesClassifierModule object in MATLAB
            var noOfCategories = _classificationCategories.Count;
            var cmd            = ClassifierUniqueId + " = BayesClassifierModule(" + noOfCategories + ");";

            MatlabInterface.Execute(cmd);
            // generate a Bayesian Classifier for each 'Pattern Classification Input' object.
            foreach (var pci in InputNodes)
            {
                var minVal = 0;
                var maxVal = 0;

                if (pci.GetType() == typeof(Variable))
                {
                    var v = (Variable)pci;
                    minVal = v.Value.MinimumAllowableValue;
                    maxVal = v.Value.MaximumAllowableValue;
                }
                else if (pci.GetType() == typeof(BayesClassifierModule))
                {
                    var b = (BayesClassifierModule)pci;
                    minVal = 1;
                    maxVal = b.ClassificationCategories.Count;
                }

                MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".newInputNode(" + minVal + ", " + maxVal + ");");
            }
            // lock BayesClassifierModule
            cmd = ClassifierUniqueId + " = " + ClassifierUniqueId + ".lock();";
            MatlabInterface.Execute(cmd);
        }
コード例 #2
0
 public void ReadStatusFlagsAndUpdateResult()
 {
     // set status flags
     if (MatlabInterface.MatlabVariableToInteger(ClassifierUniqueId + ".WaitingForTrainingResponse", false).Equals(0))
     {
         _waitingForTrainingResponse = false;
     }
     else
     {
         _waitingForTrainingResponse = true;
     }
     // update/fetch the result
     if (MatlabInterface.MatlabVariableToInteger(ClassifierUniqueId + ".ObjectFound", false).Equals(0))
     {
         Result = false;
     }
     else
     {
         Result = true;
     }
     // inform all
     if (NewResultAvailable != null)
     {
         NewResultAvailable(this, new EventArgs());
     }
 }
コード例 #3
0
        private int[] CreateArrayOfPresentValues(bool actualizeInMatlab, string nameInMatlab = "")
        {
            // all input values to array, in chronological order (order of index)
            var values = new List <int>();

            foreach (var inp in _inputNodes)
            {
                // get value
                int?value = null;
                if (inp.GetType() == typeof(Variable))
                {
                    var v = (Variable)inp;
                    if (v.Value.Value.HasValue)
                    {
                        value = v.Value.Value.Value + 1;
                    }
                    else
                    {
                        throw new ApplicationException("Variable's value is NULL!");
                    }
                }
                else if (inp.GetType() == typeof(BayesClassifierModule))
                {
                    var b = (BayesClassifierModule)inp;
                    if (b.Result != null)
                    {
                        value = b.Result.MatlabIndex;
                    }
                    else
                    {
                        throw new ApplicationException("Bayesian Classifier Module has not result!");
                    }
                }
                // add to list and move to next input
                if (value != null)
                {
                    values.Add(value.Value);
                }
            }
            if (values.Count != _inputNodes.Count)
            {
                throw new ApplicationException("Array of input values is not the same size as the number of inputs!");
            }
            var arrayOfValues = values.ToArray();

            if (!actualizeInMatlab)
            {
                return(arrayOfValues);
            }
            if (nameInMatlab != "")
            {
                MatlabInterface.ArrayToMatlabVector(arrayOfValues, nameInMatlab, true);
            }
            else
            {
                throw new ApplicationException("Must specify a name to actualize array in Matlab!");
            }
            return(arrayOfValues);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputVariable"></param>
        /// <param name="inputVariableValue"></param>
        /// <returns></returns>
        public ClassCategory GetDecision(PatternClassificationInput inputVariable, int inputVariableValue)
        {
            // MatlabInterface.Execute request
            MatlabInterface.Execute("inputClassifierDecision = " + ClassifierUniqueId + ".InputNodeClassifiers(" + inputVariable.ClassifierMatlabIndex + ").getDecision(" + inputVariableValue + ");");
            // fetch value and return
            var intResult = MatlabInterface.MatlabVariableToInteger("inputClassifierDecision", true);
            var c         = _classificationCategories[intResult - 1];

            return(c);
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inputVariable"></param>
 /// <param name="inputVariableValue"></param>
 /// <param name="c"></param>
 /// <param name="plot"></param>
 public void AssociateWithCategory(PatternClassificationInput inputVariable, int inputVariableValue,
                                   ClassCategory c, bool plot)
 {
     // associate input value with cateogiry, for the specified variable
     MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".InputNodeClassifiers(" + inputVariable.ClassifierMatlabIndex + ").createAssociation(" + inputVariableValue + ", " + c.MatlabIndex + ");");
     // plot
     if (plot)
     {
         MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".InputNodeClassifiers(" + inputVariable.ClassifierMatlabIndex + ").plotLikelihoods();");
     }
 }
コード例 #6
0
 /// <summary>
 /// Associate current values with a particular category.
 /// </summary>
 public void AssociateWithCategory(int[] inputValues, ClassCategory c, bool plot)
 {
     MatlabInterface.ArrayToMatlabVector(inputValues, "evaluateTheseValues", true);
     // MatlabInterface.Execute request
     MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".associateValuesWithCategory(evaluateTheseValues, " + c.MatlabIndex + ");");
     // show us the result - comment out of not needed
     if (plot)
     {
         MatlabInterface.Execute(ClassifierUniqueId + ".plotAllLikelihoods();");
     }
 }
コード例 #7
0
 private void CaptureReferenceImage(bool cropImage)
 {
     if (cropImage)
     {
         MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".captureRefImgAndCrop();");
     }
     else
     {
         MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".captureRefImg();");
     }
 }
コード例 #8
0
        private ClassCategory GetDecisionFromMatlabObj()
        {
            // execute request
            Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".getDecision(evaluateTheseValues);");
            Execute("Decision = " + ClassifierUniqueId + ".Decision;");
            // get result
            //var categoryNumber = Cognition.MatlabVariableToInteger(ClassifierUniqueId + ".Decision", false)
            var categoryNumber = MatlabInterface.MatlabVariableToInteger("Decision", false);
            var cat            = _classificationCategories[categoryNumber - 1];

            return(cat);
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputVariable"></param>
        /// <param name="priorProbabilities"></param>
        public void SetCategoryPriories(PatternClassificationInput inputVariable, double[] priorProbabilities)
        {
            var matlabArrayName = "newPrioriesForInputNo_" + inputVariable.ClassifierMatlabIndex;

            MatlabInterface.ArrayToMatlabVector(priorProbabilities, matlabArrayName, true);
            if (priorProbabilities.Length != _classificationCategories.Count)
            {
                throw new ApplicationException(
                          "Number of priories in array does not match number of classification categories!");
            }
            MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".setCategoryPrioriesForInput(" + inputVariable.ClassifierMatlabIndex +
                                    ", " + matlabArrayName + ");");
            // plot resultant priories of BC
            MatlabInterface.Execute("plot(" + ClassifierUniqueId + ".InputNodeClassifiers(" + inputVariable.ClassifierMatlabIndex +
                                    ").priories);");
        }
コード例 #10
0
        /// <summary>
        /// Associate current values with a particular category.
        /// </summary>
        public void AssociateWithCategory(ClassCategory c, bool plot)
        {
            if (c == null)
            {
                throw new ApplicationException("No Category Selected.");
            }

            // create array of values in MATLAB
            CreateArrayOfPresentValues(true, "evaluateTheseValues");
            // MatlabInterface.Execute request
            MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".associateValuesWithCategory(evaluateTheseValues, " + c.MatlabIndex + ");");
            // show us the result - comment out of not needed
            if (plot)
            {
                MatlabInterface.Execute(ClassifierUniqueId + ".plotAllLikelihoods();");
            }
        }
コード例 #11
0
        static void Main(string[] args)
        {
            MatlabInterface.InitMainWindow();
            int n = 0;

            while (!MatlabInterface.IsSettingReady())
            {
                Thread.Sleep(100);
                Console.WriteLine("Waiting." + (n++));
            }

            var s = MatlabInterface.GetSetting();

            Console.WriteLine(s.str);
            Console.WriteLine("Finished");
            Console.ReadKey();
        }
コード例 #12
0
        public void ProvideTrainingResponse(bool objectDetected)
        {
            if (!_waitingForTrainingResponse)
            {
                throw new ApplicationException("MATLAB SURFDetector object is not expecting a training response!");
            }
            var v = 0;

            // get int representative
            if (objectDetected)
            {
                v = 1;
            }
            MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".trainClassifier(" + v + ");");
            // reset flag
            _waitingForTrainingResponse = false;
        }
コード例 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inputValues"></param>
 /// <returns></returns>
 public ClassCategory GetDecision(int[] inputValues)
 {
     MatlabInterface.ArrayToMatlabVector(inputValues, "evaluateTheseValues", true);
     // MatlabInterface.Execute request
     return(GetDecisionFromMatlabObj());
 }
コード例 #14
0
ファイル: Cognition.cs プロジェクト: TejBirring8/AVINSoR
        // DO THIS LATER
        //public SurfFeaturesDetector SurfFeature



        /// <summary>
        /// New Avinsor Pattern Classification object to manage all pattern classification components in the project.
        /// </summary>
        public Cognition()
        {
            MatlabInterface.InitializeMatlab();
            BayesClassifierModules = new BayesClassifierModuleList(MatlabInterface.MatlabServer);
        }
コード例 #15
0
 public void CaptureCompareTrain()
 {
     MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".captureCompareTrain();");
 }
コード例 #16
0
 public Matlab()
 {
     MatlabInterface.InitializeMatlab();
     Server = MatlabInterface.MatlabServer;
     InitializeComponent();
 }
コード例 #17
0
 /// <summary>
 ///
 /// </summary>
 private void ActualizeInMatlab()
 {
     MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".SURFDetector(0);");
 }