class_docstr: DDPG class
class_docstr_tok: ["DDPG","class"]
code: def __init__(self, action_dim, state_dim, action_range):
      self.memory = np.zeros(
          (MEMORY_CAPACITY, state_dim * 2 + action_dim + 1),
          dtype=np.float32,
      )
      self.pointer = 0
      self.action_dim, self.state_dim, self.action_range = (
          action_dim,
          state_dim,
          action_range,
      )
      self.var = VAR
  
      W_init = tf.random_normal_initializer(mean=0, stddev=0.3)
      b_init = tf.constant_initializer(0.1)
  
      def get_actor(input_state_shape, name=""):
          """
          Build actor network
          :param input_state_shape: state
          :param name: name
          :return: act
          """
          input_layer = tl.layers.Input(
              input_state_shape, name="A_input"
          )
          layer = tl.layers.Dense(
              n_units=64,
              act=tf.nn.relu,
              W_init=W_init,
              b_init=b_init,
              name="A_l1",
          )(input_layer)
          layer = tl.layers.Dense(
              n_units=64,
              act=tf.nn.relu,
              W_init=W_init,
              b_init=b_init,
              name="A_l2",
          )(layer)
          layer = tl.layers.Dense(
              n_units=action_dim,
              act=tf.nn.tanh,
              W_init=W_init,
              b_init=b_init,
              name="A_a",
          )(layer)
          layer = tl.layers.Lambda(lambda x: action_range * x)(layer)
          return tl.models.Model(
              inputs=input_layer, outputs=layer, name="Actor" + name
          )
  
      def get_critic(input_state_shape, input_action_shape, name=""):
          """
          Build critic network
          :param input_state_shape: state
          :param input_action_shape: act
          :param name: name
          :return: Q value Q(s,a)
          """
          state_input = tl.layers.Input(
              input_state_shape, name="C_s_input"
          )
          action_input = tl.layers.Input(
              input_action_shape, name="C_a_input"
          )
          layer = tl.layers.Concat(1)([state_input, action_input])
          layer = tl.layers.Dense(
              n_units=64,
              act=tf.nn.relu,
              W_init=W_init,
              b_init=b_init,
              name="C_l1",
          )(layer)
          layer = tl.layers.Dense(
              n_units=64,
              act=tf.nn.relu,
              W_init=W_init,
              b_init=b_init,
              name="C_l2",
          )(layer)
          layer = tl.layers.Dense(
              n_units=1, W_init=W_init, b_init=b_init, name="C_out"
          )(layer)
          return tl.models.Model(
              inputs=[state_input, action_input],
              outputs=layer,
              name="Critic" + name,
          )
  
      self.actor = get_actor([None, state_dim])
      self.critic = get_critic([None, state_dim], [None, action_dim])
      self.actor.train()
      self.critic.train()
  
      def copy_para(from_model, to_model):
          """
          Copy parameters for soft updating
          :param from_model: latest model
          :param to_model: target model
          :return: None
          """
          for i, j in zip(
              from_model.trainable_weights, to_model.trainable_weights
          ):
              j.assign(i)
  
      self.actor_target = get_actor([None, state_dim], name="_target")
      copy_para(self.actor, self.actor_target)
      self.actor_target.eval()
  
      self.critic_target = get_critic(
          [None, state_dim], [None, action_dim], name="_target"
      )
      copy_para(self.critic, self.critic_target)
      self.critic_target.eval()
  
      self.ema = tf.train.ExponentialMovingAverage(
          decay=1 - TAU
      )  # soft replacement
  
      self.actor_opt = tf.optimizers.Adam(LR_A)
      self.critic_opt = tf.optimizers.Adam(LR_C)
  
file_path: TensorLayer/examples/reinforcement_learning/tutorial_DDPG.py
imports: import argparse
  import os
  import time
  import gym
  import matplotlib.pyplot
  import numpy
  import tensorflow
  import tensorlayer
label_desc: Use image node_id 1 to create a new DDPG object from inherited base classes: object with example: obj = DDPG(action_dim, state_dim, action_range)