Example #1
0
        static void Main(string[] args)
        {
            double[][] inputs = { new double[] { 0, 0 }, new double[] { 0, 1 }, new double[] { 1, 0 }, new double[] { 1, 1 } };
            double[] targets = { 0, 1, 1, 1 };
            double error = 1;
            int epoch = 0;

            ActivationFunction function = new SigmoidFunction();
            Neuron neuron = new Neuron(2, function);
            LearningStrategy learning = new DeltaRuleLearning(neuron, 0.75);

            while (error > 0.01)
            {
                error = learning.RunEpoch(inputs, targets);
                epoch++;
                Console.WriteLine("Iteration {0} error: {1}", epoch, error);
            }
            Console.WriteLine("Training complete after {0} epochs using the Delta Rule learning regime.", epoch);
            Console.WriteLine("Testing");
            neuron.Update(new double[] { 0, 0 });
            Console.WriteLine("{0}", neuron.Output);
            neuron.Update(new double[] { 0, 1 });
            Console.WriteLine("{0}", neuron.Output);
            neuron.Update(new double[] { 1, 0 });
            Console.WriteLine("{0}", neuron.Output);
            neuron.Update(new double[] { 1, 1 });
            Console.WriteLine("{0}", neuron.Output);
        }
Example #2
0
        public void NeuronUpdate_UpdatesOutputAndReturnsValue()
        {
            ActivationFunction sigmoidFunction = new SigmoidFunction();
            Neuron sigmoidNeuron = new Neuron(3, sigmoidFunction);

            double[] input = new double[] { 0.3, 0.2, 0.1 };
            double expected = 0.512497396484;

            sigmoidNeuron[0] = 0.1;
            sigmoidNeuron[1] = 0.2;
            sigmoidNeuron[2] = 0.3;
            sigmoidNeuron.Bias = -0.05;

            double actual = sigmoidNeuron.Update(input);
            double neuronOutput = sigmoidNeuron.Output;

            Assert.AreEqual(expected, actual, 0.0001, "Invalid neuron output");
            Assert.AreEqual(expected, neuronOutput, 0.0001, "Invalid neuron output");
        }