Created
April 8, 2018 05:32
-
-
Save joelouismarino/eb81848b5616de71ed06cba9dc36770a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import torch | |
from torch.distributions import Normal | |
# standard univariate Gaussian (Normal) | |
mean = torch.zeros(1) | |
std = torch.ones(1) | |
# evaluate at the origin | |
value = torch.zeros(1) | |
# using built-in functions | |
normal = Normal(mean, std) | |
log_density = normal.log_prob(value) | |
# implemented from scratch | |
var = std.pow(2) | |
log_density = -0.5 * (math.log(2 * math.pi) + var.log() + (value - mean).pow(2) / var) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment