Skip to content

kwargs for postfn and distfn #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions abcpmc/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ class Sampler(object):
particle_proposal_cls = ParticleProposal
particle_proposal_kwargs = {}

def __init__(self, N, Y, postfn, dist, threads=1, pool=None):
def __init__(self, N, Y, postfn, dist, threads=1, pool=None, postfn_kwargs={}, dist_kwargs={}):
self.N = N
self.Y = Y
self.postfn = postfn
self.postfn_kwargs = postfn_kwargs # keyword arguments for postfn
self.dist = dist
self.dist_kwargs = dist_kwargs # keyword arguments for distance metric
self._random = np.random.mtrand.RandomState()

if pool is not None:
Expand Down Expand Up @@ -264,7 +266,9 @@ class _RejectionSamplingWrapper(object): # @DontTrace

def __init__(self, sampler, eps, prior):
self.postfn = sampler.postfn
self.postfn_kwargs = sampler.postfn_kwargs
self.distfn = sampler.dist
self.distfn_kwargs = sampler.dist_kwargs
self._random = sampler._random
self.Y = sampler.Y
self.eps = np.asarray(eps)
Expand All @@ -280,8 +284,8 @@ def __call__(self, i):
cnt = 1
while True:
thetai = self.prior()
X = self.postfn(thetai)
p = np.asarray(self.distfn(X, self.Y))
X = self.postfn(thetai, **self.postfn_kwargs)
p = np.asarray(self.distfn(X, self.Y, **self.distfn_kwargs))
if np.all(p <= self.eps):
break
cnt+=1
Expand Down