Last updated: 2023-03-16.
tf_quant_finance.math.gradients#
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 aTensorconnected to the inputxor a Python callable accepting oneTensorof shape ofxand returning aTensorof 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 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). Default value:Nonewhich maps to a ones-likeTensorofys. 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., ‘gradients’).
Returns:#
A Tensor with the gradient of y wrt each of xs or a list of Tensors
if xs is a list.