Aan de slagGa gratis aan de slag

The Q-Network architecture

You are almost ready to train your first Deep Reinforcement Learning agent! Before you can go ahead with your first complete training loop, you need a neural network architecture to drive the agent's decisions and its ability to learn.

You will modify the generic architecture you defined in an earlier exercise. torch and torch.nn are imported into your exercises.

Deze oefening maakt deel uit van de cursus

Deep Reinforcement Learning in Python

Cursus bekijken

Oefeninstructies

  • Instantiate the first hidden layer; its input will be the environment state, with dimension state_size.
  • Instantiate the output layer; it provides the Q-values for each action, with dimension action_size.
  • Complete the forward() method; use the torch.relu activation function for this example.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

class QNetwork(nn.Module):
    def __init__(self, state_size, action_size):
        super(QNetwork, self).__init__()
        # Instantiate the first hidden layer
        self.fc1 = nn.Linear(____, ____)
        self.fc2 = nn.Linear(64, 64)
        # Instantiate the output layer
        self.fc3 = nn.Linear(____, ____)
    def forward(self, state):
        # Ensure the ReLU activation function is used
        x = ____(self.fc1(torch.tensor(state)))
        x = ____(self.fc2(x))
        return self.fc3(x)
Code bewerken en uitvoeren