Last active
October 4, 2019 12:04
-
-
Save michaelchughes/ec79770402bfa9327a93074a3a7b45d0 to your computer and use it in GitHub Desktop.
Using log of standard deviation parameterization of the Normal
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
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