Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. class TNET():
  2. """
  3. Target network is for calculating the maximum estimated Q-value in given action a.
  4. """
  5. def __init__(self, in_units, out_units, hidden_units=250):
  6. self.in_units = in_units
  7. self.out_units = out_units
  8. self.hidden_units = hidden_units
  9. self._model()
  10.  
  11. def _model(self):
  12. with tf.variable_scope('tnet'):
  13. # input layer
  14. self.x = tf.placeholder(tf.float32, shape=(None, self.in_units))
  15.  
  16. # from input layer to hidden layer1
  17. W1=tf.get_variable('W1', shape=(self.in_units, self.hidden_units), initializer=tf.random_normal_initializer())
  18. # from hidden layer1 to hiiden layer2
  19. W2=tf.get_variable('W2', shape=(self.hidden_units, self.hidden_units), initializer=tf.random_normal_initializer())
  20. # from hidden layer2 to output layer
  21. W3=tf.get_variable('W3', shape=(self.hidden_units, self.out_units), initializer=tf.random_normal_initializer())
  22.  
  23. # the bias of hidden layer1
  24. b1=tf.get_variable('b1', shape=(self.hidden_units), initializer=tf.zeros_initializer())
  25. # the bias of hidden layer2
  26. b2=tf.get_variable('b2', shape=(self.hidden_units), initializer=tf.zeros_initializer())
  27.  
  28. # the ouput of hidden layer1
  29. h1=tf.nn.tanh(tf.matmul(self.x, W1)+b1)
  30. # the output of hidden layer2
  31. h2=tf.nn.tanh(tf.matmul(h1, W2)+b2)
  32.  
  33. # the output of output layer, that is, Q-value
  34. self.q=tf.matmul(h2, W3)
  35.  
  36. self.params = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope='tnet')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement