Esempio n. 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);
            }
        }
Esempio n. 2
0
        public RLPolicy(int _Input, int _Output, int _HL, int ERun, string LearnType, double _LearnRate)
        {
            NetWorkInit = new NetworkParse[3];
            // ReportTrainingCSV = new Reporter(_HL, Letter, LearnType, ERun);

            // int HiddenLayerSize = _Input / 3 * 2 + _Output;
            int HiddenLayerSize = _HL;

            NewLearnRate   = _LearnRate;
            NetWorkInit[0] = new NetworkParse(_Input, HiddenLayerSize, "INPUT", true, "None");
            NetWorkInit[1] = new NetworkParse(HiddenLayerSize, _Output, "HIDDEN", true, "Sigmoid");
            NetWorkInit[2] = new NetworkParse(_Output, _Output, "OUTPUT", false, "Sigmoid");


            double [] temp = new double[_Output];
            if (LearnType == "E")
            {
                DoEnhancedLearning = true;
            }



            inputCount  = _Input;
            OutputCount = _Output;

            Net = new ANN(NetWorkInit, NewLearnRate);

            double [] inputCode = new double[inputCount];
            double [] result    = new double[OutputCount];

            EnhancedLearning = new ELCache(ERun, ERun, NewLearnRate, InvestigationRate);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }