class_docstr: Computes Hessian-vector product using Pearlmutter's algorithm.
  
  `Pearlmutter, Barak A. "Fast exact multiplication by the Hessian." Neural
   computation 6.1 (1994): 147-160.`
class_docstr_tok: ["Computes","Hessian-vector","product","using","Pearlmutter","'s","algorithm",".","`","Pearlmutter",",","Barak","A",".","``","Fast","exact","multiplication","by","the","Hessian",".","''","Neural","computation","6.1","(","1994",")",":","147-160.","`"]
docstr: Build the symbolic graph to compute the Hessian-vector product.
  
  Args:
      f (tf.Tensor): The function whose Hessian needs to be computed.
      target (garage.tf.policies.Policy): A parameterized object to
          optimize over.
      inputs (tuple[tf.Tensor]): The inputs for function f.
      reg_coeff (float): A small value so that A -> A + reg*I.
      name (str): Name to be used in tf.name_scope.
docstr_tok: ["Build","the","symbolic","graph","to","compute","the","Hessian-vector","product",".","Args",":","f","(","tf.Tensor",")",":","The","function","whose","Hessian","needs","to","be","computed",".","target","(","garage.tf.policies.Policy",")",":","A","parameterized","object","to","optimize","over",".","inputs","(","tuple","[","tf.Tensor","]",")",":","The","inputs","for","function","f.","reg_coeff","(","float",")",":","A","small","value","so","that","A","-",">","A","+","reg","*","I.","name","(","str",")",":","Name","to","be","used","in","tf.name_scope","."]
code: def update_hvp(
      self, f, target, inputs, reg_coeff, name="PearlmutterHVP"
  ):
      """Build the symbolic graph to compute the Hessian-vector product.
  
      Args:
          f (tf.Tensor): The function whose Hessian needs to be computed.
          target (garage.tf.policies.Policy): A parameterized object to
              optimize over.
          inputs (tuple[tf.Tensor]): The inputs for function f.
          reg_coeff (float): A small value so that A -> A + reg*I.
          name (str): Name to be used in tf.name_scope.
  
      """
      self._target = target
      self._reg_coeff = reg_coeff
      params = target.get_params()
      with tf.name_scope(name):
          constraint_grads = tf.gradients(
              f, xs=params, name="gradients_constraint"
          )
          for idx, (grad, param) in enumerate(
              zip(constraint_grads, params)
          ):
              if grad is None:
                  constraint_grads[idx] = tf.zeros_like(param)
  
          xs = tuple(
              [new_tensor_like(p.name.split(":")[0], p) for p in params]
          )
  
          def hx_plain():
              """Computes product of Hessian(f) and vector v.
  
              Returns:
                  tf.Tensor: Symbolic result.
  
              """
              with tf.name_scope("hx_plain"):
                  with tf.name_scope("hx_function"):
                      hx_f = tf.reduce_sum(
                          tf.stack(
                              [
                                  tf.reduce_sum(g * x)
                                  for g, x in zip(constraint_grads, xs)
                              ]
                          )
                      )
                  hx_plain_splits = tf.gradients(
                      hx_f, params, name="gradients_hx_plain"
                  )
                  for idx, (hx, param) in enumerate(
                      zip(hx_plain_splits, params)
                  ):
                      if hx is None:
                          hx_plain_splits[idx] = tf.zeros_like(param)
                  return flatten_tensor_variables(hx_plain_splits)
  
          self._hvp_fun = LazyDict(
              f_hx_plain=lambda: compile_function(
                  inputs=inputs + xs,
                  outputs=hx_plain(),
              ),
          )
  
imports: import abc
  from dowel import logger
  import numpy
  import tensorflow
  from garage.tf import compile_function, flatten_tensor_variables, new_tensor_like
  from garage.tf.optimizers._dtypes import LazyDict
label_desc: Use image node_id 1 for calling the PearlmutterHVP obj's underlying member method code with example usage: obj.update_hvp(f, target, inputs, reg_coeff, name) and returns: flatten_tensor_variables