We solve the continuous Mountain Car problem using continuous A2C as follows:
- Import all the necessary packages and create a continuous Mountain Car instance:
>>> import gym>>> import torch>>> import torch.nn as nn>>> import torch.nn.functional as F>>> env = gym.make('MountainCarContinuous-v0')
- Let's start with the actor-critic neural network model:
>>> class ActorCriticModel(nn.Module): ... def __init__(self, n_input, n_output, n_hidden): ... super(ActorCriticModel, self).__init__() ... self.fc = nn.Linear(n_input, n_hidden) ... self.mu = nn.Linear(n_hidden, n_output) ... self.sigma = nn.Linear(n_hidden, n_output) ... self.value = nn.Linear(n_hidden, 1) ... self.distribution = torch.distributions.Normal ... ... def forward(self, ...