Пример #1
0
        public RLPolicy(int _Input, int _Output, int _HL, String Letter, String LearnType, int ERun)
        {
            NetWorkInit = new NetworkParse[3];

            ReportTrainingCSV = new Reporter(_HL, Letter, LearnType, ERun);

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

            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(20, ERun, NewLearnRate, InvestigationRate);
        }
Пример #2
0
        public ANN CacheLearn(PastData NewEntry, ANN Net)
        {
            double LowError = double.MaxValue;

            HighError = double.MinValue;
            LowPos    = -1;
            HighPos   = -1;

            LastEntry = NewEntry;

            PreviousData.Add(NewEntry);


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

                double[] NewInput = PreviousData[a].GetInput();



                double   SingleTarget = PreviousData[a].GetTarget(0);
                double[] result       = Net.feedForward(NewInput);
                double[] NewTarget    = (double[])result.Clone();
                NewTarget[0] = SingleTarget;

                if (EnhancedLearning > 0)
                {
                    Net.Learn(NewTarget, result, NewLearnRate);
                    //EnhancedLearn(iAction, Net, NewInput, SingleTarget);
                }
                ErrorLevel = Net.LearnError(NewTarget, result);


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



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

            return(Net);
        }
Пример #3
0
        public void EnhancedLearn(int iAction, ANN Net, double[] NewInput, double SingleTarget)
        {
            double SetLevel = HighError * 0.9;
            double ErrorLevel;
            int    CheckCount = 2;

            do
            {
                double[] result    = Net.feedForward(NewInput);
                double[] NewTarget = (double[])result.Clone();
                NewTarget[iAction] = SingleTarget;


                Net.Learn(NewTarget, result, NewLearnRate);
                CheckCount--;
                ErrorLevel = Net.LearnError(NewTarget, result, iAction);
            } while (ErrorLevel > SetLevel & CheckCount > 0);
        }
Пример #4
0
        public void Learn(double _reward, double[] ID, int LastAction)
        {
            double[] Target = new double[1];



            double TotalError = 0;


            Target[0] = _reward;
            // TypeName = "Standard";



            TotalError = Net.LearnError(Target, Result);

            if (Learning)
            {
                // new Learn System
                if (DoEnhancedLearning)
                {
                    Net = EnhancedLearning.CacheLearn(new PastData(Target, Result, ID, RND, TotalError), Net);
                    Net = EnhancedLearning.UpdateCache(Net);
                }
                else
                {
                    // normal Learn
                    Net.Learn(Target, Result, NewLearnRate);
                }
            }

            if (DoEnhancedLearning)
            {
                NewLearnRate      = EnhancedLearning.GetLearnRate();
                InvestigationRate = EnhancedLearning.GetInvestigationRate();
                Learning          = EnhancedLearning.UpdateTraining(Learning, TotalError);
            }



            ReportTrainingCSV.WriteErrorRate(TotalError, LastAction, NewLearnRate, InvestigationRate, _reward, EnhancedLearning.CacheCount(), EnhancedLearning.GetPreviousAverage(), EnhancedLearning.EnhancedLearning, EnhancedLearning.HighPos, EnhancedLearning.LowPos, Net.LearnCount);
        }
Пример #5
0
        public ANN UpdateCache(ANN Net)
        {
            int count = PreviousData.Count;


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


                double SingleTarget = PreviousData[Pos].GetTarget(0);

                double SetLevel = HighError * 0.9;
                double ErrorLevel;
                int    CheckCount = 2;
                do
                {
                    double[] result    = Net.feedForward(NewInput);
                    double[] NewTarget = (double[])result.Clone();
                    NewTarget[0] = SingleTarget;


                    Net.Learn(NewTarget, result, NewLearnRate);
                    CheckCount--;
                    ErrorLevel = Net.LearnError(NewTarget, result);
                } while (ErrorLevel > SetLevel & CheckCount > 0);

                if (count > CacheSize)
                {
                    PreviousData.RemoveAt(LowPos);
                }
            }


            return(Net);
        }