Skip to content

Commit

Permalink
lnlike opt for emcee
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirky committed Jul 16, 2024
1 parent 5dbefab commit 806a25f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions alabi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,13 @@ def lnprob(self, theta):

if not hasattr(self, 'lnprior'):
raise NameError("lnprior has not been specified")

if not hasattr(self, 'like_fn'):
self.like_fn = self.evaluate

theta = np.asarray(theta).reshape(1,-1)

lnp = self.evaluate(theta) + self.lnprior(theta)
lnp = self.like_fn(theta) + self.lnprior(theta)

return lnp

Expand All @@ -690,7 +693,7 @@ def find_map(self, theta0=None, lnprior=None, method="nelder-mead", nRestarts=15
raise NotImplementedError("Not implemented.")


def run_emcee(self, lnprior=None, nwalkers=None, nsteps=int(5e4), sampler_kwargs={}, run_kwargs={},
def run_emcee(self, like_fn="surrogate", lnprior=None, nwalkers=None, nsteps=int(5e4), sampler_kwargs={}, run_kwargs={},
opt_init=True, multi_proc=True, lnprior_comment=None):
"""
Use the ``emcee`` affine-invariant MCMC package to sample the trained GP surrogate model.
Expand Down Expand Up @@ -720,6 +723,14 @@ def run_emcee(self, lnprior=None, nwalkers=None, nsteps=int(5e4), sampler_kwargs

import emcee

# specify likelihood function (true function or surrogate model)
if like_fn.lower() == "true":
print("Initializing dynesty with self.fn as likelihood.")
self.like_fn = self.fn
else:
print("Initializing dynesty with self.evaluate surrogate model as likelihood.")
self.like_fn = self.evaluate

if lnprior is None:
print(f"No lnprior specified. Defaulting to uniform prior with bounds {self.bounds}")
self.lnprior = partial(ut.lnprior_uniform, bounds=self.bounds)
Expand Down

0 comments on commit 806a25f

Please sign in to comment.