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 Layer(int neuronCount, int inputCount, ActivationFunction function)
        {
            _inputCount = inputCount;
            _neuronCount = neuronCount;

            _neurons = new Neuron[neuronCount];
            for(int i = 0; i < neuronCount; i++)
            {
                _neurons[i] = new Neuron(inputCount, function);
            }
        }
Example #3
0
        public void NeuronActivation_ReturnsNeuronActivation()
        {
            ActivationFunction sigmoidFunction = new SigmoidFunction();
            Neuron sigmoidNeuron = new Neuron(3, sigmoidFunction);

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

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

            double actual = sigmoidNeuron.Activation(input);

            Assert.AreEqual(expected, actual, 0.0001, "Invalid neuron activation");
        }
Example #4
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 ThresholdFunction();
            Neuron neuron = new Neuron(2, function);
            LearningStrategy learning = new PerceptronLearning(neuron, 0.25);

            while(error > 0)
            {
                error = learning.RunEpoch(inputs, targets);
                epoch++;
                logger.InfoFormat("Iteration {0} error: {1}", epoch, error);
            }
            logger.InfoFormat("Training complete after {0} epochs using the Perceptron learning regime.", epoch);
        }
Example #5
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");
        }
 public PerceptronLearning(Neuron neuron, double learningRate)
 {
     Neuron = neuron;
     LearningRate = learningRate;
 }
Example #7
0
 public NeuralConnection(Neuron input_, Neuron output_, float startWage)
 {
     input  = input_;
     output = output_;
     wage   = startWage;
 }