pint.mcmc_fitter.MCMCFitter

class pint.mcmc_fitter.MCMCFitter(toas, model, sampler, **kwargs)[source]

Bases: Fitter

A class for Markov-Chain Monte Carlo optimization style-fitting

This fitting is similar to that implemented in event_optimize.py

Parameters:
  • toas (pint.toas.TOAs) –

  • model

  • sampler (pint.sampler.MCMCSampler) –

  • template (object or None) – A template profile, for example, of a gaussian pulse. If template is none, then all template methods will do nothing, or raise an error, or return None. If a template is set, it is assumed that a subclass is being used.

  • lnprior (callable) – The log prior function - defaults to lnprior above

  • lnlike (callable) – The log likelihood function - defaults to lnlikelihood above

  • setpriors (callable) – The function for setting the priors on model parameters

  • weights (optional) – Weights for likelihood calculations

  • minMJD (optional) – Minimium MJD in dataset (used sometimes for get_initial_pos)

  • maxMJD (optional) – Maximum MJD in dataset (used sometimes for get_initial_pos)

Methods

auto(toas, model[, downhill, track_mode, ...])

Automatically return the proper pint.fitter.Fitter object depending on the TOAs and model.

clip_template_params(pos)

If template parameters are changeable, ensure that they are within bounds Any passing the template bounds will be clipped to the edges.

fit_toas([maxiter, pos, errfact, priorerrfact])

Fitting function - calls sampler.run_mcmc to converge using MCMC approach

ftest(parameter, component[, remove, ...])

Compare the significance of adding/removing parameters to a timing model.

generate_fit_keyvals()

Read the model to determine fitted keys and their values and errors from the par file

get_allparams()

Return a dict of all param names and values.

get_derived_params([returndict])

Return a string with various derived parameters from the fitted model

get_designmatrix()

Return the model's design matrix for these TOAs.

get_errors()

Get errors associated with all fit parameters

get_event_phases()

Return pulse phases based on the current model

get_fit_keyvals()

Basic getter, useful in event_optimize script

get_fitparams()

Return a dict of fittable param names and quantity.

get_fitparams_num()

Return a dict of fittable param names and numeric values.

get_fitparams_uncertainty()

Return a dict of fittable param names and numeric values.

get_model_parameters(theta)

Split the parameters related to the model

get_parameter_correlation_matrix([...])

Show the parameter correlation matrix post-fit.

get_parameter_covariance_matrix([...])

Show the parameter covariance matrix post-fit.

get_parameter_names()

Get parameter names for this fitter

get_parameters()

Get all parameters for this fitter

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.

get_template_parameters(theta)

Split the parameters related to the template

get_template_vals(phases)

Use the template (if it exists) to get probabilities for given phases

get_weights()

lnposterior(theta)

The log posterior (priors * likelihood)

make_resids(model)

minimize_func(theta)

Override superclass minimize_func to make compatible with scipy.optimize

phaseogram([weights, bins, rotate, size, ...])

Make a nice 2-panel phaseogram for the current model

plot()

Make residuals plot.

plot_priors(chains, burnin[, bins, scale])

print_summary()

Write a summary of the TOAs to stdout.

prof_vs_weights([nbins, use_weights])

Show binned profiles (and H-test values) as a function of the minimum weight used.

reset_model()

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

Set timing and template parameters as necessary

set_params(fitp)

Set the model parameters to the value contained in the input dict.

set_template(template)

Sets template and template metadata.

update_model([chi2])

Update the model to reflect fit results and TOA properties.

update_resids()

Update the residuals.

Attributes

covariance_matrix

set_template(template)[source]

Sets template and template metadata. Implementation depends on whether template is analytic or binned.

get_template_vals(phases)[source]

Use the template (if it exists) to get probabilities for given phases

clip_template_params(pos)[source]

If template parameters are changeable, ensure that they are within bounds Any passing the template bounds will be clipped to the edges. If template is not being fit to, then this does nothing

get_model_parameters(theta)[source]

Split the parameters related to the model

get_template_parameters(theta)[source]

Split the parameters related to the template

get_parameters()[source]

Get all parameters for this fitter

get_parameter_names()[source]

Get parameter names for this fitter

set_parameters(theta)[source]

Set timing and template parameters as necessary

get_errors()[source]

Get errors associated with all fit parameters

get_fit_keyvals()[source]

Basic getter, useful in event_optimize script

generate_fit_keyvals()[source]

Read the model to determine fitted keys and their values and errors from the par file

get_event_phases()[source]

Return pulse phases based on the current model

lnposterior(theta)[source]

The log posterior (priors * likelihood)

minimize_func(theta)[source]

Override superclass minimize_func to make compatible with scipy.optimize

fit_toas(maxiter=100, pos=None, errfact=0.1, priorerrfact=10.0)[source]

Fitting function - calls sampler.run_mcmc to converge using MCMC approach

Parameters:
  • maxiter (int) – The number of iterations to run_mcmc for

  • pos

    The intiial position of the sampler. Default behavior calls

    sampler.get_initial_pos()

  • errfact (float, optional) – Multiplicative factor for errors in get_intial_pos

  • priorerrfact (float, optional) – Error factor in setting prior widths

phaseogram(weights=None, bins=100, rotate=0.0, size=5, alpha=0.25, plotfile=None)[source]

Make a nice 2-panel phaseogram for the current model

prof_vs_weights(nbins=50, use_weights=False)[source]

Show binned profiles (and H-test values) as a function of the minimum weight used. nbins is only for the plots.

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, where GLSFitter is used to compute chi2 for appropriate Residuals objects.

Returns:

Returns appropriate subclass

Return type:

pint.fitter.Fitter

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.

See pint.models.timing_model.TimingModel.get_params_dict().

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

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 like START, FINISH, EPHEM, and DMDATA are set in the model to reflect the TOAs in actual use.

update_resids()

Update the residuals.

Run after updating a model parameter.