public void Test_NeuralNetworkLogic() { INeuralNetworkBuilder <double> builder = new SigmoidNeuralNetworkBuilder <GeneticTrainingNeuralNetwork>(); builder.BuildNetwork(2, new int[] { 3 }, 1); INeuralNetwork <double> network = builder.InitializeNeuralNetworkWithData( new double[] { 1, 1 }, null, null); // First Hidden Layer network.HiddenLayers.ElementAt(0)[0].Inputs.ElementAt(0).DendriteWeight.Weight = 0.8; network.HiddenLayers.ElementAt(0)[0].Inputs.ElementAt(1).DendriteWeight.Weight = 0.2; network.HiddenLayers.ElementAt(0)[1].Inputs.ElementAt(0).DendriteWeight.Weight = 0.4; network.HiddenLayers.ElementAt(0)[1].Inputs.ElementAt(1).DendriteWeight.Weight = 0.9; network.HiddenLayers.ElementAt(0)[2].Inputs.ElementAt(0).DendriteWeight.Weight = 0.3; network.HiddenLayers.ElementAt(0)[2].Inputs.ElementAt(1).DendriteWeight.Weight = 0.5; // Output Nueron network.Output.Neurons.ElementAt(0)[0].DendriteWeight.Weight = 0.3; network.Output.Neurons.ElementAt(0)[0].DendriteWeight.Weight = 0.5; network.Output.Neurons.ElementAt(0)[0].DendriteWeight.Weight = 0.9; // Run sigmoid function network.Pulse(null); ; }
static void Main(string[] args) { INeuralNetworkBuilder <double> builder = new DoubleNeuralNetworkBuilder <BackPropagationNeuralNetwork>(); builder.BuildNetwork(2, new int[] { 10, 20 }, 1); // no hidden layers INeuralNetwork <double> network = InitializeNeuralNetworkStartingValues(builder); int iterations = 100; double[][] input = GetInput(iterations); double[][] output = GetAdditionOutput(input); bool countedRight = false; Random rand = new Random(); int iteration = 1; while (!countedRight) { Console.WriteLine($"Iteration: { iteration }"); for (int i = 0; i < iterations; ++i) { (network as BackPropagationNeuralNetwork).Train(input, output); } int value1 = rand.Next(10); Console.WriteLine($"Value1 = { value1 }"); int value2 = rand.Next(10); Console.WriteLine($"Value2 = { value2 }"); int sum = value1 + value2; Console.WriteLine($"Sum = { sum }"); network.ApplyLearning(null); network.Input[0].Value = value1; network.Input[1].Value = value2; network.Pulse(null); double networkOutput = network.Output[0].Value; Console.WriteLine($"Neural Network output value = { networkOutput }"); Console.WriteLine($"End of iteration { iteration }"); Console.WriteLine("============================================================================"); iteration++; if (sum == networkOutput) { countedRight = true; } } Console.ReadKey(); }
static void Main(string[] args) { INeuralNetworkBuilder <double> builder = new SigmoidNeuralNetworkBuilder <GeneticTrainingNeuralNetwork>(); builder.BuildNetwork(9, null, 1); // no hidden layers INeuralNetwork <double> network = builder.InitializeNeuralNetworkWithData(new double[] { 2, 0, 1, 0, 1, 0, 2, 0, 0 }, null, null); network.LearningRate = 0.1; for (int i = 0; i < 10000; ++i) { // Calculates Sigmoid Neurons value. network.Pulse(null); // Function prepared for Genetic Training of Feed Forward Network network.ApplyLearning(null); } }