SobolSampler#
- class macrostat.sample.sobol.SobolSampler(model: Model, bounds: dict | None = None, sample_power: int = 10, sobol_seed: int = 0, logspace: bool = False, worker_function: callable = <function timeseries_worker>, simulation_args: tuple = (), output_folder: str = 'sobol_samples', cpu_count: int = 1, batchsize: int = None, output_filetype: str = 'csv', output_compression: str | None = None)[source]
Bases:
BaseSamplerA Sobol sequence sampler for efficient parameter space exploration.
The SobolSampler class implements quasi-random low-discrepancy sequence sampling to systematically explore a model’s parameter space. The benefit of Sobol sequences is that even the sub-samples are uniform distributed, which is not the case for random sampling from a uniform distribution.
The sampler works by generating a Sobol sequence in the unit hypercube [0,1]^d, transforming the sequence to the desired parameter ranges and creating model instances with the sampled parameters.
Example
>>> model = MyModel() >>> bounds = { ... 'param1': (0.1, 1.0), ... 'param2': (1.0, 10.0) ... } >>> sampler = SobolSampler( ... model=model, ... bounds=bounds, ... sample_power=8, # 2^8 = 256 samples ... logspace=True, # Sample in log space ... cpu_count=4 # Use 4 CPUs ... ) >>> sampler.sample()
- generate_parameters()[source]
Generate points in the parameterspace for the parallel processor based on a Sobol sequence.
Here the scipy.stats.qmc.Sobol class is used to generate the Sobol sequence, specifically the random_base2 method is used to generate the samples, as it is has slightly better space filling properties than with a custom number of samples.
- Returns:
DataFrame containing the Sobol points in the parameterspace. Rows are the samples, columns are the parameters
- Return type:
pd.DataFrame