public void Complex_WeightOne()
        {
            var connList = new List <WeightedDirectedConnection <double> >
            {
                new WeightedDirectedConnection <double>(0, 4, 1.0),
                new WeightedDirectedConnection <double>(1, 4, 1.0),
                new WeightedDirectedConnection <double>(1, 5, 1.0),
                new WeightedDirectedConnection <double>(3, 4, 1.0),
                new WeightedDirectedConnection <double>(4, 2, 0.9),
                new WeightedDirectedConnection <double>(5, 3, 1.0)
            };

            // Create graph.
            var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connList, 2, 2);

            // Create neural net and run tests.
            var actFn = new Logistic();
            var net   = new NeuralNetAcyclic(digraph, actFn.Fn);

            Complex_WeightOne_Inner(net, actFn);

            // Create vectorized neural net and run tests.
            var vnet = new NeuralNet.Double.Vectorized.NeuralNetAcyclic(digraph, actFn.Fn);

            Complex_WeightOne_Inner(vnet, actFn);
        }
        public void DepthNodeReorderTest()
        {
            // Define graph connections.
            var connList = new LightweightList <WeightedDirectedConnection <double> >
            {
                new WeightedDirectedConnection <double>(0, 4, 0.0),
                new WeightedDirectedConnection <double>(4, 5, 1.0),
                new WeightedDirectedConnection <double>(5, 2, 2.0),
                new WeightedDirectedConnection <double>(1, 2, 3.0),
                new WeightedDirectedConnection <double>(2, 3, 4.0)
            };

            // Create graph.
            var connSpan = connList.AsSpan();

            connSpan.Sort(WeightedDirectedConnectionComparer <double> .Default);
            var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connSpan, 2, 2);

            // The nodes should have IDs allocated based on depth, i.e. the layer they are in.
            // And connections should be ordered by source node ID.
            var connListExpected = new LightweightList <WeightedDirectedConnection <double> >
            {
                new WeightedDirectedConnection <double>(0, 2, 0.0),
                new WeightedDirectedConnection <double>(1, 4, 3.0),
                new WeightedDirectedConnection <double>(2, 3, 1.0),
                new WeightedDirectedConnection <double>(3, 4, 2.0),
                new WeightedDirectedConnection <double>(4, 5, 4.0)
            };

            // Compare actual and expected connections.
            var connSpanExpected = connListExpected.AsSpan();

            CompareConnectionLists(connSpanExpected, digraph.ConnectionIdArrays, digraph.WeightArray);

            // Test layer info.
            LayerInfo[] layerArrExpected = new LayerInfo[5];
            layerArrExpected[0] = new LayerInfo(2, 2);
            layerArrExpected[1] = new LayerInfo(3, 3);
            layerArrExpected[2] = new LayerInfo(4, 4);
            layerArrExpected[3] = new LayerInfo(5, 5);
            layerArrExpected[4] = new LayerInfo(6, 5);
            Assert.Equal(5, digraph.LayerArray.Length);

            // Check the node count.
            Assert.Equal(6, digraph.TotalNodeCount);
        }
        public void SingleInput_WeightOne()
        {
            var connList = new List <WeightedDirectedConnection <double> >();

            connList.Add(new WeightedDirectedConnection <double>(0, 1, 1.0));

            // Create graph.
            var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connList, 1, 1);

            // Create neural net and run tests.
            var actFn = new Logistic();
            var net   = new NeuralNetAcyclic(digraph, actFn.Fn);

            SingleInput_WeightOne_Inner(net, actFn);

            // Create vectorized neural net and run tests.
            var vnet = new NeuralNet.Double.Vectorized.NeuralNetAcyclic(digraph, actFn.Fn);

            SingleInput_WeightOne_Inner(vnet, actFn);
        }
Example #4
0
        public void SimpleAcyclic()
        {
            // Simple acyclic graph.
            var connList = new List <WeightedDirectedConnection <double> >
            {
                new WeightedDirectedConnection <double>(0, 3, 0.0),
                new WeightedDirectedConnection <double>(1, 3, 1.0),
                new WeightedDirectedConnection <double>(2, 3, 2.0),
                new WeightedDirectedConnection <double>(2, 4, 3.0)
            };

            // Create graph.
            var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connList, 3, 2);

            // The graph should be unchanged from the input connections.
            CompareConnectionLists(connList, digraph.ConnectionIdArrays, digraph.WeightArray);

            // Check the node count.
            Assert.Equal(5, digraph.TotalNodeCount);
        }
    public void SingleInput_WeightZero()
    {
        var connList = new LightweightList <WeightedDirectedConnection <double> > {
            new WeightedDirectedConnection <double>(0, 1, 0.0)
        };
        var connSpan = connList.AsSpan();

        // Create graph.
        var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connSpan, 1, 1);

        // Create neural net and run tests.
        var actFn = new Logistic();
        var net   = new NeuralNetAcyclic(digraph, actFn.Fn);

        SingleInput_WeightZero_Inner(net);

        // Create vectorized neural net and run tests.
        var vnet = new NeuralNets.Double.Vectorized.NeuralNetAcyclic(digraph, actFn.Fn);

        SingleInput_WeightZero_Inner(vnet);
    }
        public void TwoInputs_WeightHalf()
        {
            var connList = new List <WeightedDirectedConnection <double> >
            {
                new WeightedDirectedConnection <double>(0, 2, 0.5),
                new WeightedDirectedConnection <double>(1, 2, 0.5)
            };

            // Create graph.
            var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connList, 2, 1);

            // Create neural net and run tests.
            var actFn = new Logistic();
            var net   = new NeuralNetAcyclic(digraph, actFn.Fn);

            TwoInputs_WeightHalf_Inner(net, actFn);

            // Create vectorized neural net and run tests.
            var vnet = new NeuralNet.Double.Vectorized.NeuralNetAcyclic(digraph, actFn.Fn);

            TwoInputs_WeightHalf_Inner(vnet, actFn);
        }
        public void MultipleInputsOutputs()
        {
            var connList = new List <WeightedDirectedConnection <double> >
            {
                new WeightedDirectedConnection <double>(0, 5, 1.0),
                new WeightedDirectedConnection <double>(1, 3, 1.0),
                new WeightedDirectedConnection <double>(2, 4, 1.0)
            };

            // Create graph.
            var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connList, 3, 3);

            // Create neural net and run tests.
            var actFn = new Logistic();
            var net   = new NeuralNetAcyclic(digraph, actFn.Fn);

            MultipleInputsOutputs_Inner(net, actFn);

            // Create vectorized neural net and run tests.
            var vnet = new NeuralNet.Double.Vectorized.NeuralNetAcyclic(digraph, actFn.Fn);

            MultipleInputsOutputs_Inner(vnet, actFn);
        }
Example #8
0
        public void HiddenNode()
        {
            var connList = new List <WeightedDirectedConnection <double> >
            {
                new WeightedDirectedConnection <double>(0, 3, 0.5),
                new WeightedDirectedConnection <double>(1, 3, 0.5),
                new WeightedDirectedConnection <double>(3, 2, 2.0)
            };

            // Create graph.
            var digraph = WeightedDirectedGraphAcyclicBuilder <double> .Create(connList, 2, 1);

            // Create neural net and run tests.
            var actFn = new Logistic();
            var net   = new NeuralNetAcyclic(digraph, actFn.Fn);

            HiddenNode_Inner(net, actFn);

            // Create vectorized neural net and run tests.
            var vnet = new NeuralNets.Double.Vectorized.NeuralNetAcyclic(digraph, actFn.Fn);

            HiddenNode_Inner(vnet, actFn);
        }