# Bumps documentation

## fitters - Wrappers for various optimization algorithms

`BFGSFit` | BFGS quasi-newton optimizer.
`CheckpointMonitor` | Periodically save fit state so that it can be resumed later.
`ConsoleMonitor` | Display fit progress on the console
`DEFit` | Classic Storn and Price differential evolution optimizer.
`DreamFit` |
`DreamModel` | DREAM wrapper for fit problems.
`FitBase` | FitBase defines the interface from bumps models to the various fitting engines available within bumps.
`FitDriver` |
`LevenbergMarquardtFit` | Levenberg-Marquardt optimizer.
`MPFit` | MPFit optimizer.
`MonitorRunner` | Adaptor which allows solvers to accept progress monitors.
`MultiStart` | Multi-start monte carlo fitter.
`PSFit` | Particle swarm optimizer.
`PTFit` | Parallel tempering optimizer.
`RLFit` | Random lines optimizer.
`Resampler` |
`SimplexFit` | Nelder-Mead simplex optimizer.
`SnobFit` |
`StepMonitor` | Collect information at every step of the fit and save it to a file.
`fit` | Simplified fit interface.
`fit_result_summary` | Return a JSON-serializable summary of the fit results.
`get_fit_from_webview` | Retrieve the current problem and fit result from webview.
`help` |
`load_fit_from_export` | Reload a bumps export directory.
`load_fit_from_session` | Reload the results from a bumps session file.
`load_session` | Reload a session file from a saved hdf
`parse_tolerance` |
`plot_convergence` | Create a convergence plot from the simple fitter results.
`register` | Register a new fitter with bumps, if it is not already there.
`save_best` | Save the fit data, including parameter values, uncertainties and plots.
`save_fit` | Write a fit to a session file.
`save_fit_result` | Save the `fit_result_summary()` of fit to filename as JSON, conventionally <model>-fit.json in the export directory.
`show_results` |
`show_table` |
`test_fit_result_summary` |
`test_fitters` | Run the fit tests to make sure they work.

Interfaces to various optimizers.

class bumps.fitters.BFGSFit(problem: bumps.fitproblem.FitProblem)

  Bases: `FitBase`

  BFGS 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)
  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)

  Bases: `TimedUpdate`

  Periodically 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.

  show_improvement(history)
  show_progress(history)

class bumps.fitters.ConsoleMonitor(problem, progress=1, improvement=30)

  Bases: `TimedUpdate`

  Display fit progress on the console

  config_history(history)

    Indicate which fields are needed by the monitor and for what duration.

  final(history: History, best: Dict[str, Any])
  info(message: str)
  show_improvement(history)
  show_progress(history)

class bumps.fitters.DEFit(problem: bumps.fitproblem.FitProblem)

  Bases: `FitBase`

  Classic Storn and Price differential evolution optimizer.

  static h5dump(group: Group, state: Dict[str, Any])

    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 = 'de'

    Short name for the fit method, used as –id on the command line.

  load(input_path)
  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.

  save(output_path)
  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)
  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)

  Bases: `FitBase`

  entropy(**kw)
  error_plot(figfile)
  static h5dump(group: Group, state: MCMCDraw)

    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

    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.

  load(input_path)
  classmethod max_steps(problem: bumps.fitproblem.FitProblem, 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 = 'DREAM'

    Display name for the fit method

  plot(output_path)
  problem

    The problem that is being fit.

  save(output_path)
  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.

  show()
  solve(monitors: MonitorRunner, mapper=None, **options)
  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.

  stderr()

    Approximate standard error as 1/2 the 68% interval fo the sample, which is a more robust measure than the mean of the sample for non-normal distributions.

class bumps.fitters.DreamModel(problem=None, mapper=None)

  Bases: `object`

  DREAM wrapper for fit problems. Implements dream.core.Model protocol.

  bounds: ndarray[tuple[Any, ...], dtype[_ScalarT]]
  labels: List[str]
  map(pop)

class bumps.fitters.FitBase(problem: bumps.fitproblem.FitProblem)

  Bases: `object`

  FitBase 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 `FitDriver` first 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

    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: 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

    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)
  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)

  Bases: `object`

  chisq()
  clip()

    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()

    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)

  entropy(method=None)
  fit(resume=None, fit_state=None)

    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))

  load(input_path)
  plot(output_path, view=None)
  save(output_path)
  show()
  show_cov()
  show_entropy(method=None)
  show_err()
  stderr()

    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()

    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)

  Bases: `FitBase`

  Levenberg-Marquardt optimizer.

  cov()
  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)
  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)

  Bases: `FitBase`

  MPFit 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.

  solve(monitors=None, mapper=None, **options)
  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)

  Bases: `object`

  Adaptor which allows solvers to accept progress monitors.

  The stopping() method manages checks for abort and timeout.

  final(point: ndarray[tuple[Any, ...], dtype[_ScalarT]], value: float)
  info(message: str)
  stopping()
  update(step: int, point: ndarray[tuple[Any, ...], dtype[_ScalarT]], value: float, population_points: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None, population_values: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None)

class bumps.fitters.MultiStart(fitter: FitBase)

  Bases: `FitBase`

  Multi-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

    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)
  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)

  Bases: `FitBase`

  Particle 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)
  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)

  Bases: `FitBase`

  Parallel 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)
  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)

  Bases: `FitBase`

  Random 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)
  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)

  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.

  solve(**options)
  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)

  Bases: `FitBase`

  Nelder-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)
  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)

  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)
  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'])

  Bases: `Monitor`

  Collect 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']
  config_history(history)

    Indicate which fields are needed by the monitor and for what duration.

  update(history)

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

  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, plus labels (the fitted parameter labels, matching the order of x and dx), numpoints (number of data points) and chisq (normalized chi-squared at the best point, at full precision). 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.

bumps.fitters.fit_result_summary(results: OptimizeResult) → dict

  Return a JSON-serializable summary of the fit results.

  The summary contains every entry from results except the fitter state and the convergence history. This includes the scipy-convention entries (x, dx, fun, success, status, message, nit, …) plus labels (the fitted parameter labels, matching the order of x and dx), numpoints (number of data points) and chisq (normalized chi-squared at the best point, at full precision). For a model with gaussian independent uncertainties the raw sum of squares is chisq*dof.

async bumps.fitters.get_fit_from_webview(wait: bool = False)

  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.help(*shown)

bumps.fitters.load_fit_from_export(path: Path | str, modelfile: Path | str | None = None, args: list[str] | None = None)

  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)

  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.load_session(filename)

  Reload a session file from a saved hdf

bumps.fitters.parse_tolerance(options)

bumps.fitters.plot_convergence(results, cutoff=0.25, ax=None)

  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)

  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.

bumps.fitters.save_best(fitdriver, problem=None, best=None, view=None)

  Save the fit data, including parameter values, uncertainties and plots.

  fitdriver is the fitter that was used to drive the fit.

  problem is a FitProblem instance.

  best is the parameter set to save.

bumps.fitters.save_fit(path: Path | str, problem, fit: OptimizeResult, label: str | None = None)

  Write a fit to a session file.

bumps.fitters.save_fit_result(problem, fit, filename)

  Save the `fit_result_summary()` of fit to filename as JSON, conventionally <model>-fit.json in the export directory.

  fit may be an `OptimizeResult` or a webview `FitResult`; the latter is converted to an `OptimizeResult` for the summary.

bumps.fitters.show_results(problem, results: OptimizeResult)

bumps.fitters.show_table(problem, results)

bumps.fitters.test_fit_result_summary()

bumps.fitters.test_fitters()

  Run the fit tests to make sure they work.