tf_quant_finance.math.value_and_jacobian

Contents

Last updated: 2023-03-16.

tf_quant_finance.math.value_and_jacobian#

View source

Computes f(x) and its jacobian wrt to x.

tf_quant_finance.math.value_and_jacobian(
    f, x, unconnected_gradients=None, name=None, parallel_iterations=None,
    experimental_use_pfor=True
)

Args:#

  • f: Python callable to be differentiated. If f returns a scalar, this scalar will be differentiated. If f returns a tensor or list of tensors, by default a scalar will be computed by adding all their values to produce a single scalar. If desired, the tensors can be elementwise multiplied by the tensors passed as the dy keyword argument to the returned jacobian function.

  • x: A Tensor with respect to which the gradient is to be computed.

  • 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., 'value_and_jacobian').

  • parallel_iterations: A knob to control how many iterations are dispatched in parallel. This knob can be used to control the total memory usage.

  • experimental_use_pfor: If true, uses pfor for computing the Jacobian. Else uses a tf.while_loop.

Returns:#

A tuple of two elements. The first one is a Tensor representing the value of the function at x and the second one is a Tensor representing jacobian of f(x) wrt x.

  • y: y = f(x).

  • dydx: Jacobian of y wrt x_i, where x_i is the i-th parameter in x.