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”
- cost
ionworkspipeline.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 cost¶
Get the cost function used to evaluate samples. For MCMC samplers, this typically represents a likelihood or posterior probability.
Returns¶
ionworkspipeline.costs.Cost
Cost function object, defaults to RMSE if none provided.
- 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¶
- res
ionworkspipeline.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, 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”, “MALAMCMC”, “MetropolisRandomWalkMCMC”, “MonomialGammaHamiltonianMCMC”, “NoUTurnMCMC”, “PopulationMCMC”, “RelativisticMCMC”, “SliceDoublingMCMC”, “SliceRankShrinkingMCMC”, or “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.
- initial_phase_iterationsint, optional
Number of iterations in initial phase. Only used for methods that need an initial phase.
- thresholdfloat, optional
The threshold for early termination. Default is None.
- solver_argsdict, optional
Parameters are passed to the pints function. See the pints documentation for details.
Extends:
ionworkspipeline.data_fits.parameter_estimators.samplers.sampler.Sampler
- 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¶
- res
ionworkspipeline.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
- 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
- class ionworkspipeline.samplers.Dummy¶
Dummy sampler, returns the initial guess as a single sample.
Extends:
ionworkspipeline.data_fits.parameter_estimators.samplers.sampler.Sampler
- run(x0)¶
Return the initial guess as a single sample.
Parameters¶
- x0array_like
Initial guess for the independent variables.
Returns¶
- res
ionworkspipeline.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)