Fit
- class sherpa.fit.Fit(data, model, stat=None, method=None, estmethod=None, itermethod_opts=None)[source] [edit on github]
Bases:
NoNewAttributesAfterInit
Fit a model to a data set.
- Parameters
data (
sherpa.data.Data
orsherpa.data.DataSimulFit
) – The data to be fit.model (
sherpa.models.model.Model
orsherpa.models.model.SimulFitModel
) – The model to fit to the data. It should match thedata
parameter (i.e. be aSimulFitModel
object when data is aDataSimulFit
).stat (
sherpa.stats.Stat
orNone
, optional) – The statistic object to use. If not given thenChi2Gehrels
is used.method (
sherpa.optmethods.OptMethod
instance or None, optional) – The optimiser to use. If not given thensherpa.optmethods.LevMar
is used.estmethod (
sherpa.estmethods.EstMethod
or None, optional) – The class used to calculate errors. If not given thensherpa.estmethods.Covariance
is used.itermethod_opts (dict or None, optional) – If set, defines the iterated-fit method and options to use. It is passed through to
IterFit
.
Methods Summary
Calculate the per-bin chi-squared statistic.
Calculate the statistic value.
Calculate the statistic value and related information.
est_errors
([methoddict, parlist])Estimate errors.
fit
([outfile, clobber, numcores])Fit the model to the data.
guess
(**kwargs)Guess parameter values and limits.
simulfit
(*others)Fit multiple data sets and models simultaneously.
Methods Documentation
- calc_chisqr()[source] [edit on github]
Calculate the per-bin chi-squared statistic.
Evaluate the per-bin statistic for the current model and data settings (e.g. parameter values and data filters).
- Returns
chisq – The chi-square value for each bin of the data, using the current statistic. A value of
None
is returned if the statistic is not a chi-square distribution.- Return type
array or None
See also
- calc_stat()[source] [edit on github]
Calculate the statistic value.
Evaluate the statistic for the current model and data settings (e.g. parameter values and data filters).
- Returns
stat – The current statistic value.
- Return type
number
See also
- calc_stat_info()[source] [edit on github]
Calculate the statistic value and related information.
Evaluate the statistic for the current model and data settings (e.g. parameter values and data filters).
- Returns
statinfo – The current statistic value.
- Return type
StatInfoResults
instance
See also
- calc_thaw_indices()[source] [edit on github]
- est_errors(methoddict=None, parlist=None)[source] [edit on github]
Estimate errors.
Calculate the low and high errors for one or more of the thawed parameters in the fit.
- Parameters
methoddict (dict or None, optional) – A dictionary mapping from lower-cased method name to the associated optimisation method instance to use. This is only used if the method is changed, as described in the Notes section below.
parlist (sequence of
sherpa.models.parameter.Parameter
or None, optional) – The names of the parameters for which the errors should be calculated. If set toNone
then all the thawed parameters are used.
- Returns
res
- Return type
- Raises
sherpa.utils.err.EstErr – If any parameter in parlist is not valid (i.e. is not thawed or is not a member of the model expression being fit), or if the statistic is
LeastSq
, or if the reduced chi-square value of the current parameter values is larger than themax_rstat
option (for chi-square statistics).
See also
Notes
If a new minimum is found for any parameter then the calculation is automatically started for all the parameters using this new best-fit location. This can repeat until the
maxfits
option is reached.Unless the
Covariance
estimator is being used, or thefast
option is unset, then the method will be changed toNelderMead
(for likelihood-based statistics) orLevMar
(for chi-square based statistics) whilst calculating the errors.
- fit(outfile=None, clobber=False, numcores=1)[source] [edit on github]
Fit the model to the data.
- Parameters
- Returns
fitres
- Return type
- Raises
sherpa.utils.err.FitErr – This is raised if
clobber
isFalse
andoutfile
already exists or if all the bins have been masked out of the fit.
See also
Notes
The file created when
outfile
is set is a simple ASCII file with a header line containing the text “# nfev statistic” and then a list of the thawed parameters, and then one line for each iteration, with the values separated by spaces.
- guess(**kwargs)[source] [edit on github]
Guess parameter values and limits.
The model’s
sherpa.models.model.Model.guess
method is called with the data values (the dependent axis of the data set) and thekwargs
arguments.
- simulfit(*others)[source] [edit on github]
Fit multiple data sets and models simultaneously.
The current fit object is combined with the other fit objects and a simultaneous fit is made, using the object’s statistic and optimisation method.
- Parameters
*others (
sherpa.fit.Fit
instances) – Thedata
andmodel
attributes of these arguments are used, along with those from the object.- Returns
fitres
- Return type
See also