public void Train_RuningTraining_NetworkIsTrained() { var network = new SimpleNeuralNetwork(3); var layerFactory = new NeuralLayerFactory(); network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFuncion(), new WeightedSumFunction())); network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(0.7), new WeightedSumFunction())); network.PushExpectedValues( new double[][] { new double[] { 0 }, new double[] { 1 }, new double[] { 1 }, new double[] { 0 }, new double[] { 1 }, new double[] { 0 }, new double[] { 0 }, }); network.Train( new double[][] { new double[] { 150, 2, 0 }, new double[] { 1002, 56, 1 }, new double[] { 1060, 59, 1 }, new double[] { 200, 3, 0 }, new double[] { 300, 3, 1 }, new double[] { 120, 1, 0 }, new double[] { 80, 1, 0 }, }, 10000); network.PushInputValues(new double[] { 1054, 54, 1 }); var outputs = network.GetOutput(); }
public void PushExpectedResults_ValuesSentToNetwork_ValuesStored() { var network = new SimpleNeuralNetwork(3); network.PushExpectedValues(new double[][] { new double[] { 3, 5, 7 } }); Assert.AreEqual(3, network._expectedResult[0][0]); Assert.AreEqual(5, network._expectedResult[0][1]); Assert.AreEqual(7, network._expectedResult[0][2]); }
static void Main(string[] args) { var network = new SimpleNeuralNetwork(1); var layerFactory = new NeuralLayerFactory(); network.AddLayer(layerFactory.CreateNeuralLayer(2, new RectifiedActivationFuncion(), new WeightedSumFunction())); network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(0.4), new WeightedSumFunction())); double[][] expectedValues = new double[samples][]; double[][] trainingValues = new double[samples][]; for (int i = 0; i < samples; i++) { Random rng = new Random(); Random rng2 = new Random(); int val1 = rng.Next(rng.Next() % 1000); int val2 = rng2.Next(i % 900); expectedValues[i] = new double[] { (val1 + val2) % 2 }; trainingValues[i] = new double[] { val1, val2 }; Console.WriteLine($"val1: {val1} val2: {val2} sum: { (val1 + val2) % 2 }"); } network.PushExpectedValues(expectedValues); network.Train(trainingValues, 5000); network.PushInputValues(new double[] { 1054, 54 }); var outputs = network.GetOutput(); Console.WriteLine($"network output: {string.Join(", ", outputs)}"); Console.ReadKey(); }
public void TrainNetwork_6Inputs_3HiddenLayer_2Outputs() { var network = new SimpleNeuralNetwork(6, 1.95); // six input nuerons var layerFactory = new NeuralLayerFactory(); network.AddLayer(layerFactory.CreateNeuralLayer(3, new SigmoidActivationFunction(0.7), new WeightedSumFunction())); // three hidden layers network.AddLayer(layerFactory.CreateNeuralLayer(2, new LazyOutputFunction(), new WeightedSumFunction())); // two output layers network.PushExpectedValues( new double[][] { new double[] { 0.25, 0.20 }, new double[] { 0.10, 0.05 }, new double[] { 0.16, 0.30 }, new double[] { 0.30, 0.10 }, new double[] { 0.25, 0.20 }, new double[] { 0.10, 0.05 }, new double[] { 0.16, 0.30 }, new double[] { 0.30, 0.10 }, }); network.Train( new double[][] { new double[] { 150, 0, 0, 34, 35, 56 }, new double[] { 190, 23, 56, 0, 29, 529 }, new double[] { 290, 3, 108, 24, 189, 20 }, new double[] { 290, 67, 6, 0, 1, 0 }, new double[] { 150, 0, 0, 34, 35, 56 }, new double[] { 190, 23, 56, 0, 29, 529 }, new double[] { 290, 3, 108, 24, 189, 20 }, new double[] { 290, 67, 6, 0, 1, 0 }, }, 10000); network.PushInputValues(new double[] { 150, 0, 0, 34, 35, 56 }); var outputs = network.GetOutput(); Console.WriteLine(outputs[0].ToString() + " " + outputs[1].ToString() + "\n\n" + JsonConvert.SerializeObject(network, Formatting.Indented)); }