public void TrainMiniBatch_XORGateTest_SingleBatch()
        {
            // Arrange
            ANeuralNetwork ANN = new ANeuralNetwork();

            ANN.Create_Network(new List <int> {
                2, 3, 1
            });
            List <List <double> > InputData = new List <List <double> > {
                new List <double> {
                    1, 1
                }, new List <double> {
                    0, 1
                }, new List <double> {
                    1, 0
                }, new List <double> {
                    0, 0
                },
            };
            List <List <double> > OutputData = new List <List <double> > {
                new List <double> {
                    0
                }, new List <double> {
                    1
                }, new List <double> {
                    1
                }, new List <double> {
                    0
                }
            };
            List <List <double> > ValidationData = new List <List <double> > {
                new List <double> {
                    1, 1
                }, new List <double> {
                    0, 1
                }, new List <double> {
                    1, 0
                }, new List <double> {
                    0, 0
                },
            };
            List <double> ExpectedOutput = new List <double> {
                0, 1, 1, 0
            };

            // Act
            ANN.Train_MiniBatch(InputData, OutputData, InputData.Count, "XOR_SinleBatch.dat");
            List <double> Results = new List <double> {
            };

            for (int i = 0; i < 4; i++)
            {
                List <double> result = ANN.Get_Network_Output(ValidationData[i]);
                Results.Add(Math.Round(result[0], 0));
                Console.Write("Output = " + Results[i] + " ");
            }

            // Assert
            CollectionAssert.AreEqual(ExpectedOutput, Results);
        }
        public void TrainMiniBatch_ConvergenceTest_ValuesNOT01()
        {
            // Arrange
            ANeuralNetwork ANN = new ANeuralNetwork();

            ANN.Load_Network("Test.net");
            List <List <double> > InputData = new List <List <double> > {
                new List <double> {
                    10, 10
                }
            };
            List <List <double> > OutputData = new List <List <double> > {
                new List <double> {
                    10
                }
            };

            // Act
            ANN.Train_MiniBatch(InputData, OutputData, InputData.Count, "MiniBatch_Convergence.dat");
            List <double> Result = ANN.Get_Network_Output(InputData[0]);

            // Assert
            Console.Write("Output = " + Result[0]);
            Assert.AreNotEqual(OutputData[0][0], Math.Round(Result[0], 1));
        }
Пример #3
0
        public void UpdateNetwork()
        {
            List <List <double> > TrainingInputs = new List <List <double> > {
            };
            List <List <double> > TrainingOutput = new List <List <double> > {
            };

            for (int Row = 0; Row < EpisodeData.Count; Row++)
            {
                List <List <double> > SymertrisedRow = SymertriseData(EpisodeData[Row]);
                for (int DataRow = 0; DataRow < SymertrisedRow.Count; DataRow++)
                {
                    List <List <double> > Results = SplitInputsFromOutputs(SymertrisedRow[DataRow], 9);
                    TrainingInputs.Add(Results[0]);
                    TrainingOutput.Add(Results[1]);
                }
            }

            ANN.Train_MiniBatch(TrainingInputs, TrainingOutput, TrainingInputs.Count, "QlearnTraining.txt", 0.001, 0.7, 1e6, 1e-8, false);
            EpisodeData.Clear();
        }