Skip to content

Commit

Permalink
Normal Precision Parameter Recovery (#133)
Browse files Browse the repository at this point in the history
* remove print statemnt

* check for the recovery of precision

* trying some different values
  • Loading branch information
wd60622 authored Sep 29, 2024
1 parent b4af286 commit 7547a3e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 0 additions & 1 deletion conjugate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,6 @@ def normal(
"beta": beta_post,
}
)
print(prior.__class__)

return prior.__class__(**kwargs)

Expand Down
26 changes: 26 additions & 0 deletions scripts/parameter-recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,31 @@ def get_posterior(data):
return sample_data, get_posterior, theta


def normal_normal_gamma():
from conjugate.distributions import Normal, NormalGamma
from conjugate.models import normal

true_mu = 1.5
true_precision = 0.25

true_distribution = Normal(mu=true_mu, sigma=(1 / true_precision) ** 0.5)

def sample_data(n, rng):
return true_distribution.dist.rvs(size=n, random_state=rng)

prior = NormalGamma(mu=0, lam=1, alpha=2, beta=1)

def get_posterior(data):
return normal(
n=len(data),
x_total=data.sum(),
x2_total=(data**2).sum(),
prior=prior,
).gamma

return sample_data, get_posterior, true_precision


def parameter_recovery(
ns: list[int],
sample_data,
Expand Down Expand Up @@ -359,4 +384,5 @@ def main(setup, rng, ns):
setup = inverse_gamma_known_rate
setup = normal_known_mean_alternative
setup = weibull_known_shape
setup = normal_normal_gamma
main(setup, ns=ns, rng=rng)

0 comments on commit 7547a3e

Please sign in to comment.