class_docstr: trpo class
class_docstr_tok: ["trpo","class"]
docstr: Conjugate gradient algorithm
  (see https://en.wikipedia.org/wiki/Conjugate_gradient_method)
docstr_tok: ["Conjugate","gradient","algorithm","(","see","https",":","\/\/en.wikipedia.org\/wiki\/Conjugate_gradient_method",")"]
code: def cg(self, Ax, b):
      """
      Conjugate gradient algorithm
      (see https://en.wikipedia.org/wiki/Conjugate_gradient_method)
      """
      x = np.zeros_like(b)
      r = copy.deepcopy(
          b
      )  # Note: should be 'b - Ax(x)', but for x=0, Ax(x)=0. Change if doing warm start.
      p = copy.deepcopy(r)
      r_dot_old = np.dot(r, r)
      for _ in range(CG_ITERS):
          z = Ax(p)
          alpha = r_dot_old / (np.dot(p, z) + EPS)
          x += alpha * p
          r -= alpha * z
          r_dot_new = np.dot(r, r)
          p = r + (r_dot_new / r_dot_old) * p
          r_dot_old = r_dot_new
      return x
  
imports: import argparse
  import copy
  import os
  import threading
  import time
  import gym
  import matplotlib.pyplot
  import numpy
  import scipy.signal
  import tensorflow
  import tensorflow_probability
  import tensorlayer
label_desc: Use image node_id 12 for calling the TRPO obj's underlying member method code with example usage: obj.cg(Ax, b) and returns: x