示例#1
0
        public override Signal Backward(ComputeShader compute, Signal dout)
        {
            dbeta = Refresh(1, dout.Columns, dbeta);
            MatOperations.SumMV(compute, dout, dbeta);

            dgamma = Refresh(1, dout.Columns, dgamma);
            MatOperations.MulMM(compute, dout, xn);
            MatOperations.SumMV(compute, xn, dgamma);

            var dxn = new Signal(dout);

            MatOperations.MulMVM(compute, dout, gamma, dxn);

            var dxc = new Signal(dxn);

            MatOperations.DivMVM(compute, dxn, std, dxc);

            var dxn_x_xc = new Signal(dxn);

            MatOperations.MulMMM(compute, dxn, xc, dxn_x_xc);
            dxn.Dispose();

            var std_x_std = new Signal(std);

            MatOperations.MulMMM(compute, std, std, std_x_std);

            var dxn_x_xc_div_std_x_std = new Signal(dxn_x_xc);

            MatOperations.DivMVM(compute, dxn_x_xc, std_x_std, dxn_x_xc_div_std_x_std);
            dxn_x_xc.Dispose();
            std_x_std.Dispose();

            var dstd = new Signal(std);

            MatOperations.SumMV(compute, dxn_x_xc_div_std_x_std, dstd);
            dxn_x_xc_div_std_x_std.Dispose();

            var dvar = new Signal(dstd);

            DVar(compute, dstd, std, dvar);
            dstd.Dispose();

            DXc(compute, xc, dvar, dxc, 2f / batchSize);
            dvar.Dispose();

            var dmu = new Signal(1, dxc.Columns);

            MatOperations.SumMV(compute, dxc, dmu);

            var dx = new Signal(dout);

            DX(compute, dxc, dmu, dx, 1f / batchSize);
            dxc.Dispose();
            dmu.Dispose();

            return(dx);
        }
示例#2
0
        public override Signal Backward(ComputeShader compute, Signal dout)
        {
            var dx = new Signal(dout.Rows, weights.Rows);

            MatOperations.MultiplyMT(compute, dout, weights, dx);
            // dx.Log();

            dW = Refresh(x.Columns, dout.Columns, dW);
            MatOperations.MultiplyTM(compute, x, dout, dW);

            dB = Refresh(1, dout.Columns, dB);
            MatOperations.SumMV(compute, dout, dB);

            // dx.Log();
            // dw.Log();
            // db.Log();

            return(dx);
        }