Like tf.grad, but also returns the value of f(). Useful when f() returns a metric you want to show.
tf.grad
f()
The result is a rich object with the following properties:
f(x)
x
// f(x) = x ^ 2const f = x => x.square();// f'(x) = 2xconst 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(); Copy
// f(x) = x ^ 2const f = x => x.square();// f'(x) = 2xconst 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();
Optional
Generated using TypeDoc
Like
tf.grad
, but also returns the value off()
. Useful whenf()
returns a metric you want to show.The result is a rich object with the following properties:
f(x)
w.r.t.x
(result oftf.grad
).f(x)
.