コード例 #1
0
        public static void SimpleTetris()
        {
            Random    rnd   = new Random();
            SimpleNet Kevin = new SimpleNet(0.05, 281, 500, 5);

            Kevin.SetAfT(1, 2);
            Kevin.SetAfNames(AF.Tanh, AF.Sigmoid);
            Kevin.SetAfT(2, 1);


            while (true)
            {
                Console.Clear();
                Tetris.MapAktualisieren(true);


                while (Tetris.leben && Tetris.sinnloseBewegung < 350)
                {
                    Kevin.SetInput(Tetris.GetType2V());
                    Kevin.NeuronValue[0][280] = rnd.NextDouble() * 20 - 10;
                    Kevin.OutputBerechnen();


                    Tetris.BewegungShow(Kevin.GetOutput(), 0.7);

                    //if ((Tetris.sinnloseBewegung + 1) % 70 == 0)
                    //{
                    //    Kevin.ReinforcementLearning(-0.01);
                    //}


                    if (Tetris.punkte != 0)
                    {
                        Kevin.ReinforcementLearning(Tetris.punkte, false);
                    }



                    Console.SetCursorPosition(0, 0);
                    ArrayAusgeben(Kevin.GetOutput());
                    Console.Write(Tetris.punkte);



                    //Console.SetCursorPosition(0, 35);
                    //Console.Write(TetrisKI[iKi].ToString());


                    Tetris.punkte = 0;
                }

                System.Threading.Thread.Sleep(100);
                Kevin.ReinforcementLearning(-1, false);


                Tetris.AllesReset();
            }
        }
コード例 #2
0
ファイル: Counter.cs プロジェクト: Orgondor/Fintastic
    private void OnTriggerEnter(Collider other)
    {
        //TODO specify type of fish and change in CompareTag()
        //declare own variable for that
        bool correctFish = true;

        if (other.CompareTag("Net") && correctFish)
        {
            SimpleNet net = other.GetComponentInChildren <SimpleNet>();
            if (net && net.caughtFish)
            {
                fishCaught++;
                counter_text.text = fishCaught.ToString();
                net.Deliver();
            }
            //TODO let fish appear inside of basket
            //TODO remove fish from net
        }
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: Leep233/DeepLearning
        static void TestSimpleNet()
        {
            Matrix x = new Matrix(new double[, ] {
                { 0.6, 0.9 }
            });

            Matrix t = new Matrix(new double[, ] {
                { 0, 0, 1 }
            });

            SimpleNet net = new SimpleNet(x, t);

            Console.WriteLine(net.Predict());

            Console.WriteLine($"损失值:{net.Loss(t)}");

            Matrix dw = CommonFunctions.Gradient(net.Loss, net.w);

            Console.WriteLine($"{dw}");
        }
コード例 #4
0
        public static void SimplesSpielStart()
        {
            Q_Learning Tim3 = new Q_Learning(0.96, 0.1, 4, 0);

            SimplesSpiel.Setup(5, 5, 0, 1);
            int       action;
            SimpleNet Prediction = new SimpleNet(4, 29, 30, 25);

            Prediction.SetAfNames(AF.Linear, AF.Sigmoid, AF.Sigmoid);
            Prediction.SetAfT(1, 1);
            Prediction.SetAfT(2, 1);

            for (int i = 0; i < 100000; ++i)
            {
                double[] arrAckt = new double[4];

                if (SimplesSpiel.punkte == 0 && i > 0)
                {
                    Prediction.DeltawertBerechen((double[])SimplesSpiel.GetMap().Clone());
                    Prediction.Backpropagation();
                }


                action = Tim3.Get_SetAction(SimplesSpiel.GetPlayerPos(), SimplesSpiel.punkte);

                arrAckt[action] = 1;
                if (SimplesSpiel.punkte == 0)
                {
                    Prediction.SetInput(arrAckt.Concat(SimplesSpiel.GetMap()).ToArray());
                }
                Prediction.OutputBerechnen();

                SimplesSpiel.punkte = 0;
                SimplesSpiel.PlayerBewegen(action);
                SimplesSpiel.ExtraMapAusgeben(Prediction.GetOutput());


                //System.Threading.Thread.Sleep(10);
            }

            for (int i = 0; i < 5000; ++i)
            {
                action = Tim3.Get_SetAction(SimplesSpiel.GetPlayerPos(), SimplesSpiel.punkte);
                SimplesSpiel.punkte = 0;
                SimplesSpiel.PlayerBewegen(action);
                System.Threading.Thread.Sleep(100);
            }

            Console.ResetColor();
            while (true)
            {
                Console.SetCursorPosition(14, 0);
                Console.Write("  ");
                Console.SetCursorPosition(14, 1);
                Console.Write("  ");
                Console.SetCursorPosition(0, 0);
                Console.Write("X-Koordinate: ");
                sbyte x = Convert.ToSByte(Console.ReadLine());
                Console.Write("Y-Koordinate: ");
                sbyte y = Convert.ToSByte(Console.ReadLine());

                Q_State state = Tim3.Q_Table[new SimplesSpiel.SimplPos(x, y)];

                Console.SetCursorPosition(40, 4);
                Console.Write(Math.Round(state.actionReward[1]) + "    ");

                Console.SetCursorPosition(50, 4);
                Console.Write(Math.Round(state.actionReward[0]) + "    ");

                Console.SetCursorPosition(45, 1);
                Console.Write(Math.Round(state.actionReward[2]) + "    ");

                Console.SetCursorPosition(45, 7);
                Console.Write(Math.Round(state.actionReward[3]) + "    ");
            }
        }
コード例 #5
0
            public static void Run(int durchlaufe, int ausgebenPro)
            {
                double    Fehler   = 0;
                SimpleNet Chantall = new SimpleNet(0.1, 784, 30, 20, 10);

                Chantall.SetAfNames(AF.Sigmoid, "n", "n", "n");
                Chantall.SetAfT(1, 1);
                Chantall.SetAfT(2, 1);
                Chantall.SetAfT(3, 1);

                FileStream ifsLabels = new FileStream(@"C:\Users\Gregor\DATENBSNKEBN\train-labels.idx1-ubyte", FileMode.Open); // test labels
                FileStream ifsImages = new FileStream(@"C:\Users\Gregor\DATENBSNKEBN\train-images.idx3-ubyte", FileMode.Open); // test images

                BinaryReader brLabels = new BinaryReader(ifsLabels);
                BinaryReader brImages = new BinaryReader(ifsImages);

                int magic1    = brImages.ReadInt32(); // discard
                int numImages = brImages.ReadInt32();
                int numRows   = brImages.ReadInt32();
                int numCols   = brImages.ReadInt32();

                int magic2    = brLabels.ReadInt32();
                int numLabels = brLabels.ReadInt32();

                byte[][] pixels = new byte[28][];
                for (int i = 0; i < pixels.Length; ++i)
                {
                    pixels[i] = new byte[28];
                }

                for (int i = 1; i < durchlaufe; ++i)
                {
                    if (i % 60000 == 0)
                    {
                        ifsImages.Close();
                        brImages.Close();
                        ifsLabels.Close();
                        brLabels.Close();
                        ifsLabels = new FileStream(@"C:\Users\Gregor\memBrain\train-labels.idx1-ubyte", FileMode.Open); // test labels
                        ifsImages = new FileStream(@"C:\Users\Gregor\memBrain\train-images.idx3-ubyte", FileMode.Open); // test images

                        brLabels = new BinaryReader(ifsLabels);
                        brImages = new BinaryReader(ifsImages);

                        magic1    = brImages.ReadInt32(); // discard
                        numImages = brImages.ReadInt32();
                        numRows   = brImages.ReadInt32();
                        numCols   = brImages.ReadInt32();

                        magic2    = brLabels.ReadInt32();
                        numLabels = brLabels.ReadInt32();

                        pixels = new byte[28][];
                        for (int j = 0; j < pixels.Length; ++j)
                        {
                            pixels[j] = new byte[28];
                        }
                    }

                    for (int i1 = 0; i1 < 28; ++i1)
                    {
                        for (int j = 0; j < 28; ++j)
                        {
                            byte b = brImages.ReadByte();
                            pixels[i1][j] = b;
                        }
                    }

                    byte lbl = brLabels.ReadByte();


                    double[] erwrteterOutput = new double[10];

                    erwrteterOutput[lbl] = 1;

                    Chantall.SetInput(ConvertD(pixels));
                    Chantall.OutputBerechnen();
                    Chantall.DeltawertBerechen(erwrteterOutput);
                    Chantall.Backpropagation();

                    Fehler += Chantall.GetFehlerDif(erwrteterOutput);

                    if (i % ausgebenPro == 0)
                    {
                        Fehler /= ausgebenPro;
                        DigitImage dImage = new DigitImage(pixels, lbl);
                        Console.WriteLine(dImage.ToString());
                        ZweiArrayAusgeben(erwrteterOutput, Chantall.GetOutput());
                        Console.WriteLine("Treffer Quote: {0}", 100 - (Fehler * 10));
                        Console.WriteLine(Chantall.ToString());
                        Chantall.Etha = Fehler;

                        Fehler = 0;
                    }
                }
            }