所以我在文档( https://www.tensorflow.org/api_docs/python/tf/gradients )中阅读有关 tf.gradients() 的内容,我有点困惑。
我见过有人说 tf.gradients() 的结果是
symbolic partial derivatives of sum of ys w.r.t. x in xs.
这也是我首先想到的。但是文档描述了该函数的一个可选参数,如下所示:
stop_gradients is a Tensor or a list of tensors to be considered constant with respect to all xs. These tensors will not be backpropagated through, as though they had been explicitly disconnected using stop_gradient. Among other things, this allows computation of partial derivatives as opposed to total derivatives.
那么,如果我使用“stop_gradient”,是否只能计算偏导数,否则 len(xs) 向量中返回的默认值是全导数?可能这只是我的误解,如果有人能详细说明一下,我将不胜感激。
非常感谢!
最佳答案
根据函数文档
... It returns a list of Tensor of length len(xs) where each tensor is the sum(dy/dx) for y in ys.
所以这正是您在第一部分中所说的 - 每个输出张量都是 ys total 导数 w.r.t 的总和。对应的x。
文档建议使用 stop_gradients
参数来计算偏导数,即为此参数提供的张量在微分中被认为是常数。
关于python - TensorFlow 中的默认 tf.gradients - 全导数还是偏导数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59174710/