[英]How to use tensorflow to approximate hessian matrix's norm
I wonder is there any method to recompute gradients with updated weights within a graph or if there is any better way to do this.我想知道是否有任何方法可以在图中重新计算具有更新权重的梯度,或者是否有更好的方法来做到这一点。 For example, for estimating hessian norm, we need to compute
例如,为了估计 Hessian 范数,我们需要计算
delta ~ N(0, I)
hessian_norm = 1/M \sum_{1}^{M} gradient(f(x+delta))- gradient(f(x-delta))/(2*delta)
we need to gradient value on x+delta
.我们需要在
x+delta
上梯度值。 Currently we will get None
type if we use tf.gradient
on var+delta
directly.目前,如果我们直接在
var+delta
上使用tf.gradient
,我们将得到None
类型。
More specifally speaking, if we define更具体地说,如果我们定义
a = tf.Variable
b = some_function(a)
grad = tf.gradients(b, a)
that's a normal gradient computation but if we do这是一个正常的梯度计算,但如果我们这样做
grad_delta = tf.gradients(b, a+delta)
it will return None
.它将返回
None
。 This feature seems to make it impossible to approximate the hessian norm using the above method.这个特征似乎使得使用上述方法无法近似于 hessian 范数。
b
is not a function of a+delta
, so you get None
s. b
不是 a a+delta
的函数,所以你得到None
s。 You either need to create new value b2
which depends on a+delta
, or just move your a
variable by delta
and eval again to get second value.您可能需要创造新的价值
b2
依赖于a+delta
,或只动a
可变delta
和EVAL再次获得第二个值。
This is similar to how you do line search in TensorFlow .这类似于您在 TensorFlow 中进行线搜索的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.