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); }
/// <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();"); } }
/// <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);"); }
/// <summary> /// /// </summary> /// <param name="inputValues"></param> /// <returns></returns> public ClassCategory GetDecision(int[] inputValues) { MatlabInterface.ArrayToMatlabVector(inputValues, "evaluateTheseValues", true); // MatlabInterface.Execute request return(GetDecisionFromMatlabObj()); }