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

    The result is a rich object with the following properties:

    • grad: The gradient of f(x) w.r.t. x (result of tf.grad).
    • value: The value returned by f(x).
    // f(x) = x ^ 2
    const f = x => x.square();
    // f'(x) = 2x
    const g = tf.valueAndGrad(f);

    const x = tf.tensor1d([2, 3]);
    const {value, grad} = g(x);

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

    Type Parameters

    Parameters

    • f: ((x) => O)
        • (x): O
        • Parameters

          • x: I

          Returns O

    Returns ((x, dy?) => {
        grad: I;
        value: O;
    })

      • (x, dy?): {
            grad: I;
            value: O;
        }
      • Parameters

        • x: I
        • Optional dy: O

        Returns {
            grad: I;
            value: O;
        }

        • grad: I
        • value: O

    Doc

Generated using TypeDoc