예제 #1
0
        public void Forward()
        {
            const int inputWidth     = 4;
            const int inputHeight    = 4;
            const int inputDepth     = 4;
            const int inputBatchSize = 4;

            var layer = new PoolLayer <double>(2, 2);

            layer.Init(inputWidth, inputHeight, inputDepth);

            var data = new double[4 * 4 * 4 * 4];

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = i;
            }
            var input = new Volume.Double.Volume(data, new Shape(inputWidth, inputHeight, inputDepth, inputBatchSize));

            layer.DoForward(input);

            Assert.AreEqual(2, layer.OutputActivation.Shape.GetDimension(0));
            Assert.AreEqual(2, layer.OutputActivation.Shape.GetDimension(1));
            Assert.AreEqual(4, layer.OutputActivation.Shape.GetDimension(2));
            Assert.AreEqual(4, layer.OutputActivation.Shape.GetDimension(3));

            Assert.AreEqual(5.0, layer.OutputActivation.Get(0, 0, 0, 0));
            Assert.AreEqual(21.0, layer.OutputActivation.Get(0, 0, 1, 0));
            Assert.AreEqual(85.0, layer.OutputActivation.Get(0, 0, 1, 1));
        }
예제 #2
0
        public void Forward()
        {
            const int inputWidth     = 2;
            const int inputHeight    = 2;
            const int inputDepth     = 2;
            const int inputBatchSize = 2;

            var layer = new SigmoidLayer <double>();

            layer.Init(inputWidth, inputHeight, inputDepth);

            var input = new Volume.Double.Volume(new[]
            {
                1.0, 2.0,
                3.0, 4.0,
                5.0, 6.0,
                7.0, 8.0,
                9.0, 10.0,
                11.0, 12.0,
                13.0, 14.0,
                15.0, 16.0
            }, new Shape(inputWidth, inputHeight, inputDepth, inputBatchSize));

            layer.DoForward(input);

            for (var n = 0; n < 2; n++)
            {
                for (var c = 0; c < 2; c++)
                {
                    for (var y = 0; y < 2; y++)
                    {
                        for (var x = 0; x < 2; x++)
                        {
                            var v = input.Get(x, y, c, n);
                            Assert.AreEqual(1.0 / (1.0 + Math.Exp(-v)), layer.OutputActivation.Get(x, y, c, n));
                        }
                    }
                }
            }
        }
예제 #3
0
        public void Forward()
        {
            const int inputWidth     = 2;
            const int inputHeight    = 2;
            const int inputDepth     = 2;
            const int inputBatchSize = 2;

            var layer = new FullyConnLayer <double>(2)
            {
                BiasPref = 0.1
            };

            layer.Init(inputWidth, inputHeight, inputDepth);

            // Make sure filter shape had flatten input shape
            Assert.AreEqual(1, layer.Filters.Shape.GetDimension(0));
            Assert.AreEqual(1, layer.Filters.Shape.GetDimension(1));
            Assert.AreEqual(8, layer.Filters.Shape.GetDimension(2));
            Assert.AreEqual(2, layer.Filters.Shape.GetDimension(3));

            for (var i = 0; i < 8; i++)
            {
                layer.Filters.Set(0, 0, i, 0, i);
                layer.Filters.Set(0, 0, i, 1, i * 2.0);
            }

            var input = new Volume.Double.Volume(new[]
            {
                1.0, 2.0,
                3.0, 4.0,
                5.0, 6.0,
                7.0, 8.0,
                9.0, 10.0,
                11.0, 12.0,
                13.0, 14.0,
                15.0, 16.0
            }, new Shape(inputWidth, inputHeight, inputDepth, inputBatchSize));

            layer.DoForward(input);
        }