Beispiel #1
0
        public void MultipleTest()
        {
            var a = new TensorOld(new double[] { 1, 2, 3 });
            var b = new TensorOld(new double[] { 4, 5, 6 });
            var c = new TensorOld(new double[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }
            });
            var d = new TensorOld(new double[, ] {
                { 1, 2 }, { 3, 4 }, { 5, 6 }
            });
            var e = new TensorOld(new double[, ] {
                { 3, 2, 1 }, { 6, 5, 4 }
            });

            var ab = a * b;

            Assert.Equal(32, ab.GetValue());

            var ad         = a * d;
            var adExpected = new TensorOld(new double[] { 22, 28 }, 1, 2);

            Assert.Equal(adExpected, ad);

            var ca         = c * a;
            var caExpected = new TensorOld(new double[] { 14, 32 }, 2, 1);

            Assert.Equal(caExpected, ca);

            var abew         = TensorOld.MultipleElementWise(a, b);
            var abewExpected = new TensorOld(new double[] { 4, 10, 18 });

            Assert.Equal(abewExpected, abew);

            var ceew         = TensorOld.MultipleElementWise(c, e);
            var ceewExpected = new TensorOld(new double[, ] {
                { 3, 4, 3 }, { 24, 25, 24 }
            });

            Assert.Equal(ceewExpected, ceew);
        }
Beispiel #2
0
 /// <summary>
 /// 反向传播或叫向前传播
 /// </summary>
 /// <param name="error">传回来的误差</param>
 /// <returns>传到前面的误差</returns>
 public override TensorOld Backward(TensorOld error)
 {
     TensorOld.Apply(ForwardOutput, Derivative, Derivatives.SigmoidFromOutput);
     TensorOld.MultipleElementWise(Derivative, error, BackwardOutput);
     return(BackwardOutput);
 }