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","."]
code: def __init__(
      self,
      cg_iters=10,
      reg_coeff=1e-5,
      subsample_factor=1.0,
      backtrack_ratio=0.8,
      max_backtracks=15,
      accept_violation=False,
      hvp_approach=None,
      num_slices=1,
  ):
      self._cg_iters = cg_iters
      self._reg_coeff = reg_coeff
      self._subsample_factor = subsample_factor
      self._backtrack_ratio = backtrack_ratio
      self._max_backtracks = max_backtracks
      self._num_slices = num_slices
  
      self._opt_fun = None
      self._target = None
      self._max_constraint_val = None
      self._constraint_name = None
      self._accept_violation = accept_violation
      if hvp_approach is None:
          hvp_approach = PearlmutterHVP(num_slices)
      self._hvp_approach = hvp_approach
  
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 to create a new ConjugateGradientOptimizer object  with example: obj = ConjugateGradientOptimizer(cg_iters, reg_coeff, subsample_factor, backtrack_ratio, max_backtracks, accept_violation, hvp_approach, num_slices)