Skip to content

Commit

Permalink
Merge pull request #2 from alexander-group/dev
Browse files Browse the repository at this point in the history
Suppress the too many RuntimeWarnings
  • Loading branch information
noahfranz13 authored Jul 16, 2024
2 parents 29fe773 + 40317e5 commit 02b8eb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/syncfit/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def do_dynesty(nu:list[float], F_mJy:list[float], F_error:list[float],
lum_dist:float=None, t:float=None,
model:SyncfitModel=MQModel, fix_p:float=None,
upperlimits:list[bool]=None, ncores:int=1, seed:int=None,
**dynesty_kwargs
run_kwargs={}, dynesty_kwargs={}, logprob_kwargs={}
) -> tuple[list[float],list[float]]:
"""
Fit the data with the given model using the dynesty nested sampling package
Expand All @@ -34,7 +34,11 @@ def do_dynesty(nu:list[float], F_mJy:list[float], F_error:list[float],
upperlimits (list[bool]): True if the point is an upperlimit, False otherwise.
ncores (int) : The number of cores to run on, default is 1 and won't multiprocess
seed (int): The seed for the random number generator passed to dynesty,
dynesty_kwargs : kwargs to pass to dynesty
run_kwargs (dict) : kwargs to pass to dynesty.run_sampler
dynesty_kwargs (dict) : kwargs to pass to dynesty.DynamicNestedSampler
logprob_kwargs (dict) : kwargs to pass to the logprob. For the most part this is
handled internally but in case someone wrote a custom
model they should be able to pass in custom kwargs.
Returns:
flat_samples, log_prob
"""
Expand All @@ -43,6 +47,11 @@ def do_dynesty(nu:list[float], F_mJy:list[float], F_error:list[float],

# get the extra args
dynesty_args = model.get_kwargs(nu, F_mJy, F_error, lum_dist=lum_dist, t=t, p=fix_p)

# combine these with the logprob_kwargs
# make the logprob_kwargs second so it overwrites anything we set here
dynesty_args = dynesty_args | logprob_kwargs

ndim = len(model.get_labels(p=fix_p))
rstate = np.random.default_rng(seed)

Expand All @@ -60,7 +69,7 @@ def do_dynesty(nu:list[float], F_mJy:list[float], F_error:list[float],
ptform_kwargs=dynesty_args,
pool=pool, **dynesty_kwargs)
try:
dsampler.run_nested()
dsampler.run_nested(**run_kwargs)
except PicklingError:
raise ValueError(
'The override decorator syntax is not currently supported for dynesty!'
Expand Down
11 changes: 7 additions & 4 deletions src/syncfit/models/syncfit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'''
from dataclasses import dataclass
from abc import ABC, abstractmethod
import warnings
import numpy as np

class _SyncfitModelMeta(type):
Expand Down Expand Up @@ -132,10 +133,12 @@ def loglik(cls, theta, nu, F, F_error, p=None, **kwargs):
Returns:
The logarithmic likelihood of that theta position
'''
if p is not None:
model_result = cls.SED(nu, p, *theta, **kwargs)
else:
model_result = cls.SED(nu, *theta, **kwargs)
with warnings.catch_warnings():
warnings.simplefilter('ignore')
if p is not None:
model_result = cls.SED(nu, p, *theta, **kwargs)
else:
model_result = cls.SED(nu, *theta, **kwargs)

if not np.any(np.isfinite(model_result)):
ll = -np.inf
Expand Down

0 comments on commit 02b8eb9

Please sign in to comment.