Aan de slagGa gratis aan de slag

Critic network

Actor Critic methods require two very different neural networks.

The architecture for the actor network is identical to that of the policy network you used for REINFORCE, so you can reuse the PolicyNetwork class.

However, the critic network is something you haven't implemented so far. The critic aims to approximate the state value function \(V(s_t)\), rather than the action value function \(Q(s_t, a_t)\) approximated by Q-Networks.

You will now implement the Critic network module which you will use in A2C.

Deze oefening maakt deel uit van de cursus

Deep Reinforcement Learning in Python

Cursus bekijken

Oefeninstructies

  • Fill in the desired dimension for the second fully connected layer so that it outputs one state value.
  • Obtain the value returned by the forward pass through the critic network.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

class Critic(nn.Module):
    def __init__(self, state_size):
        super(Critic, self).__init__()
        self.fc1 = nn.Linear(state_size, 64)
        # Fill in the desired dimensions
        self.fc2 = nn.Linear(____)

    def forward(self, state):
        x = torch.relu(self.fc1(torch.tensor(state)))
        # Calculate the output value
        value = ____
        return value

critic_network = Critic(8)
state_value = critic_network(torch.rand(8))
print('State value:', state_value)
Code bewerken en uitvoeren