public void ThresholdOutput_ReturnsStepValue()
        {
            ActivationFunction thresholdFunction = new ThresholdFunction();
            double input1 = -1;
            double input2 = 0;
            double input3 = 1;
            double expected1 = 0;
            double expected2 = 1;
            double expected3 = 1;
            double actual1 = thresholdFunction.Output(input1);
            double actual2 = thresholdFunction.Output(input2);
            double actual3 = thresholdFunction.Output(input3);

            Assert.AreEqual(expected1, actual1, 0.0001, "Invalid threshold output");
            Assert.AreEqual(expected2, actual2, 0.0001, "Invalid threshold output");
            Assert.AreEqual(expected3, actual3, 0.0001, "Invalid threshold output");
        }
Exemplo n.º 2
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);
        }