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 SplitData()
        {
            // Arrange
            ANeuralNetwork        ANN      = new ANeuralNetwork();
            List <List <double> > TestData = new List <List <double> > {
                new List <double> {
                    1, 2, 3, 4
                }, new List <double> {
                    5, 6, 7, 8
                }
            };
            List <List <List <double> > > ExpectedOutput = new List <List <List <double> > > {
                new List <List <double> > {
                    new List <double> {
                        1, 2
                    }
                }, new List <List <double> > {
                    new List <double> {
                        3, 4
                    }
                }, new List <List <double> > {
                    new List <double> {
                        5, 6
                    }
                }, new List <List <double> > {
                    new List <double> {
                        7, 8
                    }
                }
            };

            // Act
            ANN.Create_Network(new List <int> {
                2, 1, 2
            });
            List <List <List <double> > > Output = ANN.SplitDataSet(TestData, 1);

            // Assert
            bool ItemsMatch = true;

            for (int ItemInOutput = 0; ItemInOutput < Output.Count; ItemInOutput++)
            {
                for (int row = 0; row < Output[ItemInOutput].Count; row++)
                {
                    for (int column = 0; column < Output[ItemInOutput][row].Count; column++)
                    {
                        Console.Write(Output[ItemInOutput][row][column] + " ");
                        if (ExpectedOutput[ItemInOutput][row][column] != Output[ItemInOutput][row][column])
                        {
                            ItemsMatch = false;
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
            Assert.IsTrue(ItemsMatch);
        }
        public void SaveNetwork()
        {
            // Arrange
            ANeuralNetwork ANN = new ANeuralNetwork();

            ANN.Create_Network(new List <int> {
                2, 3, 1
            });
            Exception expectedException = null;

            // Act
            try
            {
                ANN.Save_Network("TestSave.net");
            }
            catch (Exception ex)
            {
                expectedException = ex;
            }

            // Assert
            Assert.IsNull(expectedException);
        }
Beispiel #4
0
        // Usfule functions for interacting with NeuralNet

        public void CreateNetwork(List <int> Description)
        {
            ANN.Create_Network(Description);
        }