Samplers

class ionworkspipeline.samplers.Sampler(solver_args)

Base class for all MCMC-type samplers. While optimizers seek to find a single optimal point in parameter space, samplers explore the parameter space to characterize parameter distributions and uncertainty.

Parameters

solver_argsdict

Dictionary of arguments to pass to the solver.

Attributes

namestr

Name of the sampler, defaults to “Sampler”

costionworkspipeline.costs.Cost

Cost function used to evaluate samples, typically representing a likelihood or posterior

probabilisticbool

Whether the sampler is probabilistic (always True for samplers)

Extends: ionworkspipeline.data_fits.parameter_estimators.parameter_estimator.ParameterEstimator

property probabilistic

Whether this is a probabilistic estimator.

Returns

bool

Always True for samplers since they are designed for probabilistic parameter estimation.

run(x0)

Run the sampling algorithm to explore the parameter space.

Parameters

x0array_like

Initial point to start the Markov chain or sampling process.

Returns

resionworkspipeline.SamplerResult

The result of the sampling, containing the chain of samples and their associated costs/likelihoods.

class ionworkspipeline.samplers.Pints(method='DramACMC', log_to_screen=False, max_iterations=1000, burnin_iterations=None, initial_phase_iterations=None, **solver_args)

Sampler using the library pints: Probabilistic Inference for Bayesian Models. This is a wrapper around the pints MCMCController class.

Parameters

methodstr, optional

The method to use for sampling. Default is “DramACMC”. Must be one of: - “DramACMC” - “HamiltonianMCMC” - “HaarioBardenetACMC” - “MALAMCMC” - “MetropolisRandomWalkMCMC” - “MonomialGammaHamiltonianMCMC” - “NoUTurnMCMC” - “PopulationMCMC” - “RelativisticMCMC” - “SliceDoublingMCMC” - “SliceRankShrinkingMCMC” - “SliceStepoutMCMC”

log_to_screenbool, optional

Whether to print information at runtime. Default is False.

max_iterationsint, optional

The maximum number of iterations. Default is 1000.

burnin_iterationsint, optional

Number of initial iterations to discard. Default is 10% of max_iterations.

initial_phase_iterationsint, optional

Number of iterations in initial phase. Only used for methods that need an initial phase. Default is equal to burnin_iterations.

solver_argsdict, optional

Additional parameters passed to the pints MCMC sampler. See the pints documentation for details.

Notes

  • The sampler does not currently support equality or inequality constraints.

  • The log PDF values are cached internally to work around a pints limitation.

  • For methods that need an initial phase, initial_phase_iterations must not exceed burnin_iterations, which in turn must not exceed max_iterations.

See Also

pints.MCMCController : The underlying MCMC controller class from pints

Extends: ionworkspipeline.data_fits.parameter_estimators.samplers.sampler.Sampler

property array_output

Whether the objective function supports vector-valued outputs. Must be implemented by the subclass.

property custom_eq_constraints

Whether the equality constraints are handled specially by the estimator.

property custom_ineq_constraints

Whether the inequality constraints are handled specially by the estimator.

methods()

Return the methods supported by the pints sampler.

run(x0)

Sample the objective function.

Parameters

x0array_like

Initial parameter values to start sampling from.

Returns

resionworkspipeline.SamplerResult

The result of the sampling, containing: - samples: Array of shape (n_iterations, n_parameters) containing all samples - cost: Array of shape (n_iterations,) containing log probability densities - x: The parameter values with highest log probability - iterations: Number of iterations performed

property scalar_output

Whether the objective function supports scalar-valued outputs. Must be implemented by the subclass.

class ionworkspipeline.samplers.GridSearch(npts=10)

Sampler using a brute force grid search approach.

Parameters

nptsint, optional

The number of points to use in each dimension. Default is 10.

Extends: ionworkspipeline.data_fits.parameter_estimators.samplers.sampler.Sampler

property array_output

Whether the objective function supports vector-valued outputs. Must be implemented by the subclass.

property custom_eq_constraints

Whether the equality constraints are handled specially by the estimator.

property custom_ineq_constraints

Whether the inequality constraints are handled specially by the estimator.

run(x0)

Optimize the objective function.

Parameters

x0 : array_like

property scalar_output

Whether the objective function supports scalar-valued outputs. Must be implemented by the subclass.

class ionworkspipeline.samplers.Dummy

Dummy sampler, returns the initial guess as a single sample.

Extends: ionworkspipeline.data_fits.parameter_estimators.samplers.sampler.Sampler

property array_output

Whether the objective function supports vector-valued outputs. Must be implemented by the subclass.

property custom_eq_constraints

Whether the equality constraints are handled specially by the estimator.

property custom_ineq_constraints

Whether the inequality constraints are handled specially by the estimator.

run(x0)

Return the initial guess as a single sample.

Parameters

x0array_like

Initial guess for the independent variables.

Returns

resionworkspipeline.SamplerResult

The result of the sampling, containing: - samples: Array of shape (1, n_parameters) containing x0 - cost: Array of shape (1,) containing the log probability density at x0 - x: The parameter values with highest log probability (same as x0)

property scalar_output

Whether the objective function supports scalar-valued outputs. Must be implemented by the subclass.