class_docstr: Encapsulates fields and methods for RL policy and value function estimation with shared parameters
docstr: Parameters
  ----------
  env : obj
      RL environment
  observations : tensorflow placeholder
      Tensorflow placeholder in which the observations will be fed
  latent : tensor
      Latent state from which policy distribution parameters should be inferred
  vf_latent : tensor
      Latent state from which value function should be inferred (if None, then latent is used)
  sess : tensorflow session
      Tensorflow session to run calculations in (if None, default session is used)
  **tensors
      Tensorflow tensors for additional attributes such as state or mask
docstr_tok: ["Parameters","--","--","--","--","--","env",":","obj","RL","environment","observations",":","tensorflow","placeholder","Tensorflow","placeholder","in","which","the","observations","will","be","fed","latent",":","tensor","Latent","state","from","which","policy","distribution","parameters","should","be","inferred","vf_latent",":","tensor","Latent","state","from","which","value","function","should","be","inferred","(","if","None",",","then","latent","is","used",")","sess",":","tensorflow","session","Tensorflow","session","to","run","calculations","in","(","if","None",",","default","session","is","used",")","*","*","tensors","Tensorflow","tensors","for","additional","attributes","such","as","state","or","mask"]
code: def __init__(
      self,
      env,
      observations,
      latent,
      estimate_q=False,
      vf_latent=None,
      sess=None,
      np_mask=None,
      is_act_model=False,
      **tensors,
  ):
      """
      Parameters
      ----------
      env : obj
          RL environment
      observations : tensorflow placeholder
          Tensorflow placeholder in which the observations will be fed
      latent : tensor
          Latent state from which policy distribution parameters should be inferred
      vf_latent : tensor
          Latent state from which value function should be inferred (if None, then latent is used)
      sess : tensorflow session
          Tensorflow session to run calculations in (if None, default session is used)
      **tensors
          Tensorflow tensors for additional attributes such as state or mask
      """
  
      self.X = observations
      self.state = tf.constant([])
      self.initial_state = None
      self.__dict__.update(tensors)
  
      vf_latent = vf_latent if vf_latent is not None else latent
  
      vf_latent = tf.layers.flatten(vf_latent)
      latent = tf.layers.flatten(latent)
  
      # Based on the action space, will select what probability distribution type
      self.np_mask = np_mask
      self.pdtype = CategoricalPdType(
          env.action_space.n, env.nsteps, np_mask, is_act_model
      )
  
      self.act_latent = latent
      self.nh = env.action_space.n
  
      (
          self.pd,
          self.pi,
          self.mask,
          self.mask_npinf,
      ) = self.pdtype.pdfromlatent(latent, init_scale=0.01)
  
      # Take an action
      self.action = self.pd.sample()
  
      # Calculate the neg log of our probability
      self.neglogp = self.pd.neglogp(self.action)
      self.sess = sess or tf.get_default_session()
  
      assert estimate_q is False
      self.vf = fc(vf_latent, "vf", 1)
      self.vf = self.vf[:, 0]
  
      if is_act_model:
          self._build_model_for_step()
  
file_path: nni/nni/algorithms/hpo/ppo_tuner/policy.py
imports: import tensorflow.compat.v1
  from .distri import CategoricalPdType
  from .util import lstm_model, fc, observation_placeholder, adjust_shape
label_desc: Use image node_id 1 to create a new PolicyWithValue object  with example: obj = PolicyWithValue(env, observations, latent, estimate_q, vf_latent, sess, np_mask, is_act_model)