tristandeleu / pytorch-maml-rl

Reinforcement Learning with Model-Agnostic Meta-Learning in Pytorch
MIT License
827 stars 158 forks source link

question about /maml_rl/policies/categorical_mlp.py #32

Closed Rui-Chun closed 5 years ago

Rui-Chun commented 5 years ago
def forward(self, input, params=None):

if params is None: params = OrderedDict(self.named_parameters()) output = input for i in range(1, self.num_layers): output = F.linear(output, weight=params['layer{0}.weight'.format(i)], bias=params['layer{0}.bias'.format(i)]) output = self.nonlinearity(output) logits = F.linear(output, weight=params['layer{0}.weight'.format(self.num_layers)], bias=params['layer{0}.bias'.format(self.num_layers)]) return Categorical(logits=logits)

At the end of categorical_mlp.py, the forward function return the above result.

But should not it be " return Categorical(logits) ", since logits means the probability, right?

tristandeleu commented 5 years ago

logits are the values you would apply a softmax over to get the probabilities. They're not quite probabilities themselves (in particular, these values might be negative or don't sum to 1), and that's why we use Categorical(logits=logits). Categorical is responsible for applying that softmax operation.