6.15. pypfilt.sampler¶
The pypfilt.sampler
module provides a sampler that draws independent samples from each model parameter’s prior distribution:
-
class
pypfilt.sampler.
Independent
¶ The default sampler, which draws independent samples for each model parameter.
-
draw_samples
(settings, prng, particles, prior, sampled)¶ Return samples from the model prior distribution.
Parameters: - settings – A dictionary of sampler-specific settings.
- prng – The source of randomness for the sampler.
- particles – The number of particles.
- prior – The prior distribution table.
- sampled – Sampled values for specific parameters.
-
The pypfilt.sampler
module also provides a Latin hypercube sampler.
This sampler ensures that the samples provide a good representation of the real variability, and supports dependent parameters whose distributions depend on other parameters.
-
class
pypfilt.sampler.
LatinHypercube
¶ Draw parameter samples using Latin hypercube sampling.
-
draw_samples
(settings, prng, particles, prior, sampled)¶ Return samples from the model prior distribution.
Parameters: - settings – A dictionary of sampler-specific settings.
- prng – The source of randomness for the sampler.
- particles – The number of particles.
- prior – The prior distribution table.
- sampled – Sampled values for specific parameters.
-
To use this sampler, add the following to your scenario files:
[components]
sampler = "pypfilt.sampler.LatinHypercube"
[sampler]
dependent_distributions_function = "beta_distribution"
[prior]
# Sample alpha uniformly over the interval [5, 10].
alpha = { name = "uniform", args.loc = 5, args.scale = 5}
# Identify beta as a dependent parameter.
beta = { dependent = true }
You then need to define a function that constructs the sampling distribution for each dependent parameter:
def beta_distribution(indep_values, dep_params):
"""Define beta ~ N(alpha + 1, 1)."""
return {
'beta': {
'name': 'norm',
'args': {'loc': indep_values['alpha'] + 1, 'scale': 1},
},
}
Note
See the lhs documentation for examples of how to define distributions for independent and dependent parameters.
6.15.1. Defining a custom sampler¶
A custom sampler should derive the following base class:
-
class
pypfilt.sampler.
Base
¶ The base class for parameter samplers.
-
draw_samples
(settings, prng, particles, prior, sampled)¶ Return samples from the model prior distribution.
Parameters: - settings – A dictionary of sampler-specific settings.
- prng – The source of randomness for the sampler.
- particles – The number of particles.
- prior – The prior distribution table.
- sampled – Sampled values for specific parameters.
-