Exemple #1
0
        public void TestLayersInitializers()
        {
            var layer   = new Layer(3, new SigmoidFunction(), new UnbiasedUtility());
            var network = new Network(2);

            network.AddLayer(layer);
        }
Exemple #2
0
        public void TestGetOutputTransform()
        {
            //            var layer1 = new Layer(2, new SigmoidFunction(), new BiasedUtility());
            var layer2 = new Layer(3, new SigmoidFunction(), new BiasedUtility());
            var layer3 = new Layer(4, new SigmoidFunction(), new BiasedUtility());

            var network = new Network(4);

            //            network.AddLayer(layer1);
            network.AddLayer(layer2);
            network.AddLayer(layer3);
            //            var input = new double[,] { { 2, 3, 1 }, { 4, 2, 1 } };
            //layer1.WeightMatrix = Matrix<double>.Build.DenseOfArray(input);
            //layer2.WeightMatrix = Matrix<double>.Build.DenseOfArray(new double[,] { { 1, 1, 1 } });
            var trainingElems = new List <TrainingElement>();

            trainingElems.Add(new TrainingElement(new double[, ] {
                { 1 }, { 0 }, { 0 }, { 0 }
            }, new double[, ] {
                { 1 }, { 0 }, { 0 }, { 0 }
            }));

            trainingElems.Add(new TrainingElement(new double[, ] {
                { 0 }, { 1 }, { 0 }, { 0 }
            }, new double[, ] {
                { 0 }, { 1 }, { 0 }, { 0 }
            }));

            trainingElems.Add(new TrainingElement(new double[, ] {
                { 0 }, { 0 }, { 1 }, { 0 }
            }, new double[, ] {
                { 0 }, { 0 }, { 1 }, { 0 }
            }));

            trainingElems.Add(new TrainingElement(new double[, ] {
                { 0 }, { 0 }, { 0 }, { 1 }
            }, new double[, ] {
                { 0 }, { 0 }, { 0 }, { 1 }
            }));

            network.Train(0.5, 1000, 0.85, trainingElems);
            var kupa0 = network.ForwardPropagation(Matrix <double> .Build.DenseOfArray(new double[, ] {
                { 1 }, { 0 }, { 0 }, { 0 }
            }));

            Console.WriteLine($"5 300 1 1 {kupa0}");
            var kupa1 = network.ForwardPropagation(Matrix <double> .Build.DenseOfArray(new double[, ] {
                { 0 }, { 1 }, { 0 }, { 0 }
            }));

            Console.WriteLine($"0 1 {kupa1}");
            var kup2a = network.ForwardPropagation(Matrix <double> .Build.DenseOfArray(new double[, ] {
                { 0 }, { 0 }, { 1 }, { 0 }
            }));

            Console.WriteLine($"1 0 {kup2a}");
            var kupa3 = network.ForwardPropagation(Matrix <double> .Build.DenseOfArray(new double[, ] {
                { 0 }, { 0 }, { 0 }, { 1 }
            }));

            Console.WriteLine($"0 0 {kupa3}");
        }