예제 #1
0
파일: Test.cs 프로젝트: GWigWam/NeuralNet
        public void TestBias()
        {
            double input = 0.3;
            double inpToOutWeight = 0.4;
            double biasToOutWeight = 0.5;

            var sigmoid = new SigmoidFunction();
            var nw = new Network(sigmoid, false);

            var inputNode = new Input(input);
            var bias = new Bias();
            var outputNode = new Perceptron(sigmoid, "Output");
            Connection.Create(inpToOutWeight, inputNode, outputNode);
            Connection.Create(biasToOutWeight, bias, outputNode);

            nw.Nodes = new Node[][] {
                new Node[] { inputNode },
                new Node[] { outputNode }
            };

            var nwOut = nw.Nodes[1][0].Output;

            //Output
            // = Sig(inpToOut.Output + biasToOut.Output)
            // = Sig((inpToOut.Weight * inpToOut.GetInput()) + (biasToOutWeight * 1))
            // = Sig((inpToOut.Weight * inputNode.Output) + (biasToOutWeight))
            // = Sig((this.weight * this.input) + (biasToOutWeight))
            var expOut = sigmoid.Calculate((inpToOutWeight * input) + biasToOutWeight);

            Assert.AreEqual(nwOut, expOut);
        }
예제 #2
0
파일: Test.cs 프로젝트: GWigWam/NeuralNet
        public void TestConnection()
        {
            double weight = 2;
            double input = 5;
            var inp = new Input(input);
            var outp = new Perceptron(new SigmoidFunction(), "Output");
            var wc = Connection.Create(weight, inp, outp);

            Assert.AreEqual(wc.Output, weight * input);
            Assert.AreEqual(inp.GetOutgoingConnections()[0], outp.GetIncommingConnections()[0]);
        }
예제 #3
0
파일: Test.cs 프로젝트: GWigWam/NeuralNet
        public void TestDelConnection()
        {
            var inp = new Input(5);
            var outp = new Perceptron(new SigmoidFunction());

            var beforeConnect = outp.Output;

            var con = Connection.Create(1, inp, outp);

            outp.ResetCache();
            var afterConnect = outp.Output;

            Assert.AreNotEqual(beforeConnect, afterConnect);

            con.Delete();
            outp.ResetCache();

            Assert.AreEqual(beforeConnect, outp.Output);
        }
예제 #4
0
파일: Test.cs 프로젝트: GWigWam/NeuralNet
        public void TestPerceptronCaching()
        {
            double local1 = -10;
            double local2 = -5;

            var in1 = new Input(local1, "Input1");
            var in2 = new Input(local2, "Input2");
            var p = new Perceptron(new SigmoidFunction());

            Connection.Create(0.5, in1, p);
            Connection.Create(1, in2, p);

            Assert.IsTrue(p.Output < 0.1);

            in1.Value = 10;
            in2.Value = 5;

            Assert.IsTrue(p.Output < 0.1);

            p.ResetCache();

            Assert.IsFalse(p.Output < 0.1);
        }
예제 #5
0
파일: Test.cs 프로젝트: GWigWam/NeuralNet
        public void TestNetworkOutput()
        {
            var rand = new Random();
            double input = (double)(rand.NextDouble());
            double weight = (double)(rand.NextDouble());

            var sigmoid = new SigmoidFunction();
            var nw = new Network(sigmoid, false);

            var inputNode = new Input(input);
            var outputNode = new Perceptron(sigmoid, "Output");
            Connection.Create(weight, inputNode, outputNode);

            nw.Nodes = new Node[][] {
                new Node[] { inputNode },
                new Node[] { outputNode }
            };

            var nwOut = nw.CurOutput()[0];
            Assert.AreEqual(outputNode.Output, nwOut);

            var expOut = sigmoid.Calculate(input * weight);

            Assert.AreEqual(nwOut, expOut);
        }
예제 #6
0
파일: Test.cs 프로젝트: GWigWam/NeuralNet
        public void TestGetInputResult()
        {
            var rand = new Random();
            double input = (double)(rand.NextDouble() * 100 + 1);
            double weight = (double)(rand.NextDouble() * 2);

            var sigmoid = new SigmoidFunction();
            var nw = new Network(sigmoid, false);

            var inputNode = new Input(input);
            var outputNode = new Perceptron(sigmoid, "Output");
            Connection.Create(weight, inputNode, outputNode);

            nw.Nodes = new Node[][] {
                new Node[] { inputNode },
                new Node[] { outputNode }
            };

            var nwOut = nw.GetInputResult(input)[0];

            //Output
            // = Sig(inpToOut.Output)
            // = Sig(inpToOut.Weight * inpToOut.GetInput())
            // = Sig(inpToOut.Weight * inputNode.Output)
            // = Sig(this.weight * this.input)
            var expOut = sigmoid.Calculate(weight * input);

            Assert.AreEqual(nwOut, expOut);
        }