second_order.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:tensorflow-forward-ad 作者: renmengye 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号