BayesicFitting

Model Fitting and Evidence Calculation

View project on GitHub



class IterativeFitter( BaseFitter )[source]

Base class with methods common to all iterative fitters.

Author: Do Kester.

Attributes

  • tolerance : float
         When absolute and relative steps in subsequent chisq steps are less than
         tolerance, the fitter stops. Default = 0.0001

  • maxIter : int
         When the number of iterations gets larger than maxiter the fitter
         stops with a ConvergenceError Default = 1000 * nparams

  • iter : int (read only)
         iteration counter

  • ntrans : int (read only)
         number of transforms

  • verbose : int
         information per iteration.
         0 : silent
         1 : base information (default)
         2 : report about every 100th iteration
         3 : report about every ietration

  • tooLarge : int
         When the length parameter array is too large to make a Hessian.
         To avert OutOfMemory. Default = 100

  • plotter : Plotter
         Iteration plotter class. Default = IterationPlotter

  • plotIter : int
         Produce a plot for every plotIter-th iteration.
         Default = 0 (no plotting)

Raises
ConvergenceError Something went wrong during the convergence if the fit.

IterativeFitter( xdata, model, maxIter=None, tolerance=0.0001, verbose=1, **kwargs ) [source]

Create a new iterative fitter, providing xdatas and model.

This is a base class. It collects stuff common to all iterative fitters. It does not work by itself.

Parameters

  • xdata : array_like
         array of independent input values

  • model : Model
         the model function to be fitted

  • tolerance : float
         When absolute and relative steps in subsequent chisq steps are less than
         tolerance, the fitter stops. Default = 0.01

  • maxIter : None or int
         When the number of iterations gets larger than maxiter the fitter
         stops with a ConvergenceError Default = 1000 * nparams

  • verbose : int
         0 : silent
         1 : report result
         2 : report every 100th iteration
         3 : report every iteration

  • kwargs : dict
         for BaseFitter map, keep, fixedScale

setParameters( params ) [source]
Initialize the parameters of the model A little superfluous: see [Model#setParameters.](Model#setParameters.)

Parameters

  • params : array_like
         initial parameters

setPlotters( plot ) [source]
Set plot methods as requested by plot.
plot doIterPlot doLastPlot comment
False no plot no plot default; dont plot
True no plot plotSampleList
"last" no plot plotSampleList
"iter" plotWalker no plot
"all" plotWalker plotSampleList
"test" plotWalker plotSampleList no show(), for tests

The plot methods plotWalker and plotSampleList are part of the module Plotter.py
     Parameters

  • plot : str or bool (False)
         as in table

plotNot( ydata, param, force=False ) [source]

do not plot

plotIter( ydata, param, force=False ) [source]

Plot Iteration results

fitprolog( ydata, weights=None, accuracy=None, keep=None ) [source]
Prolog for all iterative Fitters.
  1. Sets up plotting (if requested)
  2. Sets self.iter and self.ntrans to 0
  3. Checks data/weighs for Nans
  4. Makes fitIndex.

Parameters

  • ydata : array_like
         the data vector to be fitted
  • weights : array_like
         weights pertaining to the data
  • accuracy : float or array_like
         accuracy of (individual) data
  • keep : dict of {int:float}
         dictionary of indices (int) to be kept at a fixed value (float)

Returns

  • fitIndex : ndarray of int
         Indices of the parameters that need fitting

fit( ydata, weights=None, keep=None, **kwargs ) [source]
Return model parameters fitted to the data.

It will calculate the hessian matrix and chisq.

Parameters

  • ydata : array_like
         the data vector to be fitted
  • weights : array_like
         weights pertaining to the data
  • keep : dict of {int:float}
         dictionary of indices (int) to be kept at a fixed value (float)
  • kwargs :
         passed to the fitter

Raises
ConvergenceError if it stops when the tolerance has not yet been reached.

report( verbose, ydata, param, chi, more=None, force=False ) [source]
Report on intermediate results.
Methods inherited from BaseFitter