Esempio n. 1
0
        /// <summary>
        /// Register feature to the CLassifier
        /// Format:G,N,%C,%R,%U,%D
        /// </summary>
        /// <param name="datastructureGroup"></param>
        /// <param name="elementSize">Number of elements in the data structure at the time of an operation, N</param>
        /// <param name="percentC">%C</param>
        /// <param name="percentR">%R</param>
        /// <param name="percentU">%U</param>
        /// <param name="percentD">%D</param>
        public void RegisterFeature(DataStructureGroup datastructureGroup, int elementSize, double percentC, double percentR, double percentU, double percentD, CrudBasedCollection.C5DataStructure currentDS)
        {
            while (!isBusy)//this is to make sure that the next feature will be registered only after the prior one has been completely registered.
            {
                isBusy = true;
                currentDataStructure = currentDS;


                //1. Encode and normalize the feature values
                double[] x = new double[10];                                                                            //10 input values of the ANN
                double[] encodedNormInterfaceAndSetBagProperty = EncodeNormalizeDataStructureGroup(datastructureGroup); //X1 Feature (5-length array)
                Array.Copy(encodedNormInterfaceAndSetBagProperty, 0, x, 0, 5);                                          //copy to the first 5 arrays
                x[5] = (elementSize - gaussMeanX2) / gaussStdvX2;                                                       //X2 Feature
                x[6] = (percentC - gaussMeanX3) / gaussStdvX3;                                                          //X3 Feature
                x[7] = (percentR - gaussMeanX4) / gaussStdvX4;                                                          //X4 Feature
                x[8] = (percentU - gaussMeanX5) / gaussStdvX5;                                                          //X5 Feature
                x[9] = (percentD - gaussMeanX6) / gaussStdvX6;                                                          //X6 Feature;

                //2. Register to Classifier and compute the data structure
                double[] computed_y = Classifier.ComputeOutputs(x);//9 output values of the ANN
                //using winner-take-all method to evaluate y values
                int    maxComputedYIndex = MaxIndex(computed_y);
                string computedDS        = yValues[maxComputedYIndex];
                ngram.Dequeue();
                ngram.Enqueue(computedDS);

                //3. Register the computed DS as an N-Gram sequence to the Predictor
                Predictor.RegisterSequence(ngram.ToArray());
                string[] ngramMinus1 = new string[NValue - 1];
                Array.Copy(ngram.ToArray(), 1, ngramMinus1, 0, NValue - 1);
                CrudBasedCollection.C5DataStructure predictedDS = GetC5DataStructure(Predictor.PredictNext(ngramMinus1));
                isBusy = false;
                registerCount++;
                //For debugging or simulation purposes only, comment this line to improve performance
                OnFeatureRegistered(new FeatureRegisteredEventArgs(datastructureGroup, elementSize, percentC, percentR, percentU, percentD, computedDS, currentDataStructure.ToString(), Predictor.PredictedProbabilty, predictedDS.ToString(), registerCount));//raise an event

                bool reset = false;

                DecisionMaker.MakeDecision(registerCount, currentDataStructure, predictedDS, Predictor.PredictedProbabilty, out reset);
                if (reset)
                {
                    registerCount = 0;
                }


                break;
            }
        }