Ejemplo n.º 1
0
        public void Relu()
        {
            var volume = new Double.Volume(new[] { -1.0, 0.0, 3.0, 5.0 }, new Shape(4));

            var result = volume.Relu();

            Assert.AreEqual(0.0, result.Get(0));
            Assert.AreEqual(0.0, result.Get(1));
            Assert.AreEqual(3.0, result.Get(2));
            Assert.AreEqual(5.0, result.Get(3));
        }
Ejemplo n.º 2
0
        public void TanhGradient()
        {
            var inputActivation          = new Double.Volume(new[] { -1.0, 0.0, 3.0, 5.0 }, new Shape(4));
            var outputActivation         = inputActivation.Relu();
            var outputActivationGradient = new Double.Volume(new[] { 1.0, 1.0, 1.0, 1.0 }, new Shape(4));

            var result = outputActivation.TanhGradient(inputActivation, outputActivationGradient);

            Assert.AreEqual(1.0, result.Get(0));
            Assert.AreEqual(1.0, result.Get(1));
            Assert.AreEqual(-8.0, result.Get(2));
            Assert.AreEqual(-24.0, result.Get(3));
        }
Ejemplo n.º 3
0
        public void SigmoidGradient()
        {
            var inputActivation = new Double.Volume(new[] { -1.0, 0.0, 3.0, 5.0 }, new Shape(4),
                                                    GpuContext.Default);
            var outputActivation         = inputActivation.Relu();
            var outputActivationGradient = new Double.Volume(new[] { 1.0, 1.0, 1.0, 1.0 }, new Shape(4),
                                                             GpuContext.Default);

            var result = outputActivation.SigmoidGradient(inputActivation, outputActivationGradient);

            Assert.AreEqual(0.0, result.Get(0));
            Assert.AreEqual(0.0, result.Get(1));
            Assert.AreEqual(-6.0, result.Get(2));
            Assert.AreEqual(-20.0, result.Get(3));
        }