Beispiel #1
0
 public void Backward(float gradientTop)
 {
     axpbypc.gradient = gradientTop;
     ag1.backward();
     ag0.backward();
     mg1.backward();
     mg0.backward();
 }
Beispiel #2
0
    public void Test1()
    {
        var a = new Unit(1.0f, 0.0f);
        var b = new Unit(2.0f, 0.0f);
        var c = new Unit(-3.0f, 0.0f);
        var x = new Unit(-1.0f, 0.0f);
        var y = new Unit(3.0f, 0.0f);

        var mulg0 = new GateMul();
        var mulg1 = new GateMul();
        var addg0 = new GateAdd();
        var addg1 = new GateAdd();
        var sg0   = new GateSigmoid();

        var ax      = mulg0.forward(a, x);
        var by      = mulg1.forward(b, y);
        var axpby   = addg0.forward(ax, by);
        var axpbypc = addg1.forward(axpby, c);
        var s       = sg0.forward(axpbypc);

        Debug.LogFormat("forward: pass 1: {0}", s.value);

        s.gradient = 1.0f;
        sg0.backward();
        addg1.backward();
        addg0.backward();
        mulg1.backward();
        mulg0.backward();

        var step = 0.01f;

        a.value += step * a.gradient;
        b.value += step * b.gradient;
        c.value += step * c.gradient;
        x.value += step * x.gradient;
        y.value += step * y.gradient;

        ax      = mulg0.forward(a, x);
        by      = mulg1.forward(b, y);
        axpby   = addg0.forward(ax, by);
        axpbypc = addg1.forward(axpby, c);
        s       = sg0.forward(axpbypc);

        Debug.LogFormat("forward: pass 2: {0}", s.value);
    }