class_docstr: Q-Learning with deep neural network to learn the control policy. 
  Uses a deep neural network model to predict the expected utility (Q-value) of executing an action in a given state. 
  
  Reference: https://arxiv.org/abs/1312.5602
  Parameters:
  -----------
  env_name: string
      The environment that the agent will explore. 
      Check: https://gym.openai.com/envs
  epsilon: float
      The epsilon-greedy value. The probability that the agent should select a random action instead of
      the action that will maximize the expected utility. 
  gamma: float
      Determines how much the agent should consider future rewards. 
  decay_rate: float
      The rate of decay for the epsilon value after each epoch.
  min_epsilon: float
      The value which epsilon will approach as the training progresses.
class_docstr_tok: ["Q-Learning","with","deep","neural","network","to","learn","the","control","policy",".","Uses","a","deep","neural","network","model","to","predict","the","expected","utility","(","Q-value",")","of","executing","an","action","in","a","given","state",".","Reference",":","https",":","\/\/arxiv.org\/abs\/1312.5602","Parameters",":","--","--","--","--","--","-","env_name",":","string","The","environment","that","the","agent","will","explore",".","Check",":","https",":","\/\/gym.openai.com\/envs","epsilon",":","float","The","epsilon-greedy","value",".","The","probability","that","the","agent","should","select","a","random","action","instead","of","the","action","that","will","maximize","the","expected","utility",".","gamma",":","float","Determines","how","much","the","agent","should","consider","future","rewards",".","decay_rate",":","float","The","rate","of","decay","for","the","epsilon","value","after","each","epoch",".","min_epsilon",":","float","The","value","which","epsilon","will","approach","as","the","training","progresses","."]
code: def train(self, n_epochs=500, batch_size=32):
      max_reward = 0
  
      for epoch in range(n_epochs):
          state = self.env.reset()
          total_reward = 0
  
          epoch_loss = []
          while True:
              action = self._select_action(state)
              # Take a step
              new_state, reward, done, _ = self.env.step(action)
  
              self._memorize(state, action, reward, new_state, done)
  
              # Sample replay batch from memory
              _batch_size = min(len(self.memory), batch_size)
              replay = random.sample(self.memory, _batch_size)
  
              # Construct training set from replay
              X, y = self._construct_training_set(replay)
  
              # Learn control policy
              loss = self.model.train_on_batch(X, y)
              epoch_loss.append(loss)
  
              total_reward += reward
              state = new_state
  
              if done:
                  break
  
          epoch_loss = np.mean(epoch_loss)
  
          # Reduce the epsilon parameter
          self.epsilon = self.min_epsilon + (
              1.0 - self.min_epsilon
          ) * np.exp(-self.decay_rate * epoch)
  
          max_reward = max(max_reward, total_reward)
  
          print(
              "%d [Loss: %.4f, Reward: %s, Epsilon: %.4f, Max Reward: %s]"
              % (
                  epoch,
                  epoch_loss,
                  total_reward,
                  self.epsilon,
                  max_reward,
              )
          )
  
      print("Training Finished")
  
file_path: ML-From-Scratch/mlfromscratch/reinforcement_learning/deep_q_network.py
imports: from __future__ import print_function, division
  import random
  import numpy
  import gym
  from collections import deque
label_desc: Use image node_id 6 for calling the DeepQNetwork obj's underlying member method code with example usage: obj.train(n_epochs, batch_size) without return types