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); }
/// <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); }
/// <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();"); } }
/// <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();"); } }
private void CaptureReferenceImage(bool cropImage) { if (cropImage) { MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".captureRefImgAndCrop();"); } else { MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".captureRefImg();"); } }
/// <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);"); }
private ClassCategory GetDecisionFromMatlabObj() { // MatlabInterface.Execute request MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".getDecision(evaluateTheseValues);"); MatlabInterface.Execute("Decision = " + ClassifierUniqueId + ".Decision;"); // get result //var categoryNumber = Cognition.MatlabVariableToInteger(ClassifierUniqueId + ".Decision", false) var categoryNumber = MatlabInterface.MatlabVariableToInteger("Decision", false); if (categoryNumber == 0) { return(null); } var cat = _classificationCategories[categoryNumber - 1]; return(cat); }
/// <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();"); } }
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; }
public void CaptureCompareTrain() { MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".captureCompareTrain();"); }
/// <summary> /// /// </summary> private void ActualizeInMatlab() { MatlabInterface.Execute(ClassifierUniqueId + " = " + ClassifierUniqueId + ".SURFDetector(0);"); }