fitters - Wrappers for various optimization algorithms¶
BFGS quasi-newton optimizer. |
|
Periodically save fit state so that it can be resumed later. |
|
Display fit progress on the console |
|
Classic Storn and Price differential evolution optimizer. |
|
DREAM wrapper for fit problems. |
|
FitBase defines the interface from bumps models to the various fitting engines available within bumps. |
|
Levenberg-Marquardt optimizer. |
|
MPFit optimizer. |
|
Adaptor which allows solvers to accept progress monitors. |
|
Multi-start monte carlo fitter. |
|
Particle swarm optimizer. |
|
Parallel tempering optimizer. |
|
Random lines optimizer. |
|
Nelder-Mead simplex optimizer. |
|
Collect information at every step of the fit and save it to a file. |
|
Simplified fit interface. |
|
Retrieve the current problem and fit result from webview. |
|
Reload a bumps export directory. |
|
Reload the results from a bumps session file. |
|
Reload a session file from a saved hdf |
|
Create a convergence plot from the simple fitter results. |
|
Register a new fitter with bumps, if it is not already there. |
|
Write a fit to a session file. |
|
Run the fit tests to make sure they work. |
Interfaces to various optimizers.
- class bumps.fitters.BFGSFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseBFGS quasi-newton optimizer.
BFGS estimates Hessian and its Cholesky decomposition, but initial tests give uncertainties quite different from the directly computed Jacobian in Levenburg-Marquardt or the Hessian estimated at the minimum by numerical differentiation.
To use the internal ‘H’ and ‘L’ and save some computation time, then use:
C = lsqerror.chol_cov(fit.result['L']) stderr = lsqerror.stderr(C)
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'newton'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Quasi-Newton BFGS'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 3000), ('ftol', 1e-06), ('xtol', 1e-12), ('starts', 1), ('jump', 0)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.CheckpointMonitor(checkpoint, progress=1800)[source]¶
Bases:
TimedUpdatePeriodically save fit state so that it can be resumed later.
- checkpoint: Callable[None, None] = None¶
Function to call at each checkpoint.
- config_history(history)¶
Indicate which fields are needed by the monitor and for what duration.
- class bumps.fitters.ConsoleMonitor(problem, progress=1, improvement=30)[source]¶
Bases:
TimedUpdateDisplay fit progress on the console
- config_history(history)¶
Indicate which fields are needed by the monitor and for what duration.
- class bumps.fitters.DEFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseClassic Storn and Price differential evolution optimizer.
- static h5dump(group: Group, state: Dict[str, Any])[source]¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any[source]¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'de'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Differential Evolution'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 1000), ('pop', 10), ('CR', 0.9), ('F', 2.0), ('ftol', 1e-08), ('xtol', 1e-06)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.DreamFit(problem)[source]¶
Bases:
FitBase- static h5dump(group: Group, state: MCMCDraw)[source]¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) MCMCDraw[source]¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'dream'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem, options: Dict[str, Any] | None = None) int[source]¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'DREAM'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('samples', 10000), ('burn', 100), ('pop', 10), ('init', 'eps'), ('thin', 1), ('alpha', 0.0), ('outliers', 'iqr'), ('trim', True), ('steps', 0)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.DreamModel(problem=None, mapper=None)[source]¶
Bases:
objectDREAM wrapper for fit problems. Implements dream.core.Model protocol.
- bounds: ndarray[tuple[Any, ...], dtype[_ScalarT]]¶
- labels: List[str]¶
- class bumps.fitters.FitBase(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
objectFitBase defines the interface from bumps models to the various fitting engines available within bumps.
Each engine is defined in its own class with a specific set of attributes and methods.
The name attribute is the name of the optimizer. This is just a simple string.
The settings attribute is a list of pairs (name, default), where the names are defined as fields in FitOptions. A best attempt should be made to map the fit options for the optimizer to the standard fit options, since each of these becomes a new command line option when running bumps. If that is not possible, then a new option should be added to FitOptions. A plugin architecture might be appropriate here, if there are reasons why specific problem domains might need custom fitters, but this is not yet supported.
Each engine takes a fit problem in its constructor.
The
solve()method runs the fit. It accepts a monitor to track updates, a mapper to distribute work and key-value pairs defining the settings.There are a number of optional methods for the fitting engines. Basically, all the methods in
FitDriverfirst check if they are specialized in the fit engine before performing a default action.The load/save methods load and save the fitter state in a given directory with a specific base file name. The fitter can choose a file extension to add to the base name. Some care is needed to be sure that the extension doesn’t collide with other extensions such as .mon for the fit monitor.
The plot method shows any plots to help understand the performance of the fitter, such as a convergence plot showing the the range of values in the population over time, as well as plots of the parameter uncertainty if available. The plot should work within is given a figure canvas to work with
The stderr/cov methods should provide summary statistics for the parameter uncertainties. Some fitters, such as MCMC, will compute these directly from the population. Others, such as BFGS, will produce an estimate of the uncertainty as they go along. If the fitter does not provide these estimates, then they will be computed from numerical derivatives at the minimum in the FitDriver method.
- static h5dump(group: Group, state: Any) None[source]¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any[source]¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id: str¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int[source]¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name: str¶
Display name for the fit method
- problem: bumps.fitproblem.FitProblem¶
The problem that is being fit.
- settings: List[Tuple[str, Any]]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state: Any = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.FitDriver(fitclass=None, problem=None, monitors=None, abort_test=None, mapper=None, time=0.0, **options)[source]¶
Bases:
object- clip()[source]¶
Force parameters within bounds so constraints are finite.
The problem is updated with the new parameter values.
Returns a list of parameter names that were clipped.
- cov()[source]¶
Return an estimate of the covariance of the fit.
Depending on the fitter and the problem, this may be computed from existing evaluations within the fitter, or from numerical differentiation around the minimum.
If the problem uses \(\chi^2/2\) as its nllf, then the covariance is derived from the Jacobian:
x = fit.problem.getp() J = bumps.lsqerror.jacobian(fit.problem, x) cov = bumps.lsqerror.jacobian_cov(J)
Otherwise, the numerical differentiation will use the Hessian estimated from nllf:
x = fit.problem.getp() H = bumps.lsqerror.hessian(fit.problem, x) cov = bumps.lsqerror.hessian_cov(H)
- fit(resume=None, fit_state=None)[source]¶
Providing fit_state allows the fit to resume from a previous state. If None then the fit will be started from a clean state.
The fitclass object should provide static methods for h5dump/h5load for saving and loading the internal state of the fitter to a specific group in an hdf5 file. The result of h5load(group) can be passed as fit_state to resume a fit with whatever new options are provided. It is up to the fitter to decide how to interpret this. The state can be retrieved from state=driver.fitter.state at the end of the fit and saved using h5dump(group, state).
resume (= resume_path / problem.name) is used by the pre-1.0 command line interface to provide the base path for the fit state files. For dream this can be replaced by the following:
fn, labels = getattr(problem, "derive_vars", (None, [])) fit_state = load_state(input_path, report=100, derived_vars=len(labels))
- stderr()[source]¶
Return an estimate of the standard error of the fit.
Depending on the fitter and the problem, this may be computed from existing evaluations within the fitter, or from numerical differentiation around the minimum.
- stderr_from_cov()[source]¶
Return an estimate of standard error of the fit from covariance matrix.
Unlike stderr, which uses the estimate from the underlying fitter (DREAM uses the MCMC sample for this), stderr_from_cov estimates the error from the diagonal of the covariance matrix. Here, the covariance matrix may have been estimated by the fitter instead of the Hessian.
- class bumps.fitters.LevenbergMarquardtFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseLevenberg-Marquardt optimizer.
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'scipy.leastsq'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Levenberg-Marquardt (scipy.leastsq)'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 200), ('ftol', 1.5e-08), ('xtol', 1.5e-08)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.MPFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseMPFit optimizer.
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'lm'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Levenberg-Marquardt'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 200), ('ftol', 1e-10), ('xtol', 1e-10), ('starts', 1), ('jump', 0)]¶
Available fitting options and their default values.
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.MonitorRunner(monitors: List[Monitor], problem, abort_test=None, max_time=0.0)[source]¶
Bases:
objectAdaptor which allows solvers to accept progress monitors.
The stopping() method manages checks for abort and timeout.
- class bumps.fitters.MultiStart(fitter: FitBase)[source]¶
Bases:
FitBaseMulti-start monte carlo fitter.
This fitter wraps a local optimizer, restarting it a number of times to give it a chance to find a different local minimum. If the jump radius is non-zero, then restart near the best fit, otherwise restart at random.
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int[source]¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Multistart Monte Carlo'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('starts', 100), ('jump', 0)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.PSFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseParticle swarm optimizer.
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'ps'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Particle Swarm'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 3000), ('pop', 1)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.PTFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseParallel tempering optimizer.
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'pt'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Parallel Tempering'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 400), ('nT', 24), ('CR', 0.9), ('burn', 100), ('Tmin', 0.1), ('Tmax', 10.0)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.RLFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseRandom lines optimizer.
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'rl'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Random Lines'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 3000), ('pop', 0.5), ('CR', 0.9), ('starts', 20), ('jump', 0)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.Resampler(fitter)[source]¶
Bases:
FitBase- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings¶
Available fitting options and their default values.
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.SimplexFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBaseNelder-Mead simplex optimizer.
- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'amoeba'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'Nelder-Mead Simplex'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 1000), ('radius', 0.15), ('xtol', 1e-06), ('ftol', 1e-08), ('starts', 1), ('jump', 0.01)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.SnobFit(problem: bumps.fitproblem.FitProblem)[source]¶
Bases:
FitBase- static h5dump(group: Group, state: Any) None¶
Store fitter.state into the given HDF5 Group.
This will be restored by the corresponding h5load, then passed to the fitter to resume from its current state. This strategy is particularly useful for MCMC analysis where you may need more iterations for the chains to reach equilibrium. It is also the basis of checkpoint/restore operations for fitters such as de and amoeba which manage a population, though in those cases the best point seen so far may be good enough.
- static h5load(group: Group) Any¶
Load internal fit state from the group saved by h5dump. Note that this function will be responsible for migrating state from older versions to newer versions of the saved representation.
- id = 'snobfit'¶
Short name for the fit method, used as –id on the command line.
- classmethod max_steps(problem: bumps.fitproblem.FitProblem | None = None, options: Dict[str, Any] | None = None) int¶
Return the maximum number of steps the fitter will take based on the given options.
Default implementation just returns the ‘steps’ option multiplied by ‘starts’,
- name = 'SNOBFIT'¶
Display name for the fit method
- problem¶
The problem that is being fit.
- settings = [('steps', 200)]¶
Available fitting options and their default values.
- solve(monitors: MonitorRunner, mapper=None, **options)[source]¶
- state = None¶
Internal fit state. If the state object has a draw method this should return a set of points from the posterior probability distribution for the fit.
- class bumps.fitters.StepMonitor(problem, fid, fields=['step', 'time', 'value', 'point'])[source]¶
Bases:
MonitorCollect information at every step of the fit and save it to a file.
fid is the file to save the information to fields is the list of “step|time|value|point” fields to save
The point field should be last in the list.
- FIELDS = ['step', 'time', 'value', 'point']¶
- bumps.fitters.fit(problem, method: str = 'amoeba', session: Path | str | None = None, resume: OptimizeResult | None = None, export: Path | str | None = None, name: str | None = None, verbose: bool = False, parallel: int = 1, **options) OptimizeResult[source]¶
Simplified fit interface.
Given a fit problem, the name of a fitter and the fitter options, it will run the fit and return the best value and standard error of the parameters.
The keyword argments mostly follow the argument names used in the bumps command line interface. Try use method=method rather than fit=method)
Returns a scipy OptimizeResult object containing x and dx. Some fitters also include a result.state object. For dream this can be used as bumps.dream.views.plot_all(result.state) to generate the uncertainty plots. Use plot_convergence(result) to show how the fit progressed. result.convergence is a vector of current value for each step, or an array with best and population quantiles, [best, 0%, 20%, 50%, 80%, 100%].
Note: All fits report result.success=True even if they did not converge. Similarly result.status=0 and result.message=”successful termination”.
If session=path/file.h5 is provided, append the fit to the session history, or create a new session if the file doesn’t exist.
If resume=result is provided, then attempt to resume the fit from the previous result.
If export=path is provided, generate the standard plots and export files to the specified directory.
You can set name=basename as the base file name for all files stored in the export directory, or use name=problem.name as the default.
If verbose is true, then the console monitor will be enabled, showing progress through the fit and showing the parameter standard error at the end of the fit, otherwise it is completely silent.
If parallel=n is provided, then run on n separate cpus. By default parallel=1 to run on a single cpu. For slow functions set parallel=0 to run on all cpus. You want to run on a single cpu if your function is already parallel (for example using multiprocessing or using gpu code), or if your function is so fast that the overhead of transfering data is higher than cost of n function calls.
- async bumps.fitters.get_fit_from_webview(wait: bool = False)[source]¶
Retrieve the current problem and fit result from webview.
If wait then wait for any running fit to complete before fetching.
Returns the problem and an OptimizerResult similar to the simple fit() result
- bumps.fitters.load_fit_from_export(path: Path | str, modelfile: Path | str | None = None, args: list[str] | None = None)[source]¶
Reload a bumps export directory.
path is the path to the directory, or to a <model>.par file within that directory. Use the <model>.par file if you have multiple models exported to the same path.
If modelfile is provided then use it, otherwise use <model>.py in the current directory. That means you can change to the directory containing your model then run bumps with –reload-export=path without having to list <model>.py on the command line. This is handy if you have several variations saved to different filenames stored along with your data.
sys.argv is set to args before loading the model.
- bumps.fitters.load_fit_from_session(filename: Path | str)[source]¶
Reload the results from a bumps session file.
filename is a path to an HDF5 file.
Returns (problem, results) where problem contains the model executable and results is a scipy OptimizationResults object. We add state if available and convergence to the results, similar to simple fit.
Use load_session(filename) directly if you want more control.
- bumps.fitters.plot_convergence(results, cutoff=0.25, ax=None)[source]¶
Create a convergence plot from the simple fitter results.
Note that this will not work with a webview FitResults object returned from a session file. Those will not have dof defined, and use fit_state instead of state.
- bumps.fitters.register(fitter, active=True)[source]¶
Register a new fitter with bumps, if it is not already there.
active is False if you don’t want it showing up in the GUI selector.