Skip to content
Snippets Groups Projects
Commit c7c57cc6 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Resolve "bilby_mcmc not able to use priors with infinite support"

parent 08b2a15f
No related branches found
No related tags found
No related merge requests found
......@@ -313,6 +313,10 @@ class DifferentialEvolutionProposal(BaseProposal):
class UniformProposal(BaseProposal):
"""A proposal using uniform draws from the prior support
Note: for priors with infinite support, this proposal will not propose a
point, leading to inefficient sampling. You may wish to omit this proposal
if you have priors with infinite support.
Parameters
----------
priors: bilby.core.prior.PriorDict
......@@ -330,9 +334,14 @@ class UniformProposal(BaseProposal):
def propose(self, chain):
sample = chain.current_sample
for key in self.parameters:
sample[key] = np.random.uniform(
self.prior_minimum_dict[key], self.prior_maximum_dict[key]
)
width = self.prior_width_dict[key]
if np.isinf(width) is False:
sample[key] = np.random.uniform(
self.prior_minimum_dict[key], self.prior_maximum_dict[key]
)
else:
# Unable to generate a uniform sample on infinite support
pass
log_factor = 0
return sample, log_factor
......
......@@ -30,6 +30,8 @@ class TestBaseProposals(unittest.TestCase):
for i in range(ndim)
})
priors["fixedA"] = bilby.core.prior.DeltaFunction(1)
priors["infinite_support"] = bilby.core.prior.Normal(0, 1)
priors["half_infinite_support"] = bilby.core.prior.HalfNormal(1)
return priors
def create_random_sample(self, ndim=2):
......@@ -37,6 +39,8 @@ class TestBaseProposals(unittest.TestCase):
p[LOGLKEY] = np.random.normal(0, 1)
p[LOGPKEY] = -1
p["fixedA"] = 1
p["infinite_support"] = np.random.normal(0, 1)
p["half_infinite_support"] = np.abs(np.random.normal(0, 1))
return Sample(p)
def create_chain(self, n=1000, ndim=2):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment