Exemplo n.º 1
0
        public void Example_2_1_a_TestMethod()
        {
            double[,] w = new double[1, 3];
            w[0, 0]     = 0.5;
            w[0, 1]     = 1.5;
            w[0, 2]     = -1;
            Perceptron p = new Perceptron(w, Activation.Threshold, 0);

            double[] x = new double[2];
            x[0] = 0.7;
            x[1] = 2.5;
            double[] result   = p.Calc(x);
            double   actual   = result[0];
            double   expected = 0;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void Example_2_1_c_TestMethod()
        {
            double[,] w = new double[1, 3];
            w[0, 0]     = -0.2;
            w[0, 1]     = 0.03;
            w[0, 2]     = 1.2;
            Perceptron p = new Perceptron(w, Activation.Linear);

            double[] x = new double[2];
            x[0] = 0.7;
            x[1] = 2.5;
            double[] result   = p.Calc(x);
            double   actual   = result[0];
            double   expected = 2.82;

            Assert.AreEqual(expected, actual, 0.01);
        }
Exemplo n.º 3
0
        public void SaveLoadBinPerceptronTestMethod()
        {
            double[,] w = new double[1, 3];
            w[0, 0]     = 0.5;
            w[0, 1]     = 1.5;
            w[0, 2]     = -1;
            Perceptron p = new Perceptron(w, Activation.Threshold, 0);

            p.Save(@"C:\Users\super_be\Source\Repos\Neuron.Net\Neuron.Net\Neuron.Net\Neuron.Net.Core.Tests\Data\Test.nnp");
            Perceptron n = Perceptron.Load(@"C:\Users\super_be\Source\Repos\Neuron.Net\Neuron.Net\Neuron.Net\Neuron.Net.Core.Tests\Data\Test.nnp");

            double[] x = new double[2];
            x[0] = 0.7;
            x[1] = 2.5;
            double[] result   = n.Calc(x);
            double   actual   = result[0];
            double   expected = 0;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void Example_2_2_1_TestMethod()
        {
            double[,] w = new double[2, 3];
            w[0, 0]     = 1.5;
            w[0, 1]     = -1.0;
            w[0, 2]     = -1.0;
            w[1, 0]     = 0.5;
            w[1, 1]     = -1.0;
            w[1, 2]     = -1.0;
            Perceptron p = new Perceptron(w, Activation.Threshold, 0);

            double[,] w1 = new double[1, 3];
            w1[0, 0]     = -0.5;
            w1[0, 1]     = 1.0;
            w1[0, 2]     = -1.0;
            Perceptron p1 = new Perceptron(w1, Activation.Threshold, 0);

            double[] x = new double[2];
            x[0] = 1;
            x[1] = 1;
            double[] result   = p.Calc(x);
            double   actual   = result[0];
            double   expected = 0;

            Assert.AreEqual(expected, actual);
            actual   = result[1];
            expected = 0;
            Assert.AreEqual(expected, actual);
            double[] result1 = p1.Calc(result);
            actual   = result1[0];
            expected = 0;
            Assert.AreEqual(expected, actual);

            x[0]     = 1;
            x[1]     = 0;
            result   = p.Calc(x);
            actual   = result[0];
            expected = 1;
            Assert.AreEqual(expected, actual);
            actual   = result[1];
            expected = 0;
            Assert.AreEqual(expected, actual);
            result1  = p1.Calc(result);
            actual   = result1[0];
            expected = 1;
            Assert.AreEqual(expected, actual);

            x[0]     = 0;
            x[1]     = 1;
            result   = p.Calc(x);
            actual   = result[0];
            expected = 1;
            Assert.AreEqual(expected, actual);
            actual   = result[1];
            expected = 0;
            Assert.AreEqual(expected, actual);
            result1  = p1.Calc(result);
            actual   = result1[0];
            expected = 1;
            Assert.AreEqual(expected, actual);

            x[0]     = 0;
            x[1]     = 0;
            result   = p.Calc(x);
            actual   = result[0];
            expected = 1;
            Assert.AreEqual(expected, actual);
            actual   = result[1];
            expected = 1;
            Assert.AreEqual(expected, actual);
            result1  = p1.Calc(result);
            actual   = result1[0];
            expected = 0;
            Assert.AreEqual(expected, actual);
        }