Exemplo n.º 1
0
        public void TrainCorrectThreePasses()
        {
            Layer layer = new Layer(new double[, ] {
                { 1, 1 }
            });
            List <TrainingVector> trainingVectors = new List <TrainingVector>
            {
                new TrainingVector(
                    new NetworkVector(new double[] { 0, 0 }),
                    new NetworkVector(new double[] { 1 })
                    ),
                new TrainingVector(
                    new NetworkVector(new double[] { 1, 0 }),
                    new NetworkVector(new double[] { 0 })
                    ),
                new TrainingVector(
                    new NetworkVector(new double[] { 0, 1 }),
                    new NetworkVector(new double[] { 0 })
                    ),
                new TrainingVector(
                    new NetworkVector(new double[] { 1, 1 }),
                    new NetworkVector(new double[] { 1 })
                    )
            };

            OnlineTrainer trainer = new OnlineTrainer(layer, trainingVectors);

            trainer.Train();
            trainer.Train();
            trainer.Train();

            double[,] weightsCheck = new double[, ] {
                { 3, 7 }
            };
            double[] biasesCheck = new double[] { -1 };

            for (int i = 0; i < layer.NumberOfOutputs; i++)
            {
                Assert.AreEqual(biasesCheck[i], layer.State.Biases[i]);

                for (int j = 0; j < layer.NumberOfInputs; j++)
                {
                    Assert.AreEqual(weightsCheck[i, j], layer.State.Weights[i, j]);
                }
            }
        }
Exemplo n.º 2
0
        public void CanRunOnlineTrainer()
        {
            Layer layer = new Layer(new double[, ] {
                { 1, 1 }
            });
            List <TrainingVector> trainingVectors = new List <TrainingVector>
            {
                new TrainingVector(
                    new NetworkVector(new double[] { 0, 0 }),
                    new NetworkVector(new double[] { 1 })
                    )
            };

            OnlineTrainer trainer = new OnlineTrainer(layer, trainingVectors);

            trainer.Train();
        }