IterFit

class sherpa.fit.IterFit(data, model, stat, method, itermethod_opts=None)[source] [edit on github]

Bases: sherpa.utils.NoNewAttributesAfterInit

Methods Summary

fit(statfunc, pars, parmins, parmaxes[, ...])

primini(statfunc, pars, parmins, parmaxes[, ...])

An iterative scheme, where the variance is computed from the model amplitudes.

sigmarej(statfunc, pars, parmins, parmaxes)

Exclude points that are significately far away from the best fit.

Methods Documentation

fit(statfunc, pars, parmins, parmaxes, statargs=(), statkwargs=None)[source] [edit on github]
primini(statfunc, pars, parmins, parmaxes, statargs=(), statkwargs=None)[source] [edit on github]

An iterative scheme, where the variance is computed from the model amplitudes.

This is a chi-square statistic where the variance is computed from model amplitudes derived in the previous iteration of the fit. This ‘Iterative Weighting’ 1 attempts to remove biased estimates of model parameters which is inherent in chi-square statistics 2.

Raises

sherpa.utils.err.FitErr – This exception is raised if the statistic is not supported. This method can only be used with Chi-Square statistics with errors.

Notes

The following keys are looked for in the itermethod_opts dictionary:

Key

Type

Description

tol

number

The tolerance used when comparing the statistic values.

maxiters

int

The maximum number of iterations.

The variance in bin i for iteration j is estimated to be:

\[\sigma(j)_i^2 = S(t_s(j-1))_i + (A_s/A_b)^2 B(t_b(j-1))_i\]

where the subscript i indicates the bin number, j is the number of iterations that have been carried out in the fitting process, S is the model-predicted amplitude of the source in the bin, B is the background (off-source) model amplitude, A_s and A_b are the source and background areas (or scaling factors), and t_s and t_b are the set of source and background model parameter values derived in the previous iteration (indicated by the j-1 term). The variances are set to an array of ones on the first iteration.

In addition to reducing parameter estimate bias, this statistic can be used even when the number of counts in each bin is small (< 5), although the user should proceed with caution.

References

1

“Multiparameter linear least-squares fitting to Poisson data one count at a time”, Wheaton et al. 1995, ApJ 438, 322 http://adsabs.harvard.edu/abs/1995ApJ…438..322W

2

“Bias-Free Parameter Estimation with Few Counts, by Iterative Chi-Squared Minimization”, Kearns, Primini, & Alexander, 1995, ADASS IV, 331 http://adsabs.harvard.edu/abs/1995ASPC…77..331K

sigmarej(statfunc, pars, parmins, parmaxes, statargs=(), statkwargs=None, cache=True)[source] [edit on github]

Exclude points that are significately far away from the best fit.

The sigmarej scheme is based on the IRAF sfit function 3, where after a fit data points are excluded if the value of (data-model) / error exceeds a threshold, and the data re-fit. This removal of data points continues until the fit has converged or a maximum number of iterations has been reached. The error removal can be asymmetric, since there are separate options for the lower and upper limits.

Raises

sherpa.utils.err.FitErr – This exception is raised if the statistic is not supported. This method can only be used with Chi-Square statistics with errors.

Notes

The following keys are looked for in the itermethod_opts dictionary:

Key

Type

Description

maxiters

int > 0

The maximum number of iterations.

lrej

number > 0

The number of sigma below the model to reject.

hrej

number > 0

The number of sigma above the model to reject.

grow

int >= 0

If greater than zero, also remove this many data points to either side of the identified element.

References

3

http://iraf.net/irafhelp.php?val=sfit