python - TensorFlow 中的默认 tf.gradients - 全导数还是偏导数?

标签 python tensorflow gradient

所以我在文档( 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/

相关文章:

python - ManyToMany 关系中的 Save()

python - CNN 仅针对 binary_crossentropy 损失函数收敛并且在测试数据集上失败

c++ - 在 OpenCV 中绘制梯度 vector 场

python - 反向传播 - 梯度误差 [Python]

python - NumPy:使用自定义数据类型时的数组分配问题

Python 名称错误 : global name 'any' is not defined

python - 使用 Django 启用管理员时出现 404

python - 如何恢复tensorflow2中的特定检查点(以实现提前停止)?

python - 如何在 Keras Tensorflow 中为采样创建自定义层?

javascript - 如何仅使用 Javascript(无 CSS)创建从黑到白的渐变?