Accept-reject sampler
In addition to sampling each model parameter independently, the
epifx.select
module provides support for sampling particles according to
arbitrary target distributions, using an accept-reject sampler.
Proposals will be drawn from the model prior distribution.
- epifx.select.select(instance, target, seed, notify_fn=None)
Select particles according to a target distribution. Proposals will be drawn from the model prior distribution.
- Parameters:
instance – The simulation instance.
target – The target distribution.
seed – The PRNG seed used for accepting particles.
notify_fn – An optional function that is notified of each acceptance loop, and should accept two arguments: the number of particles and the number of accepted particles.
- Returns:
The initial state vector for each accepted particle.
- Return type:
numpy.ndarray
Note
The
instance
should not be reused after calling this function. To prevent this from happening, the instance settings will be deleted.
# Save the accepted particles to disk.
vec = epifx.select.select(instance, target, seed)
sampled_values = vec[column_names]
header = ' '.join(column_names)
np.savetxt(out_file, sampled_values, header=header, comments='')
Any target distribution for which a probability density can be defined can be used with this sampler:
- class epifx.select.Target
The base class for target particle distributions.
Two target distributions are provided by this module.
The TargetAny
distribution accepts all particles with equal
likelihood, for the case where the proposal distribution is identical to the
desired target distribution:
- class epifx.select.TargetAny
A distribution that accepts all proposals with equal likelihood.
The TargetPeakMVN
distribution is a multivariate normal distribution
for the peak timing and size, as defined by previously-observed peaks:
- class epifx.select.TargetPeakMVN(peak_sizes, peak_times)
A multivariate normal distribution for the peak timing and size.
- Parameters:
peak_sizes – An array of previously-observed peak sizes.
peak_time – An array of previously-observed peak times.