parameters: (self,
                 player_id,
                 state_representation_size,
                 num_actions,
                 hidden_layers_sizes=128,
                 replay_buffer_capacity=10000,
                 batch_size=128,
                 replay_buffer_class=ReplayBuffer,
                 learning_rate=0.01,
                 update_target_network_every=1000,
                 learn_every=10,
                 discount_factor=1.0,
                 min_buffer_size_to_learn=1000,
                 epsilon_start=1.0,
                 epsilon_end=0.1,
                 epsilon_decay_duration=int(1e6),
                 optimizer_str="sgd",
                 loss_str="mse")
docstring: Initialize the DQN agent.
docstring_summary: Initialize the DQN agent.
docstring_tokens: Initialize the DQN agent .
function: def __init__(self,
                 player_id,
                 state_representation_size,
                 num_actions,
                 hidden_layers_sizes=128,
                 replay_buffer_capacity=10000,
                 batch_size=128,
                 replay_buffer_class=ReplayBuffer,
                 learning_rate=0.01,
                 update_target_network_every=1000,
                 learn_every=10,
                 discount_factor=1.0,
                 min_buffer_size_to_learn=1000,
                 epsilon_start=1.0,
                 epsilon_end=0.1,
                 epsilon_decay_duration=int(1e6),
                 optimizer_str="sgd",
                 loss_str="mse"):
      """Initialize the DQN agent."""
  
      # This call to locals() is used to store every argument used to initialize
      # the class instance, so it can be copied with no hyperparameter change.
      self._kwargs = locals()
  
      self.player_id = player_id
      self._num_actions = num_actions
      if isinstance(hidden_layers_sizes, int):
        hidden_layers_sizes = [hidden_layers_sizes]
      self._layer_sizes = hidden_layers_sizes
      self._batch_size = batch_size
      self._update_target_network_every = update_target_network_every
      self._learn_every = learn_every
      self._min_buffer_size_to_learn = min_buffer_size_to_learn
      self._discount_factor = discount_factor
  
      self._epsilon_start = epsilon_start
      self._epsilon_end = epsilon_end
      self._epsilon_decay_duration = epsilon_decay_duration
  
      # TODO(author6) Allow for optional replay buffer config.
      if not isinstance(replay_buffer_capacity, int):
        raise ValueError("Replay buffer capacity not an integer.")
      self._replay_buffer = replay_buffer_class(replay_buffer_capacity)
      self._prev_timestep = None
      self._prev_action = None
  
      # Step counter to keep track of learning, eps decay and target network.
      self._step_counter = 0
  
      # Keep track of the last training loss achieved in an update step.
      self._last_loss_value = None
  
      # Create the Q-network instances
      self._q_network = MLP(state_representation_size, self._layer_sizes,
                            num_actions)
  
      self._target_q_network = MLP(state_representation_size, self._layer_sizes,
                                   num_actions)
  
      if loss_str == "mse":
        self.loss_class = F.mse_loss
      elif loss_str == "huber":
        self.loss_class = F.smooth_l1_loss
      else:
        raise ValueError("Not implemented, choose from 'mse', 'huber'.")
  
      if optimizer_str == "adam":
        self._optimizer = torch.optim.Adam(
            self._q_network.parameters(), lr=learning_rate)
      elif optimizer_str == "sgd":
        self._optimizer = torch.optim.SGD(
            self._q_network.parameters(), lr=learning_rate)
      else:
        raise ValueError("Not implemented, choose from 'adam' and 'sgd'.")
function_tokens: def __init__ ( self , player_id , state_representation_size , num_actions , hidden_layers_sizes = 128 , replay_buffer_capacity = 10000 , batch_size = 128 , replay_buffer_class = ReplayBuffer , learning_rate = 0.01 , update_target_network_every = 1000 , learn_every = 10 , discount_factor = 1.0 , min_buffer_size_to_learn = 1000 , epsilon_start = 1.0 , epsilon_end = 0.1 , epsilon_decay_duration = int ( 1e6 ) , optimizer_str = "sgd" , loss_str = "mse" ) : # This call to locals() is used to store every argument used to initialize # the class instance, so it can be copied with no hyperparameter change. self . _kwargs = locals ( ) self . player_id = player_id self . _num_actions = num_actions if isinstance ( hidden_layers_sizes , int ) : hidden_layers_sizes = [ hidden_layers_sizes ] self . _layer_sizes = hidden_layers_sizes self . _batch_size = batch_size self . _update_target_network_every = update_target_network_every self . _learn_every = learn_every self . _min_buffer_size_to_learn = min_buffer_size_to_learn self . _discount_factor = discount_factor self . _epsilon_start = epsilon_start self . _epsilon_end = epsilon_end self . _epsilon_decay_duration = epsilon_decay_duration # TODO(author6) Allow for optional replay buffer config. if not isinstance ( replay_buffer_capacity , int ) : raise ValueError ( "Replay buffer capacity not an integer." ) self . _replay_buffer = replay_buffer_class ( replay_buffer_capacity ) self . _prev_timestep = None self . _prev_action = None # Step counter to keep track of learning, eps decay and target network. self . _step_counter = 0 # Keep track of the last training loss achieved in an update step. self . _last_loss_value = None # Create the Q-network instances self . _q_network = MLP ( state_representation_size , self . _layer_sizes , num_actions ) self . _target_q_network = MLP ( state_representation_size , self . _layer_sizes , num_actions ) if loss_str == "mse" : self . loss_class = F . mse_loss elif loss_str == "huber" : self . loss_class = F . smooth_l1_loss else : raise ValueError ( "Not implemented, choose from 'mse', 'huber'." ) if optimizer_str == "adam" : self . _optimizer = torch . optim . Adam ( self . _q_network . parameters ( ) , lr = learning_rate ) elif optimizer_str == "sgd" : self . _optimizer = torch . optim . SGD ( self . _q_network . parameters ( ) , lr = learning_rate ) else : raise ValueError ( "Not implemented, choose from 'adam' and 'sgd'." )