• Like tf.grads, but returns also the value of f(). Useful when f() returns a metric you want to show.

    The result is a rich object with the following properties:

    • grads: The gradients of f() w.r.t. each input (result of tf.grads).
    • value: The value returned by f(x).
    // f(a, b) = a * b
    const f = (a, b) => a.mul(b);
    // df/da = b, df/db = a
    const g = tf.valueAndGrads(f);

    const a = tf.tensor1d([2, 3]);
    const b = tf.tensor1d([-2, -3]);
    const {value, grads} = g([a, b]);

    const [da, db] = grads;

    console.log('value');
    value.print();

    console.log('da');
    da.print();
    console.log('db');
    db.print();

    Type Parameters

    Parameters

    • f: ((...args) => O)
        • (...args): O
        • Parameters

          Returns O

    Returns ((args, dy?) => {
        grads: Tensor[];
        value: O;
    })

      • (args, dy?): {
            grads: Tensor[];
            value: O;
        }
      • Parameters

        Returns {
            grads: Tensor[];
            value: O;
        }

    Doc

Generated using TypeDoc