Skip to content

Commit

Permalink
Merge pull request #137 from joezuntz/fix-poco-pickling
Browse files Browse the repository at this point in the history
Change pocomc.Prior object to use a global Pipeline variabkle
  • Loading branch information
joezuntz authored Jul 26, 2024
2 parents ae1b65c + 921caa7 commit daa33a8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cosmosis/samplers/poco/poco_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ def log_likelihood(p):


class Prior:
def __init__(self, pipeline):
self.pipeline = pipeline
self.dim = len(self.pipeline.varied_params)
self.bounds = np.array([p.limits for p in self.pipeline.varied_params])
def __init__(self):
self.dim = len(pipeline.varied_params)
self.bounds = np.array([p.limits for p in pipeline.varied_params])

def logpdf(self, x):
return np.array([self.pipeline.prior(p) for p in x])
return np.array([pipeline.prior(p) for p in x])

def rvs(self, size=None):
return np.array([self.pipeline.randomized_start() for i in range(size)])
return np.array([pipeline.randomized_start() for i in range(size)])


class PocoMCSampler(ParallelSampler):
Expand Down Expand Up @@ -73,7 +72,7 @@ def config(self):

# Finally we can create the sampler
self.sampler = self.pocomc.Sampler(
prior=Prior(self.pipeline),
prior=Prior(),
likelihood=log_likelihood,
random_state=seed,
n_effective=self.n_effective,
Expand Down

0 comments on commit daa33a8

Please sign in to comment.