Ejemplo 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;
            }
        }
Ejemplo n.º 2
0
        public void MakeDecision(int registeredSubsequenceCount, CrudBasedCollection.C5DataStructure currentDataStructure, CrudBasedCollection.C5DataStructure predictedDataStructure, double probability, out bool resetCount)
        {
            resetCount = false;

            //main logic for the dicision making
            if (registeredSubsequenceCount >= RegisteredDatastructureCountThreshold &&      //   then check if data structure has been registered to the ngram for a certian threshold
                probability >= PredictedPropbabilityThreshold)                                //   and the predicted probability number is equal or greater than a certain threshold
            {
                //trace the number of Yes
                YesDecisionCount++;

                if (predictedDataStructure != CrudBasedCollection.C5DataStructure.Unknown &&         //if the predicted DS is not Unknown or not the same as the current one
                    currentDataStructure != predictedDataStructure)
                {
                    PredictedDataStructure = predictedDataStructure;
                    resetCount             = true;                                                        //the count will be reset every transformation is made
                    if (IsDynamicMode)                                                                    //Make notify only when run on Dynamic Mode
                    {
                        OnTransformationNotified(new TransformNotifiedEventArgs(predictedDataStructure)); //Raise an event to notify the Green data structure to transform to the specific data structure
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public TransformNotifiedEventArgs(CrudBasedCollection.C5DataStructure dataStructure)
 {
     this.TransformToDataStructure = dataStructure;
 }