Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelchughes/ec79770402bfa9327a93074a3a7b45d0 to your computer and use it in GitHub Desktop.
Save michaelchughes/ec79770402bfa9327a93074a3a7b45d0 to your computer and use it in GitHub Desktop.
Using log of standard deviation parameterization of the Normal
S = 10 # num samples throughout
## FIRST, REMEMBER THE COMMON PARAMETERIZATION
# x ~ Normal(m, sigma^2)
# m is a real number
# sigma >= 0 is a standard deviation
m = 2
sigma = 0.1
# Draw samples
x_S = stats.norm.rvs(m, sigma, size=S)
# Compute logpdf at each sample
logp_S = stats.norm.logpdf(x_S, m, sigma)
print(x_S)
print(logp_S)
### SWITCH TO USING LOG-OF-STDDEV PARAMETERZATION
# x ~ Normal(m, (e^{s})^2 )
# m is a real number
# s is a real number
m = 2.0
s = np.log(0.1)
# Draw samples
x_S = stats.norm.rvs(m, np.exp(s), size=S)
logp_S = stats.norm.logpdf(x_S, m, np.exp(s))
print(x_S)
print(logp_S)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment