tfmri.math.make_val_and_grad_fn

make_val_and_grad_fn(value_fn)[source]

Function decorator to compute both function value and gradient.

Turns function value_fn that evaluates and returns a Tensor with the value of the function evaluated at the input point into one that returns a tuple of two Tensors with the value and the gradient of the defined function evaluated at the input point.

This is useful for constructing functions for optimization.

Parameters

value_fn – A Python function to decorate.

Returns

The decorated function.