add eps to avoid NaN

I tracked some NaN's I was getting down to here. It happens when std is a small number, then var is even smaller, and log_density=inf. There are some problems where the agent will learn to use small standard deviations because jittering movements have a high cost, this makes those more stable.
This commit is contained in:
Mike Clark
2017-11-04 16:24:54 +08:00
committed by GitHub
parent 9ef309696f
commit deab7043fc
+1 -1
View File
@@ -154,7 +154,7 @@ class GaussianActorNet(nn.Module, BasicNet):
def log_density(self, x, mean, log_std, std):
var = std.pow(2)
log_density = -(x - mean).pow(2) / (2 * var) - 0.5 * torch.log(2 * Variable(torch.FloatTensor([np.pi])).expand_as(x)) - log_std
log_density = -(x - mean).pow(2) / (2 * var + 1e-5) - 0.5 * torch.log(2 * Variable(torch.FloatTensor([np.pi])).expand_as(x)) - log_std
return log_density.sum(1)
def entropy(self, std):