def __init__(self, obs_space, action_space, config, loss_fn, stats_fn=None, grad_stats_fn=None, before_loss_init=None, make_model=None, action_sampler_fn=None, existing_inputs=None, existing_model=None, get_batch_divisibility_req=None, obs_include_prev_action_reward=True):
    'Initialize a dynamic TF policy.\n\n        Arguments:\n            observation_space (gym.Space): Observation space of the policy.\n            action_space (gym.Space): Action space of the policy.\n            config (dict): Policy-specific configuration data.\n            loss_fn (func): function that returns a loss tensor the policy\n                graph, and dict of experience tensor placeholders\n            stats_fn (func): optional function that returns a dict of\n                TF fetches given the policy and batch input tensors\n            grad_stats_fn (func): optional function that returns a dict of\n                TF fetches given the policy and loss gradient tensors\n            before_loss_init (func): optional function to run prior to loss\n                init that takes the same arguments as __init__\n            make_model (func): optional function that returns a ModelV2 object\n                given (policy, obs_space, action_space, config).\n                All policy variables should be created in this function. If not\n                specified, a default model will be created.\n            action_sampler_fn (func): optional function that returns a\n                tuple of action and action logp tensors given\n                (policy, model, input_dict, obs_space, action_space, config).\n                If not specified, a default action distribution will be used.\n            existing_inputs (OrderedDict): when copying a policy, this\n                specifies an existing dict of placeholders to use instead of\n                defining new ones\n            existing_model (ModelV2): when copying a policy, this specifies\n                an existing model to clone and share weights with\n            get_batch_divisibility_req (func): optional function that returns\n                the divisibility requirement for sample batches\n            obs_include_prev_action_reward (bool): whether to include the\n                previous action and reward in the model input\n        '
    self.config = config
    self._loss_fn = loss_fn
    self._stats_fn = stats_fn
    self._grad_stats_fn = grad_stats_fn
    self._obs_include_prev_action_reward = obs_include_prev_action_reward
    prev_actions = None
    prev_rewards = None
    if (existing_inputs is not None):
        obs = existing_inputs[SampleBatch.CUR_OBS]
        if self._obs_include_prev_action_reward:
            prev_actions = existing_inputs[SampleBatch.PREV_ACTIONS]
            prev_rewards = existing_inputs[SampleBatch.PREV_REWARDS]
    else:
        obs = tf.placeholder(tf.float32, shape=([None] + list(obs_space.shape)), name='observation')
        if self._obs_include_prev_action_reward:
            prev_actions = ModelCatalog.get_action_placeholder(action_space)
            prev_rewards = tf.placeholder(tf.float32, [None], name='prev_reward')
    self._input_dict = {SampleBatch.CUR_OBS: obs, SampleBatch.PREV_ACTIONS: prev_actions, SampleBatch.PREV_REWARDS: prev_rewards, 'is_training': self._get_is_training_placeholder()}
    self._seq_lens = tf.placeholder(dtype=tf.int32, shape=[None], name='seq_lens')
    if action_sampler_fn:
        if (not make_model):
            raise ValueError('make_model is required if action_sampler_fn is given')
        self.dist_class = None
    else:
        (self.dist_class, logit_dim) = ModelCatalog.get_action_dist(action_space, self.config['model'])
    if existing_model:
        self.model = existing_model
    elif make_model:
        self.model = make_model(self, obs_space, action_space, config)
    else:
        self.model = ModelCatalog.get_model_v2(obs_space, action_space, logit_dim, self.config['model'], framework='tf')
    if existing_inputs:
        self._state_in = [v for (k, v) in existing_inputs.items() if k.startswith('state_in_')]
        if self._state_in:
            self._seq_lens = existing_inputs['seq_lens']
    else:
        self._state_in = [tf.placeholder(shape=((None,) + s.shape), dtype=s.dtype) for s in self.model.get_initial_state()]
    (model_out, self._state_out) = self.model(self._input_dict, self._state_in, self._seq_lens)
    if action_sampler_fn:
        (action_sampler, action_logp) = action_sampler_fn(self, self.model, self._input_dict, obs_space, action_space, config)
    else:
        action_dist = self.dist_class(model_out, self.model)
        action_sampler = action_dist.sample()
        action_logp = action_dist.sampled_action_logp()
    sess = (tf.get_default_session() or tf.Session())
    if get_batch_divisibility_req:
        batch_divisibility_req = get_batch_divisibility_req(self)
    else:
        batch_divisibility_req = 1
    TFPolicy.__init__(self, obs_space, action_space, sess, obs_input=obs, action_sampler=action_sampler, action_logp=action_logp, loss=None, loss_inputs=[], model=self.model, state_inputs=self._state_in, state_outputs=self._state_out, prev_action_input=prev_actions, prev_reward_input=prev_rewards, seq_lens=self._seq_lens, max_seq_len=config['model']['max_seq_len'], batch_divisibility_req=batch_divisibility_req)
    before_loss_init(self, obs_space, action_space, config)
    if (not existing_inputs):
        self._initialize_loss()
Initialize a dynamic TF policy.

Arguments:
    observation_space (gym.Space): Observation space of the policy.
    action_space (gym.Space): Action space of the policy.
    config (dict): Policy-specific configuration data.
    loss_fn (func): function that returns a loss tensor the policy
        graph, and dict of experience tensor placeholders
    stats_fn (func): optional function that returns a dict of
        TF fetches given the policy and batch input tensors
    grad_stats_fn (func): optional function that returns a dict of
        TF fetches given the policy and loss gradient tensors
    before_loss_init (func): optional function to run prior to loss
        init that takes the same arguments as __init__
    make_model (func): optional function that returns a ModelV2 object
        given (policy, obs_space, action_space, config).
        All policy variables should be created in this function. If not
        specified, a default model will be created.
    action_sampler_fn (func): optional function that returns a
        tuple of action and action logp tensors given
        (policy, model, input_dict, obs_space, action_space, config).
        If not specified, a default action distribution will be used.
    existing_inputs (OrderedDict): when copying a policy, this
        specifies an existing dict of placeholders to use instead of
        defining new ones
    existing_model (ModelV2): when copying a policy, this specifies
        an existing model to clone and share weights with
    get_batch_divisibility_req (func): optional function that returns
        the divisibility requirement for sample batches
    obs_include_prev_action_reward (bool): whether to include the
        previous action and reward in the model input
def __init__(self, obs_space, action_space, config, loss_fn, stats_fn=None, grad_stats_fn=None, before_loss_init=None, make_model=None, action_sampler_fn=None, existing_inputs=None, existing_model=None, get_batch_divisibility_req=None, obs_include_prev_action_reward=True):
    'Initialize a dynamic TF policy.\n\n        Arguments:\n            observation_space (gym.Space): Observation space of the policy.\n            action_space (gym.Space): Action space of the policy.\n            config (dict): Policy-specific configuration data.\n            loss_fn (func): function that returns a loss tensor the policy\n                graph, and dict of experience tensor placeholders\n            stats_fn (func): optional function that returns a dict of\n                TF fetches given the policy and batch input tensors\n            grad_stats_fn (func): optional function that returns a dict of\n                TF fetches given the policy and loss gradient tensors\n            before_loss_init (func): optional function to run prior to loss\n                init that takes the same arguments as __init__\n            make_model (func): optional function that returns a ModelV2 object\n                given (policy, obs_space, action_space, config).\n                All policy variables should be created in this function. If not\n                specified, a default model will be created.\n            action_sampler_fn (func): optional function that returns a\n                tuple of action and action logp tensors given\n                (policy, model, input_dict, obs_space, action_space, config).\n                If not specified, a default action distribution will be used.\n            existing_inputs (OrderedDict): when copying a policy, this\n                specifies an existing dict of placeholders to use instead of\n                defining new ones\n            existing_model (ModelV2): when copying a policy, this specifies\n                an existing model to clone and share weights with\n            get_batch_divisibility_req (func): optional function that returns\n                the divisibility requirement for sample batches\n            obs_include_prev_action_reward (bool): whether to include the\n                previous action and reward in the model input\n        '
    self.config = config
    self._loss_fn = loss_fn
    self._stats_fn = stats_fn
    self._grad_stats_fn = grad_stats_fn
    self._obs_include_prev_action_reward = obs_include_prev_action_reward
    prev_actions = None
    prev_rewards = None
    if (existing_inputs is not None):
        obs = existing_inputs[SampleBatch.CUR_OBS]
        if self._obs_include_prev_action_reward:
            prev_actions = existing_inputs[SampleBatch.PREV_ACTIONS]
            prev_rewards = existing_inputs[SampleBatch.PREV_REWARDS]
    else:
        obs = tf.placeholder(tf.float32, shape=([None] + list(obs_space.shape)), name='observation')
        if self._obs_include_prev_action_reward:
            prev_actions = ModelCatalog.get_action_placeholder(action_space)
            prev_rewards = tf.placeholder(tf.float32, [None], name='prev_reward')
    self._input_dict = {SampleBatch.CUR_OBS: obs, SampleBatch.PREV_ACTIONS: prev_actions, SampleBatch.PREV_REWARDS: prev_rewards, 'is_training': self._get_is_training_placeholder()}
    self._seq_lens = tf.placeholder(dtype=tf.int32, shape=[None], name='seq_lens')
    if action_sampler_fn:
        if (not make_model):
            raise ValueError('make_model is required if action_sampler_fn is given')
        self.dist_class = None
    else:
        (self.dist_class, logit_dim) = ModelCatalog.get_action_dist(action_space, self.config['model'])
    if existing_model:
        self.model = existing_model
    elif make_model:
        self.model = make_model(self, obs_space, action_space, config)
    else:
        self.model = ModelCatalog.get_model_v2(obs_space, action_space, logit_dim, self.config['model'], framework='tf')
    if existing_inputs:
        self._state_in = [v for (k, v) in existing_inputs.items() if k.startswith('state_in_')]
        if self._state_in:
            self._seq_lens = existing_inputs['seq_lens']
    else:
        self._state_in = [tf.placeholder(shape=((None,) + s.shape), dtype=s.dtype) for s in self.model.get_initial_state()]
    (model_out, self._state_out) = self.model(self._input_dict, self._state_in, self._seq_lens)
    if action_sampler_fn:
        (action_sampler, action_logp) = action_sampler_fn(self, self.model, self._input_dict, obs_space, action_space, config)
    else:
        action_dist = self.dist_class(model_out, self.model)
        action_sampler = action_dist.sample()
        action_logp = action_dist.sampled_action_logp()
    sess = (tf.get_default_session() or tf.Session())
    if get_batch_divisibility_req:
        batch_divisibility_req = get_batch_divisibility_req(self)
    else:
        batch_divisibility_req = 1
    TFPolicy.__init__(self, obs_space, action_space, sess, obs_input=obs, action_sampler=action_sampler, action_logp=action_logp, loss=None, loss_inputs=[], model=self.model, state_inputs=self._state_in, state_outputs=self._state_out, prev_action_input=prev_actions, prev_reward_input=prev_rewards, seq_lens=self._seq_lens, max_seq_len=config['model']['max_seq_len'], batch_divisibility_req=batch_divisibility_req)
    before_loss_init(self, obs_space, action_space, config)
    if (not existing_inputs):
        self._initialize_loss()