def gauss_newton_vec_z(ys, zs, xs, vs):
"""Implements HJJ'v, where v is on the output space.
Args:
ys: Loss function or output variables.
zs: Before output layer (input to softmax).
xs: Weights, list of tensors.
vs: List of tensors to multiply, for each weight tensor.
Returns:
HJJ'v: Gauss-Newton vector product on the output space.
"""
# Validate the input
if type(zs) == list:
if len(vs) != len(zs):
raise ValueError("zs and vs must have the same length.")
grads_z = tf.gradients(ys, zs, gate_gradients=True)
jv = tf.gradients(zs, xs, vs, gate_gradients=True)
hjjv = forward_gradients(grads_z, xs, jv, gate_gradients=True)
return hjjv
评论列表
文章目录