Ejemplo n.º 1
0
        public void Pool2DGradientBatch()
        {
            var inputActivation = new Double.Volume(new[]
            {
                1.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 1.0, 7.0,
                2.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 4.0, 1.0,

                2.0, 0.0, 2.0, 2.0,
                2.0, 0.0, 2.0, 14.0,
                4.0, 0.0, 2.0, 2.0,
                2.0, 0.0, 8.0, 2.0
            }, new Shape(4, 4, 1, 2));

            var outputActivation = inputActivation.Pool(2, 2, 0, 2);

            var outputActivationGradient = new Double.Volume(new[]
            {
                1.0, 1.0, 1.0, 1.0,
                2.0, 2.0, 2.0, 2.0,
            }, new Shape(2, 2, 1, 2));

            var result = outputActivation.PoolGradient(inputActivation, outputActivationGradient, 2, 2, 0, 2);

            Assert.AreEqual(1.0, result.Get(0, 0, 0, 0));
            Assert.AreEqual(1.0, result.Get(3, 1, 0, 0));
            Assert.AreEqual(1.0, result.Get(0, 2, 0, 0));
            Assert.AreEqual(1.0, result.Get(2, 3, 0, 0));

            Assert.AreEqual(2.0, result.Get(0, 0, 0, 1));
            Assert.AreEqual(2.0, result.Get(3, 1, 0, 1));
            Assert.AreEqual(2.0, result.Get(0, 2, 0, 1));
            Assert.AreEqual(2.0, result.Get(2, 3, 0, 1));
        }
Ejemplo n.º 2
0
        public void Pool2DBatch()
        {
            var volume = new Double.Volume(new[]
            {
                1.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 1.0, 7.0,
                2.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 4.0, 1.0,

                2.0, 0.0, 2.0, 2.0,
                2.0, 0.0, 2.0, 14.0,
                4.0, 0.0, 2.0, 2.0,
                2.0, 0.0, 8.0, 2.0
            }, new Shape(4, 4, 1, 2));

            var result = volume.Pool(2, 2, 0, 2);

            Assert.AreEqual(2, result.Shape.GetDimension(0));
            Assert.AreEqual(2, result.Shape.GetDimension(1));
            Assert.AreEqual(1, result.Shape.GetDimension(2));
            Assert.AreEqual(2, result.Shape.GetDimension(3));

            Assert.AreEqual(1.0, result.Get(0, 0, 0, 0));
            Assert.AreEqual(7.0, result.Get(1, 0, 0, 0));
            Assert.AreEqual(2.0, result.Get(0, 1, 0, 0));
            Assert.AreEqual(4.0, result.Get(1, 1, 0, 0));

            Assert.AreEqual(2.0, result.Get(0, 0, 0, 1));
            Assert.AreEqual(14.0, result.Get(1, 0, 0, 1));
            Assert.AreEqual(4.0, result.Get(0, 1, 0, 1));
            Assert.AreEqual(8.0, result.Get(1, 1, 0, 1));
        }
Ejemplo n.º 3
0
        public void Pool2D()
        {
            var volume = new Double.Volume(new[]
            {
                1.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 1.0, 7.0,
                2.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 4.0, 1.0
            }, new Shape(4, 4), GpuContext.Default);

            var result = volume.Pool(2, 2, 0, 2);

            Assert.AreEqual(2, result.Shape.GetDimension(0));
            Assert.AreEqual(2, result.Shape.GetDimension(0));

            Assert.AreEqual(1.0, result.Get(0, 0));
            Assert.AreEqual(7.0, result.Get(1, 0));
            Assert.AreEqual(2.0, result.Get(0, 1));
            Assert.AreEqual(4.0, result.Get(1, 1));
        }
Ejemplo n.º 4
0
        public void Pool2DGradient()
        {
            var inputActivation = new Double.Volume(new[]
            {
                1.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 1.0, 7.0,
                2.0, 0.0, 1.0, 1.0,
                1.0, 0.0, 4.0, 1.0
            }, new Shape(4, 4), GpuContext.Default);

            var outputActivation = inputActivation.Pool(2, 2, 0, 2);

            var outputActivationGradient = new Double.Volume(new[] { 1.0, 1.0, 1.0, 1.0 }, new Shape(2, 2),
                                                             GpuContext.Default);

            var result = outputActivation.PoolGradient(inputActivation, outputActivationGradient, 2, 2, 0, 2);

            Assert.AreEqual(1.0f, result.Get(0, 0));
            Assert.AreEqual(1.0f, result.Get(3, 1));
            Assert.AreEqual(1.0f, result.Get(0, 2));
            Assert.AreEqual(1.0f, result.Get(2, 3));
        }