예제 #1
0
        public static void Main(string[] args)
        {
            NNet xor = new NNet(1)
            {
                Input   = Vector.FromArray(new[] { 1.0, 0.0 }),
                Weights = new[]
                {
                    new Matrix().FromArray(new[, ]
                    {
                        { 0.9, 0.2 },
                        { 0.3, 0.8 },
                    }),
                    new Matrix().FromArray(new[, ]
                    {
                        { 0.7, 0.6 },
                        //{ 0.3 }, //, 0.8 },
                    }),
                }
            };

            xor.FeedForward();
            Console.WriteLine($"XOR: {xor.Output}");
//			Console.WriteLine(xor);
            xor.BackPropogate(new[] { 0.9 });             // Expect 1 (becomes 0.9).
            xor.FeedForward();
//			Console.WriteLine(xor);
            Console.WriteLine($"XOR: {xor.Output}");

//			xor.FeedForward();
//			Console.WriteLine($"XOR: {xor.Output}");
            for (int i = 0; i < 10000; i++)
            {
                xor.FeedForward();
                xor.BackPropogate(new[] { 0.9 });                 // Expect 0 (becomes 0.1).
            }

//
            xor.FeedForward();
            Console.WriteLine($"XOR: {xor.Output}");

            NeuralNetwork nn = new NeuralNetwork(new[]
            {
                new Matrix().FromArray(new[, ]
                {
                    { 0.9, 0.2, -0.4 },
                    { -0.3, 0.8, -0.9 },
                    { -0.4, 0.9, 0.3 },
                }),
                new Matrix().FromArray(new[, ]
                {
                    { 0.7, -0.6, -0.2, 0.4 },
                    //{ 0.3 }, //, 0.8 },
                }),
            });

            Console.WriteLine(nn.FeedForward((Vector) new VectorBuilder <Vector> {
                1.0, 1.0
            }.Get()));
            for (int i = 0; i < 100000; i++)
            {
                nn.Epoch(new[] { 1.0, 1.0 }, new[] { 0.1 });
            }
            Console.WriteLine(nn.FeedForward((Vector) new VectorBuilder <Vector> {
                1.0, 1.0
            }.Get()));

            Console.WriteLine(" NEURAL NET BELOW");
            Console.WriteLine(nn);
//			for (int i = 0; i < 10000; i++)
//			{
////				nn.Epoch(new[] { 0.0, 0.0 }, new[] { 0.1 });
//				nn.Epoch(new[] { 1.0, 0.0 }, new[] { 0.9 });
//				nn.Epoch(new[] { 0.0, 1.0 }, new[] { 0.9 });
////				nn.Epoch(new[] { 1.0, 1.0 }, new[] { 0.1 });
//			}
//
//			Console.WriteLine(" ~~~~~ ");
//			Console.WriteLine(nn.FeedForward((Vector) new VectorBuilder<Vector> { 0.0, 0.0 }.Get()));
//			Console.WriteLine(nn.FeedForward((Vector) new VectorBuilder<Vector> { 1.0, 0.0 }.Get()));
//			Console.WriteLine(nn.FeedForward((Vector) new VectorBuilder<Vector> { 0.0, 1.0 }.Get()));
//			Console.WriteLine(nn.FeedForward((Vector) new VectorBuilder<Vector> { 1.0, 1.0 }.Get()));
        }