tf_quant_finance.math.make_val_and_grad_fn

Last updated: 2023-03-16.

tf_quant_finance.math.make_val_and_grad_fn#

View source

Function decorator to compute both function value and gradient.

tf_quant_finance.math.make_val_and_grad_fn(
    value_fn
)

For example:#

@tff.math.make_val_and_grad_fn
def quadratic(x):
  return tf.reduce_sum(scales * (x - minimum) ** 2, axis=-1)

Turns quadratic into a function that accepts a point as a Tensor as input and returns a tuple of two Tensors with the value and the gradient of the defined quadratic function evaluated at the input point.

This is useful for constructing functions to optimize with tff.math.optimizer methods.

Args:#

  • value_fn: A python function to decorate.

Returns:#

The decorated function.