pint.fitter.DownhillFitter
- class pint.fitter.DownhillFitter(toas, model, track_mode=None, residuals=None)[source]
Bases:
Fitter
Abstract base class for downhill fitters.
These fitters use the algorithm implemented here, in
pint.fitter.DownhillFitter.fit_toas()
to work their way towards a solution, keeping track of convergence. The linear algebra required by various kinds of fitting is abstracted away intopint.fitter.ModelState
objects so that this same code can be used for correlated or uncorrelated TOA errors and narrowband or wideband TOAs.Methods
auto
(toas, model[, downhill, track_mode, ...])Automatically return the proper
pint.fitter.Fitter
object depending on the TOAs and model.fit_toas
([maxiter, noise_fit_niter, ...])Carry out a cautious downhill fit.
ftest
(parameter, component[, remove, ...])Compare the significance of adding/removing parameters to a timing model.
Return a dict of all param names and values.
get_derived_params
([returndict])Return a string with various derived parameters from the fitted model
Return the model's design matrix for these TOAs.
Return a dict of fittable param names and quantity.
Return a dict of fittable param names and numeric values.
Return a dict of fittable param names and numeric values.
Show the parameter correlation matrix post-fit.
Show the parameter covariance matrix post-fit.
get_params_dict
([which, kind])Return a dict mapping parameter names to values.
get_summary
([nodmx])Return a human-readable summary of the Fitter results.
make_resids
(model)minimize_func
(x, *args)Wrapper function for the residual class.
plot
()Make residuals plot.
Write a summary of the TOAs to stdout.
Reset the current model to the initial model.
set_fitparams
(*params)Update the "frozen" attribute of model parameters.
set_param_uncertainties
(fitp)Set the model parameters to the value contained in the input dict.
set_params
(fitp)Set the model parameters to the value contained in the input dict.
update_model
([chi2])Update the model to reflect fit results and TOA properties.
Update the residuals.
Attributes
covariance_matrix
fac
- fit_toas(maxiter=20, noise_fit_niter=2, required_chi2_decrease=0.01, max_chi2_increase=0.01, min_lambda=0.001, noisefit_method='Newton-CG', compute_noise_uncertainties=True, debug=False)[source]
Carry out a cautious downhill fit.
This tries to take the same steps as
pint.fitter.WLSFitter.fit_toas()
orpint.fitter.GLSFitter.fit_toas()
orpint.fitter.WidebandTOAFitter.fit_toas()
. At each step, it checks whether the new model has a betterchi2
than the current one; if the new model is invalid or worse than the current one, it tries taking a shorter step in the same direction. This can exit if it exceeds the maximum number of iterations or if improvement is not possible even with very short steps, or it can exit successfully if a full-size step is taken and it does not decrease thechi2
by much.The attribute
self.converged
is set to True or False depending on whether the process actually converged.This function can also estimate white noise parameters (EFACs and EQUADs) and their uncertainties.
If there are no free white noise parameters, this function will do one iteration of the downhill fit (implemented in the _fit_toas() method). If free white noise parameters are present, it will fit for them by numerically maximizing the likelihood function (implemented in the _fit_noise() method). The timing model fit and the noise model fit are run iteratively in an alternating fashion. Fitting for a white noise parameter is as simple as:
fitter.model.EFAC1.frozen = False fitter.fit_toas()
- Parameters:
maxiter (int) – Abandon the process if this many successful steps have been taken.
required_chi2_decrease (float) – A full-size step that makes less than this much improvement is taken to indicate that the fitter has converged.
max_chi2_increase (float) – If this is positive, consider taking steps that slightly worsen the chi2 in hopes of eventually finding our way downhill.
min_lambda (float) – If steps are shrunk by this factor and still don’t result in improvement, abandon hope of convergence and stop.
noisefit_method (str) – Algorithm used to fit for noise parameters. See the documentation for scipy.optimize.minimize() for more details and available options.
- classmethod auto(toas, model, downhill=True, track_mode=None, residuals=None, **kwargs)
Automatically return the proper
pint.fitter.Fitter
object depending on the TOAs and model.In general the downhill fitters are to be preferred. See https://github.com/nanograv/PINT/wiki/How-To#choose-a-fitter for the logic used.
- Parameters:
toas (a pint TOAs instance) – The input toas.
model (a pint timing model instance) – The initial timing model for fitting.
downhill (bool, optional) – Whether or not to use the downhill fitter variant
track_mode (str, optional) – How to handle phase wrapping. This is used when creating
pint.residuals.Residuals
objects, and its meaning is defined there.residuals (
pint.residuals.Residuals
) – Initial residuals. This argument exists to support an optimization, whereGLSFitter
is used to computechi2
for appropriate Residuals objects.
- Returns:
Returns appropriate subclass
- Return type:
- ftest(parameter, component, remove=False, full_output=False, maxiter=1)
Compare the significance of adding/removing parameters to a timing model.
- Parameters:
parameter (PINT parameter object) – (may be a list of parameter objects)
component (String) – Name of component of timing model that the parameter should be added to (may be a list) The number of components must equal number of parameters.
remove (Bool) – If False, will add the listed parameters to the model. If True will remove the input parameters from the timing model.
full_output (Bool) – If False, just returns the result of the F-Test. If True, will also return the new model’s residual RMS (us), chi-squared, and number of degrees of freedom of new model.
maxiter (int) – How many times to run the linear least-squares fit, re-evaluating the derivatives at each step for the F-tested model. Default is one.
- Returns:
- ftFloat
F-test significance value for the model with the larger number of components over the other. Computed with pint.utils.FTest().
- resid_rms_testFloat (Quantity)
If full_output is True, returns the RMS of the residuals of the tested model fit. Will be in units of microseconds as an astropy quantity. If wideband fitter this will be the time residuals.
- resid_wrms_testFloat (Quantity)
If full_output is True, returns the Weighted RMS of the residuals of the tested model fit. Will be in units of microseconds as an astropy quantity. If wideband fitter this will be the time residuals.
- chi2_testFloat
If full_output is True, returns the chi-squared of the tested model. If wideband fitter this will be the total chi-squared of the combined residual.
- dof_testInt
If full_output is True, returns the degrees of freedom of the tested model. If wideband fitter this will be the total chi-squared of the combined residual.
- dm_resid_rms_testFloat (Quantity)
If full_output is True and a wideband timing fitter is used, returns the RMS of the DM residuals of the tested model fit. Will be in units of pc/cm^3 as an astropy quantity.
- dm_resid_wrms_testFloat (Quantity)
If full_output is True and a wideband timing fitter is used, returns the Weighted RMS of the DM residuals of the tested model fit. Will be in units of pc/cm^3 as an astropy quantity.
- Return type:
dictionary
- get_allparams()
Return a dict of all param names and values. Deprecated.
- get_derived_params(returndict=False)
Return a string with various derived parameters from the fitted model
- Parameters:
returndict (bool, optional) – Whether to only return the string of results or also a dictionary
- Returns:
results (str)
parameters (dict, optional)
- get_designmatrix()
Return the model’s design matrix for these TOAs.
- get_fitparams()
Return a dict of fittable param names and quantity. Deprecated.
- get_fitparams_num()
Return a dict of fittable param names and numeric values. Deprecated.
- get_fitparams_uncertainty()
Return a dict of fittable param names and numeric values. Deprecated.
- get_parameter_correlation_matrix(with_phase=False, pretty_print=False, prec=3, usecolor=True)
Show the parameter correlation matrix post-fit.
If with_phase, then show and return the phase column as well. If pretty_print, then also pretty-print on stdout the matrix. prec is the precision of the floating point results. If usecolor is True, then pretty printing will have color.
- get_parameter_covariance_matrix(with_phase=False, pretty_print=False, prec=3)
Show the parameter covariance matrix post-fit.
If with_phase, then show and return the phase column as well. If pretty_print, then also pretty-print on stdout the matrix. prec is the precision of the floating point results.
- get_params_dict(which='free', kind='quantity')
Return a dict mapping parameter names to values.
- get_summary(nodmx=False)
Return a human-readable summary of the Fitter results.
- Parameters:
nodmx (bool) – Set to True to suppress printing DMX parameters in summary
- minimize_func(x, *args)
Wrapper function for the residual class.
This is meant to be passed to
scipy.optimize.minimize
. The function must take a single list of input values, x, and a second optional tuple of input arguments. It returns a quantity to be minimized (in this case chi^2).
- plot()
Make residuals plot.
This produces a time residual plot.
- print_summary()
Write a summary of the TOAs to stdout.
- reset_model()
Reset the current model to the initial model.
- set_fitparams(*params)
Update the “frozen” attribute of model parameters. Deprecated.
- set_param_uncertainties(fitp)
Set the model parameters to the value contained in the input dict.
See
pint.models.timing_model.TimingModel.set_param_uncertainties()
.
- set_params(fitp)
Set the model parameters to the value contained in the input dict.
See
pint.models.timing_model.TimingModel.set_param_values()
.
- update_model(chi2=None)
Update the model to reflect fit results and TOA properties.
This is called by
fit_toas
to ensure that parameters likeSTART
,FINISH
,EPHEM
, andDMDATA
are set in the model to reflect the TOAs in actual use.
- update_resids()
Update the residuals.
Run after updating a model parameter.