Profilers¶
Profiler¶
- class desilike.profilers.base.Profiler(likelihood, posterior=True, rng=None, directory=None)[source]¶
Profiler used to compute likelihood and posterior profiles.
Initialize the profiler.
- Parameters:
likelihood (BaseLikelihood) – Likelihood to profile.
posterior (bool, optional) – If
True, profile the posterior. Otherwise, profile the likelihood. Default isTrue.rng (numpy.random.Generator, int or None, optional) – Random number generator. Default is
None.directory (str, Path, or None, optional) – Save samples to this folder. Default is
None.
- add_manual_grid(grid)[source]¶
Manually add parameter grid to optimize.
- Parameters:
grid (dict) – Parameter grid to profile, i.e.,
dict(a=[0, 1, 2])implies that the maximum likelihood is found for \(a=0\), \(a=1\), and \(a=2\). If multiple parameters are specified, all combinations are profiled.- Raises:
ValueError – If no parameter is specificed or a parameter is not described in the likelihood.
- add_single_sample(sample)[source]¶
Add a parameter combination to optimize.
- Parameters:
sample (dict) – Single parameter combination to profile.
- Raises:
ValueError – If a parameter is not described in the likelihood.
- run(n_per_iter=10, max_iter=10, tol=0.001, warm_start=False, max_init_attempts=100, optimizer=<function scipy_dual_annealing>, optimizer_kwargs=None)[source]¶
Run the profiler.
- Parameters:
n_per_iter (int, optional) – Independent optimizations per sample at each iteration. Default is 10.
max_iter (int, optional) – Maximum number of iterations. Default is 10.
tol (float, optional) – Optimization stops if maximum improvement accross all samples drops below
tolbetween optimizations. Default is 1e-2.warm_start (bool, optional) – If True, starting positions are derived from interpolating previous points. This can only be done if the profiler was run with
warm_start=Falsebefore.max_init_attempts (int, optional) – Maximum number of attempts to initialize each sample. Default is 100.
optimizer (callable, optional) – Optimizer function from
desilike.profilers.optimizers. Default isdesilike.profilers.scipy_dual_annealing.optimizer_kwargs (dict, optional) – Optional keyword arguments passed to the optimizer. Default is
None.
- Raises:
ValueError – If trying to run the profiler without having added samples.
- Returns:
samples – Maxima found by the profiler.
- Return type:
Optimizers¶
Collection of wrappers for commonly used optimizers.
- desilike.profilers.optimizers.scipy_dual_annealing(f, x_0, rng, **kwargs)[source]¶
Optimize using
scipy.dual_annealing().- Parameters:
f (callable) – Function to optimize.
x_0 (array-like) – Starting point.
rng (numpy.random.Generator) – Random number generator.
**kwargs – Additional keyword arguments passed to
scipy.dual_annealing.
- Returns:
x_min (numpy.ndarray) – Coordinates of the minimum.
f_min (float) – Value of the objective function at the minimum.
success (bool) – Whether the optimizer finished successfully.
- desilike.profilers.optimizers.scipy_minimize(f, x_0, rng, **kwargs)[source]¶
Optimize using
scipy.minimize().- Parameters:
f (callable) – Objective function.
x_0 (array-like) – Starting point.
rng (numpy.random.Generator) – Unused. Present for API consistency.
**kwargs – Additional keyword arguments passed to
scipy.minimize.
- Returns:
x_min (numpy.ndarray) – Coordinates of the minimum.
f_min (float) – Value of the objective function at the minimum.
success (bool) – Whether the optimizer finished successfully.