Last updated: 2023-03-16.
tf_quant_finance.math.value_and_gradient#
Computes f(*xs) and its gradients wrt to *xs.
tf_quant_finance.math.value_and_gradient(
f, xs, output_gradients=None, use_gradient_tape=False,
unconnected_gradients=None, name=None
)
Args:#
f: Pythoncallableto be differentiated. Iffreturns a scalar, this scalar will be differentiated. Iffreturns 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 thedykeyword argument to the returned gradient function.xs: Python list of parameters offfor which to differentiate. (Can also be singleTensor.)output_gradients: ATensoror list ofTensors the same size as the resultys = f(*xs)and holding the gradients computed for eachyinys. This argument is forwarded to the underlying gradient implementation (i.e., either thegrad_ysargument oftf.gradientsor theoutput_gradientsargument oftf.GradientTape.gradient).use_gradient_tape: Pythonboolindicating thattf.GradientTapeshould be used regardless oftf.executing_eagerly()status. Default value:False.unconnected_gradients: An enumtf.UnconnectedGradientswhich specifies the gradient value returned when the given input tensors are unconnected. Default value:None, which maps totf.UnconnectedGradients.NONE.name: Pythonstrname prefixed to ops created by this function. Default value:None(i.e.,'value_and_gradient').
Returns:#
A tuple of two elements. The first one is a Tensor representing the value
of the function at xs and the second one is either a Tensor or a list of
Tensors representing the gradient of f(*xs) wrt xs.
y:y = f(*xs).dydx: Gradient ofywrt each ofxs.