示例#1
0
        public void ReluLayer_ForwardGradientWithLeakyUnits()
        {
            // http://en.wikipedia.org/wiki/Rectifier_(neural_networks)#Leaky_ReLUs

            var config = new ReluLayerConfiguration(0.01f);
            var layer = new ReluLayer(config);
            layer.Setup(bottom, top);
            layer.Forward(bottom, top);

            double slope = layer.Parameters.NegativeSlope;

            Assert.Equal(bottom.Count, top.Count);

            using (var topCpu = top.OnCpu())
            using (var bottomCpu = bottom.OnCpu())
            {
                int count = bottom.Count;
                for (int i = 0; i < count; i++)
                {
                    if (bottomCpu.DataAt(i) <= 0)
                    {
                        Assert.True(topCpu.DataAt(i) >= bottomCpu.DataAt(i) * slope - 0.000001);
                    }
                    else
                    {
                        Assert.True(topCpu.DataAt(i) >= 0.0d);
                        Assert.True(topCpu.DataAt(i) == 0.0d || topCpu.DataAt(i) == bottomCpu.DataAt(i));
                    }
                };
            }
        }
示例#2
0
        public void ReluLayer_ForwardWithLeakyUnits()
        {
            // http://en.wikipedia.org/wiki/Rectifier_(neural_networks)#Leaky_ReLUs

            var config = new ReluLayerConfiguration(0.01f);
            var layer  = new ReluLayer(config);

            layer.Setup(bottom, top);
            layer.Forward(bottom, top);

            double slope = layer.Parameters.NegativeSlope;

            Assert.Equal(bottom.Count, top.Count);

            using (var topCpu = top.OnCpu())
                using (var bottomCpu = bottom.OnCpu())
                {
                    int count = bottom.Count;
                    for (int i = 0; i < count; i++)
                    {
                        if (bottomCpu.DataAt(i) <= 0)
                        {
                            Assert.True(topCpu.DataAt(i) >= bottomCpu.DataAt(i) * slope - 0.000001);
                        }
                        else
                        {
                            Assert.True(topCpu.DataAt(i) >= 0.0d);
                            Assert.True(topCpu.DataAt(i) == 0.0d || topCpu.DataAt(i) == bottomCpu.DataAt(i));
                        }
                    }
                    ;
                }
        }
示例#3
0
        public void ReluLayer_Setup()
        {
            var layer = new ReluLayer();

            layer.Setup(bottom, top);

            Assert.Equal(bottom.Num, top.Num);
            Assert.Equal(bottom.Channels, top.Channels);
            Assert.Equal(bottom.Height, top.Height);
            Assert.Equal(bottom.Width, top.Width);
        }
示例#4
0
        public void ReluLayer_Forward()
        {
            var layer = new ReluLayer();
            layer.Setup(bottom, top);
            layer.Forward(bottom, top);

            Assert.Equal(bottom.Count, top.Count);

            using (var topCpu = top.OnCpu())
            using (var bottomCpu = bottom.OnCpu())
            {
                int count = bottom.Count;
                for (int i = 0; i < count; i++)
                {
                    Assert.True(topCpu.DataAt(i) >= 0.0d);
                    Assert.True(topCpu.DataAt(i) == 0.0d || topCpu.DataAt(i) == bottomCpu.DataAt(i));
                };
            }
        }
示例#5
0
        public void ReluLayer_Forward()
        {
            var layer = new ReluLayer();

            layer.Setup(bottom, top);
            layer.Forward(bottom, top);

            Assert.Equal(bottom.Count, top.Count);

            using (var topCpu = top.OnCpu())
                using (var bottomCpu = bottom.OnCpu())
                {
                    int count = bottom.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Assert.True(topCpu.DataAt(i) >= 0.0d);
                        Assert.True(topCpu.DataAt(i) == 0.0d || topCpu.DataAt(i) == bottomCpu.DataAt(i));
                    }
                    ;
                }
        }
示例#6
0
        public void ReluLayer_Setup()
        {
            var layer = new ReluLayer();
            layer.Setup(bottom, top);

            Assert.Equal(bottom.Num, top.Num);
            Assert.Equal(bottom.Channels, top.Channels);
            Assert.Equal(bottom.Height, top.Height);
            Assert.Equal(bottom.Width, top.Width);
        }