@@ -188,27 +188,31 @@ def __init__(self, N, Y, postfn, dist, threads=1, pool=None):
188188 self .mapFunc = self .pool .map
189189
190190
191- def sample (self , prior , eps_proposal ):
191+ def sample (self , prior , eps_proposal , initialPool = None ):
192192 """
193193 Launches the sampling process. Yields the intermediate results per iteration.
194194
195195 :param prior: instance of a prior definition (or an other callable) see :py:class:`sampler.GaussianPrior`
196196 :param eps_proposal: an instance of a threshold proposal (or an other callable) see :py:class:`sampler.ConstEps`
197+ :param initialPool: a PoolSpec object to be used as initial sample. if none is given this is created using _RejectionSamplingWrapper
197198
198199 :yields pool: yields a namedtuple representing the values of one iteration
199200 """
200-
201- eps = eps_proposal .next ()
202- wrapper = _RejectionSamplingWrapper (self , eps , prior )
203-
204- res = list (self .mapFunc (wrapper , range (self .N )))
205- thetas = np .array ([theta for (theta , _ , _ ) in res ])
206- dists = np .array ([dist for (_ , dist , _ ) in res ])
207- cnts = np .sum ([cnt for (_ , _ , cnt ) in res ])
208- ws = np .ones (self .N ) / self .N
209-
210- pool = PoolSpec (0 , eps , self .N / cnts , thetas , dists , ws )
211- yield pool
201+
202+ if initialPool = None :
203+ eps = eps_proposal .next ()
204+ wrapper = _RejectionSamplingWrapper (self , eps , prior )
205+
206+ res = list (self .mapFunc (wrapper , range (self .N )))
207+ thetas = np .array ([theta for (theta , _ , _ ) in res ])
208+ dists = np .array ([dist for (_ , dist , _ ) in res ])
209+ cnts = np .sum ([cnt for (_ , _ , cnt ) in res ])
210+ ws = np .ones (self .N ) / self .N
211+
212+ pool = PoolSpec (0 , eps , self .N / cnts , thetas , dists , ws )
213+ yield pool
214+ else :
215+ pool = initialPool
212216
213217 for t , eps in enumerate (eps_proposal , 1 ):
214218 particleProposal = self .particle_proposal_cls (self , eps , pool , self .particle_proposal_kwargs )
0 commit comments