original_docstring: 
          Retrieve a group of samples from the memory and for each of them update the learning equation, then train
          
docstring: Retrieve a group of samples from the memory and for each of them update the learning equation, then train
docstring_tokens: Retrieve a group of samples from the memory and for each of them update the learning equation then train
code: def _replay(self):
          """
          Retrieve a group of samples from the memory and for each of them update the learning equation, then train
          """
          batch = self._Memory.get_samples(self._Model.batch_size)
  
          if len(batch) > 0:  # if the memory is full enough
              states = np.array([val[0] for val in batch])  # extract states from the batch
              next_states = np.array([val[3] for val in batch])  # extract next states from the batch
  
              # prediction
              q_s_a = self._Model.predict_batch(states)  # predict Q(state), for every sample
              q_s_a_d = self._Model.predict_batch(next_states)  # predict Q(next_state), for every sample
  
              # setup training arrays
              x = np.zeros((len(batch), self._num_states))
              y = np.zeros((len(batch), self._num_actions))
  
              for i, b in enumerate(batch):
                  state, action, reward, _ = b[0], b[1], b[2], b[3]  # extract data from one sample
                  current_q = q_s_a[i]  # get the Q(state) predicted before
                  current_q[action] = reward + self._gamma * np.amax(q_s_a_d[i])  # update Q(state, action)
                  x[i] = state
                  y[i] = current_q  # Q(state) that includes the updated action value
  
              self._Model.train_batch(x, y)  # train the NN
              self._model_training_loss.append(self._Model.training_loss)
code_tokens: def _replay ( self ) : batch = self . _Memory . get_samples ( self . _Model . batch_size ) if len ( batch ) > 0 : states = np . array ( [ val [ 0 ] for val in batch ] ) next_states = np . array ( [ val [ 3 ] for val in batch ] ) q_s_a = self . _Model . predict_batch ( states ) q_s_a_d = self . _Model . predict_batch ( next_states ) x = np . zeros ( ( len ( batch ) , self . _num_states ) ) y = np . zeros ( ( len ( batch ) , self . _num_actions ) ) for i , b in enumerate ( batch ) : state , action , reward , _ = b [ 0 ] , b [ 1 ] , b [ 2 ] , b [ 3 ] current_q = q_s_a [ i ] current_q [ action ] = reward + self . _gamma * np . amax ( q_s_a_d [ i ] ) x [ i ] = state y [ i ] = current_q self . _Model . train_batch ( x , y ) self . _model_training_loss . append ( self . _Model . training_loss )
short_docstring: Retrieve a group of samples from the memory and for each of them update the learning equation, then train
short_docstring_tokens: Retrieve a group of samples from the memory and for each of them update the learning equation then train
comment: """
          Retrieve a group of samples from the memory and for each of them update the learning equation, then train
          """$SEP$# if the memory is full enough$SEP$# extract states from the batch$SEP$# extract next states from the batch$SEP$# prediction$SEP$# predict Q(state), for every sample$SEP$# predict Q(next_state), for every sample$SEP$# setup training arrays$SEP$# extract data from one sample$SEP$# get the Q(state) predicted before$SEP$# update Q(state, action)$SEP$# Q(state) that includes the updated action value$SEP$# train the NN