예제 #1
0
        public void Learn(double[] MainResult, double Reward, double[] Target, double[] inputs, int Type)
        {
            TotalError = 0;



            TotalError = Net.LearnError(Target, MainResult);
            //Learning = false;
            if (Learning)
            {
                // new Learn System
                if (DoEnhancedLearning)
                {
                    Net = EnhancedLearning.CacheLearn(new PastData(Target, MainResult, RND, TotalError, inputs, Type), Net);
                    Net = EnhancedLearning.UpdateCache(Net);
                }
                else
                {
                    // normal Learn
                    Net.Learn(Target, MainResult, NewLearnRate);
                }
            }

            if (DoEnhancedLearning)
            {
                NewLearnRate      = EnhancedLearning.GetLearnRate();
                InvestigationRate = EnhancedLearning.GetInvestigationRate();
                Learning          = EnhancedLearning.UpdateTraining(Learning, TotalError);
            }
        }
예제 #2
0
        public ANN UpdateCache(ANN Net)
        {
            int count = PreviousData.Count;


            if (count > 2 && HighPos > -1)
            {
                int      Pos      = HighPos;
                double[] NewInput = PreviousData[Pos].GetInput();


                double[] SingleTarget = PreviousData[Pos].GetTarget();
                double[] result       = Net.feedForward(NewInput);
                HighError = Net.LearnError(SingleTarget, result);



                double ErrorLevel;
                int    CheckCount = 1;
                do
                {
                    Net.Learn(SingleTarget, result, NewLearnRate);
                    result = Net.feedForward(NewInput);
                    CheckCount--;
                    ErrorLevel = Net.LearnError(SingleTarget, result);
                } while (ErrorLevel > LowError && CheckCount > 0);
            }


            return(Net);
        }
예제 #3
0
        public void EnhancedLearn(ANN Net, double[] NewInput, double [] SingleTarget)
        {
            double ErrorLevel;

            double[] result = Net.feedForward(NewInput);
            ErrorLevel = Net.LearnError(SingleTarget, result);
            double SetLevel = ErrorLevel * 0.9;
            //if (SetLevel < 0.05)
            //{
            //SetLevel = 0.05;
            //}
            int CheckCount = 10;

            do
            {
                result = Net.feedForward(NewInput);



                Net.Learn(SingleTarget, result, NewLearnRate);
                CheckCount--;
                ErrorLevel = Net.LearnError(SingleTarget, result);
            } while (ErrorLevel > SetLevel || CheckCount > 0);
        }
예제 #4
0
        public ANN CacheLearn(PastData NewEntry, ANN Net)
        {
            int OneCount   = 0;
            int TwoCount   = 0;
            int ThreeCount = 0;


            // LowPos = -1;
            // HighPos = -1;
            LowError  = double.MaxValue;
            HighError = double.MinValue;

            LastEntry = NewEntry;


            double ErrorLevel = 0;

            double[] NewInput = NewEntry.GetInput();



            double[] SingleTarget = NewEntry.GetTarget();
            double[] result       = Net.feedForward(NewInput);
            Net.Learn(SingleTarget, result, NewLearnRate);



            //   ErrorLevel = Net.LearnError(SingleTarget, result);

            // add a bit that only addes bad ones!
            // if (ErrorLevel > 0.25)
            // {
            PreviousData.Add(NewEntry);
            //     Console.WriteLine("hello");
            // }
            // Console.WriteLine("ADDING ENTRY : " + PreviousData.Count);



            if (PreviousData.Count > CacheSize)
            {
                PreviousData.RemoveAt(LowPos);
                LowError = double.MaxValue;
                LowPos   = -1;
            }

            for (int a = 0; a < PreviousData.Count(); a++)
            {
                ErrorLevel = 0;

                NewInput = PreviousData[a].GetInput();


                SingleTarget = PreviousData[a].GetTarget();

                if (EnhancedLearning > 0)
                {
                    EnhancedLearn(Net, NewInput, SingleTarget);
                }

                /////
                // Store Type Makeup
                if (PreviousData[a].GetTypeCode() == 1)
                {
                    OneCount++;
                }
                if (PreviousData[a].GetTypeCode() == 2)
                {
                    TwoCount++;
                }
                if (PreviousData[a].GetTypeCode() == 3)
                {
                    ThreeCount++;
                }



                result   = Net.feedForward(NewInput);
                TypeData = "" + OneCount + " ," + TwoCount + "," + ThreeCount + "," + (OneCount + TwoCount + ThreeCount);

                ErrorLevel = Net.LearnError(SingleTarget, result);


                if (ErrorLevel < LowError)
                {
                    LowError = ErrorLevel;
                    LowPos   = a;
                }
                if (ErrorLevel > HighError)
                {
                    HighError = ErrorLevel;
                    HighPos   = a;
                }

                //  }
            }

            if (EnhancedLearning > 0)
            {
                EnhancedLearning--;
            }

            return(Net);
        }