<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.math.value_and_jacobian" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.math.value_and_jacobian

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/math/jacobian.py">View source</a>



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

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



<!-- Placeholder for "Used in" -->


#### Args:


* <b>`f`</b>: 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.
* <b>`x`</b>: A `Tensor` with respect to which the gradient is to be computed.
* <b>`unconnected_gradients`</b>: 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`.
* <b>`name`</b>: Python `str` name prefixed to ops created by this function.
  Default value: `None` (i.e., `'value_and_jacobian'`).
* <b>`parallel_iterations`</b>: A knob to control how many iterations are dispatched
  in parallel. This knob can be used to control the total memory usage.
* <b>`experimental_use_pfor`</b>: 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`.

* <b>`y`</b>: `y = f(x)`.
* <b>`dydx`</b>: Jacobian of `y` wrt `x_i`, where `x_i` is the i-th parameter in
`x`.