static void Main(string[] args)
        {
            nn = new NN(2, 1, 1, 4, 1);

            int count = 0;

            double[,] bits = new double[4, 2];
            for (byte b = 0; b < 4; b++)
            {
                bits[b, 0] = GetBit(b, 0) ? 1 : -1;
                bits[b, 1] = GetBit(b, 1) ? 1 : -1;
            }
                        
            double[] input = new double[2];
            
            while (count < 10000)
            {
                input[0] = bits[count%4, 0];
                input[1] = bits[count%4, 1];
                                
                double xor = (input[0] > 0 ^ input[1] > 0) ? 1 : 0;

                double[] answer = nn.FeedForward(input);

                double[] err = { xor - answer[0] };

                nn.BackProp(err);

                Console.WriteLine(xor + "\t" + answer[0].ToString("#.###") + "\t" + err[0].ToString("#.###"));

                count++;
            }
            
            Console.ReadKey();
        }
Exemple #2
0
        public static float LaunchFirst(NN net, int[] layers, float[] chosen)
        {
            StreamReader sk = new StreamReader(@"weightValues1.txt", System.Text.Encoding.GetEncoding(1257));

            net.ReadWeights(sk);
            sk.Close();

            float output = ((net.FeedForward(chosen)[0]) + 1f) * 2.5f; //gaunamas outputas is neural network

            Console.WriteLine("First AI result: {0}", output);

            List <float> possibilities = new List <float>();  //galimos vietos ikelti pamoka

            for (int i = 0; i < 5; i++)
            {
                if (chosen[i * 3 + 2] == 0f || chosen[i * 3] + chosen[i * 3 + 1] == 8f)
                {
                    possibilities.Add(i);
                }

                if (chosen[i * 3 + 2] == 0f && chosen[i * 3] + chosen[i * 3 + 1] == 8f)
                {
                    possibilities.Add(i);
                }
            }

            float nearest = ClosestTo(possibilities, output);

            return(nearest);
        }
Exemple #3
0
        public static int LaunchSecond(NN net, int[] layers, ref string[] chosen, string reference)
        {
            StreamReader sk = new StreamReader(@"weightValues2.txt", System.Text.Encoding.GetEncoding(1257));

            net.ReadWeights(sk);
            sk.Close();

            const int dataCount = 8;                    //kiek pradiniu duomenu

            float[] primalData = new float[dataCount];  //naujas duomenu masyvas NN'ui

            for (int i = 0; i < dataCount; i++)
            {
                primalData[i] = 1f;
            }

            primalData = TurnSecond(chosen, reference);                  //jau suzymetos klases ir langai paverciami i duomenis NN'ui

            float output = ((net.FeedForward(primalData)[0]) + 1f) * 4f; //gaunamas outputas is neural network

            Console.WriteLine("Second AI result: {0}", output);

            List <float> possibilities = new List <float>();      //galimos vietos ikelti pamoka

            for (int j = 0; j < dataCount; j++)
            {
                if (chosen[j] == "-")
                {
                    possibilities.Add(j);     //surenkamos visos tuscios vietos
                }
            }

            float nearest = ClosestTo(possibilities, output);   //surandama artimiausia tuscia vieta pamokai

            return((int)nearest);
        }