class_docstr: Performs constrained optimization via line search.
  
  The search direction is computed using a conjugate gradient algorithm,
  which gives x = A^{-1}g, where A is a second order approximation of the
  constraint and g is the gradient of the loss function.
  
  Args:
      cg_iters (int): The number of CG iterations used to calculate A^-1 g
      reg_coeff (float): A small value so that A -> A + reg*I
      subsample_factor (float): Subsampling factor to reduce samples when
          using "conjugate gradient. Since the computation time for the
          descent direction dominates, this can greatly reduce the overall
          computation time.
      backtrack_ratio (float): backtrack ratio for backtracking line search.
      max_backtracks (int): Max number of iterations for backtrack
          linesearch.
      accept_violation (bool): whether to accept the descent step if it
          violates the line search condition after exhausting all
          backtracking budgets.
      hvp_approach (HessianVectorProduct): A class that computes
          Hessian-Vector products.
      num_slices (int): Hessian-vector product function's inputs will be
          divided into num_slices and then averaged together to improve
          performance.
class_docstr_tok: ["Performs","constrained","optimization","via","line","search",".","The","search","direction","is","computed","using","a","conjugate","gradient","algorithm",",","which","gives","x","=","A^","{","-1","}","g",",","where","A","is","a","second","order","approximation","of","the","constraint","and","g","is","the","gradient","of","the","loss","function",".","Args",":","cg_iters","(","int",")",":","The","number","of","CG","iterations","used","to","calculate","A^-1","g","reg_coeff","(","float",")",":","A","small","value","so","that","A","-",">","A","+","reg","*","I","subsample_factor","(","float",")",":","Subsampling","factor","to","reduce","samples","when","using","``","conjugate","gradient",".","Since","the","computation","time","for","the","descent","direction","dominates",",","this","can","greatly","reduce","the","overall","computation","time",".","backtrack_ratio","(","float",")",":","backtrack","ratio","for","backtracking","line","search",".","max_backtracks","(","int",")",":","Max","number","of","iterations","for","backtrack","linesearch",".","accept_violation","(","bool",")",":","whether","to","accept","the","descent","step","if","it","violates","the","line","search","condition","after","exhausting","all","backtracking","budgets",".","hvp_approach","(","HessianVectorProduct",")",":","A","class","that","computes","Hessian-Vector","products",".","num_slices","(","int",")",":","Hessian-vector","product","function","'s","inputs","will","be","divided","into","num_slices","and","then","averaged","together","to","improve","performance","."]
docstr: Update the optimizer.
  
  Build the functions for computing loss, gradient, and
  the constraint value.
  
  Args:
      loss (tf.Tensor): Symbolic expression for the loss function.
      target (garage.tf.policies.Policy): A parameterized object to
          optimize over.
      leq_constraint (tuple[tf.Tensor, float]): A constraint provided
          as a tuple (f, epsilon), of the form f(*inputs) <= epsilon.
      inputs (list(tf.Tenosr)): A list of symbolic variables as inputs,
          which could be subsampled if needed. It is assumed that the
          first dimension of these inputs should correspond to the
          number of data points.
      extra_inputs (list[tf.Tenosr]): A list of symbolic variables as
          extra inputs which should not be subsampled.
      name (str): Name to be passed to tf.name_scope.
      constraint_name (str): A constraint name for prupose of logging
          and variable names.
docstr_tok: ["Update","the","optimizer",".","Build","the","functions","for","computing","loss",",","gradient",",","and","the","constraint","value",".","Args",":","loss","(","tf.Tensor",")",":","Symbolic","expression","for","the","loss","function",".","target","(","garage.tf.policies.Policy",")",":","A","parameterized","object","to","optimize","over",".","leq_constraint","(","tuple","[","tf.Tensor",",","float","]",")",":","A","constraint","provided","as","a","tuple","(","f",",","epsilon",")",",","of","the","form","f","(","*","inputs",")","<","=","epsilon",".","inputs","(","list","(","tf.Tenosr",")",")",":","A","list","of","symbolic","variables","as","inputs",",","which","could","be","subsampled","if","needed",".","It","is","assumed","that","the","first","dimension","of","these","inputs","should","correspond","to","the","number","of","data","points",".","extra_inputs","(","list","[","tf.Tenosr","]",")",":","A","list","of","symbolic","variables","as","extra","inputs","which","should","not","be","subsampled",".","name","(","str",")",":","Name","to","be","passed","to","tf.name_scope",".","constraint_name","(","str",")",":","A","constraint","name","for","prupose","of","logging","and","variable","names","."]
code: def update_opt(
      self,
      loss,
      target,
      leq_constraint,
      inputs,
      extra_inputs=None,
      name="ConjugateGradientOptimizer",
      constraint_name="constraint",
  ):
      """Update the optimizer.
  
      Build the functions for computing loss, gradient, and
      the constraint value.
  
      Args:
          loss (tf.Tensor): Symbolic expression for the loss function.
          target (garage.tf.policies.Policy): A parameterized object to
              optimize over.
          leq_constraint (tuple[tf.Tensor, float]): A constraint provided
              as a tuple (f, epsilon), of the form f(*inputs) <= epsilon.
          inputs (list(tf.Tenosr)): A list of symbolic variables as inputs,
              which could be subsampled if needed. It is assumed that the
              first dimension of these inputs should correspond to the
              number of data points.
          extra_inputs (list[tf.Tenosr]): A list of symbolic variables as
              extra inputs which should not be subsampled.
          name (str): Name to be passed to tf.name_scope.
          constraint_name (str): A constraint name for prupose of logging
              and variable names.
  
      """
      params = target.get_params()
      with tf.name_scope(name):
          inputs = tuple(inputs)
          if extra_inputs is None:
              extra_inputs = tuple()
          else:
              extra_inputs = tuple(extra_inputs)
  
          constraint_term, constraint_value = leq_constraint
  
          with tf.name_scope("loss_gradients"):
              grads = tf.gradients(loss, xs=params)
              for idx, (grad, param) in enumerate(zip(grads, params)):
                  if grad is None:
                      grads[idx] = tf.zeros_like(param)
              flat_grad = flatten_tensor_variables(grads)
  
          self._hvp_approach.update_hvp(
              f=constraint_term,
              target=target,
              inputs=inputs + extra_inputs,
              reg_coeff=self._reg_coeff,
              name="update_opt_" + constraint_name,
          )
  
          self._target = target
          self._max_constraint_val = constraint_value
          self._constraint_name = constraint_name
  
          self._opt_fun = LazyDict(
              f_loss=lambda: compile_function(
                  inputs=inputs + extra_inputs,
                  outputs=loss,
              ),
              f_grad=lambda: compile_function(
                  inputs=inputs + extra_inputs,
                  outputs=flat_grad,
              ),
              f_constraint=lambda: compile_function(
                  inputs=inputs + extra_inputs,
                  outputs=constraint_term,
              ),
              f_loss_constraint=lambda: compile_function(
                  inputs=inputs + extra_inputs,
                  outputs=[loss, constraint_term],
              ),
          )
  
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 2 for calling the ConjugateGradientOptimizer obj's underlying member method code with example usage: obj.update_opt(loss, target, leq_constraint, inputs, extra_inputs, name, constraint_name) without return types