tf_quant_finance.math.gradients

Contents

Last updated: 2023-03-16.

tf_quant_finance.math.gradients#

View source

Computes the gradients of func_or_y wrt to *xs.

tf_quant_finance.math.gradients(
    func_or_y, xs, output_gradients=None, use_gradient_tape=False,
    unconnected_gradients=None, name=None
)

Args:#

  • func_or_y: Either a Tensor connected to the input x or a Python callable accepting one Tensor of shape of x and returning a Tensor of any shape. The function whose gradient is to be computed. If eagerly executing, can only be a callable, i.e., one should not supply a Tensor in eager mode. xs: Python list of parameters of f for which to differentiate. (Can also be single Tensor.) output_gradients: A Tensor or list of Tensors the same size as the result ys = f(*xs) and holding the gradients computed for each y in ys. This argument is forwarded to the underlying gradient implementation (i.e., either the grad_ys argument of tf.gradients or the output_gradients argument of tf.GradientTape.gradient). Default value: None which maps to a ones-like Tensor of ys. use_gradient_tape: Python bool indicating that tf.GradientTape should be used regardless of tf.executing_eagerly() status. Default value: False. unconnected_gradients: An enum tf.UnconnectedGradients which specifies the gradient value returned when the given input tensors are unconnected. Default value: None, which maps to tf.UnconnectedGradients.NONE. name: Python str name prefixed to ops created by this function. Default value: None (i.e., ‘gradients’).

Returns:#

A Tensor with the gradient of y wrt each of xs or a list of Tensors if xs is a list.