Exemple #1
0
        public Form1()
        {
            InitializeComponent();
            state = new double[] { -Math.PI, 0 };
            sim = new InvertedPendulumEnvironmentSimulator();

            timer1.Start();
        }
Exemple #2
0
        public RL_TDlambda()
        {
            InitializeComponent();
            sim = new InvertedPendulumEnvironmentSimulator();

            igmn1 = new IGMN(new Vector(new double[] { 1, 1, 1 }));
            igmn2 = new IGMN(new Vector(new double[] { 1, 1, 1 }));
            tab1 = new TabularApproximator(new int[] { 200, 200 }, new double[] { -Math.PI, -1.5*Math.PI }, new double[] { Math.PI, 1.5 * Math.PI });
            tab2 = new TabularApproximator(new int[] { 200, 200 }, new double[] { -Math.PI, -1.5*Math.PI }, new double[] { Math.PI, 1.5 * Math.PI });
            r = new Random();
            isRunning = true;
            trainingThread = new Thread(new ThreadStart(train));
            trainingThread.Start();
            timer1.Start();
        }
Exemple #3
0
        protected Bitmap VisualizeInvertedPendulum()
        {
            int res = 1200;

            Bitmap bm = new Bitmap(res, res);
            Graphics g = Graphics.FromImage(bm);
            InvertedPendulumEnvironmentSimulator simm = new InvertedPendulumEnvironmentSimulator();

            double[] state = new double[] { Math.PI, 0 };
            double sumreward = 0;

            for (int i = 0; i < 300; ++i)
            {
                double M;
                double q_act;
                double reward;
                GetAction(state, out M, out q_act, true);
                simm.Simulate(state, new double[] { M }, dT, out state, out reward);
                sumreward += reward;
                if (i % 1 == 0)
                {
                    float zx = 75 + ((i % 100)) * 10;
                    float zy = 150 + 150 * (i / 100);
                    float z = 50;

                    float e1x = zx + (float)(z * simm.Length * Math.Sin(simm.Angle));
                    float e1y = zy - (float)(z * simm.Length * Math.Cos(simm.Angle));
                                        
                    Pen p = new Pen(Color.Black);

                    g.DrawLine(p, zx, zy, e1x, e1y);
                    g.DrawEllipse(p, zx-2, zy-2, 4, 4);
                }
            }
            if (bestsumreward < sumreward)
            {
                bestsumreward = sumreward;
                bm.Save("invertedpendulum.png");
            }

            Console.Out.WriteLine(sumreward);

            return bm;
        }