|
PyXspec
1.0.1
|
Public Member Functions | |
| def | __init__ |
| def | error |
| def | ftest |
| def | goodness |
| def | improve |
| def | perform |
| def | renorm |
| def | show |
| def | steppar |
Public Attributes | |
| bayes | |
| Turn Bayesian inference on or off [string]. | |
| covariance | |
| The covariance matrix from the most recent fit [tuple of floats] (GET only). | |
| criticalDelta | |
| Critical delta for fit statistic convergence [float]. | |
| delta | |
| Set fit delta values to be proportional to the parameter value [float]. | |
| dof | |
| The degrees of freedom for the fit [int] (GET only). | |
| method | |
| The fitting algorithm to use [string]. | |
| nIterations | |
| The maximum number of fit iterations prior to query [int]. | |
| query | |
| The fit query setting [string]. | |
| statistic | |
| Fit statistic value from the most recent fit [float] (GET only). | |
| statMethod | |
| The type of fit statistic in use [string]. | |
| weight | |
| Change the weighting function used in the calculation of chi-sq [string]. | |
Xspec fitting class.
This is a singleton - only 1 instance allowed
Public instance attributes (implemented as properties):
bayes -- Turn Bayesian inference on or off [string].
Valid settings are "on", "off" (default), or "cons".
"cons" turns Bayesian inference on AND gives ALL
parameters a constant prior. Priors can be set for
parameters individually through the Parameter object's
'prior' attribute.
covariance -- The covariance matrix from the most recent fit [tuple
of floats] (GET only).
As with standard XSPEC's "tclout covar", this only
returns the diagonal and below-diagonal matrix
elements.
criticalDelta -- Critical delta for fit statistic convergence [float].
The absolute change in the fit statistic between
iterations, less than which the fit is deemed to
have converged.
delta -- Set fit delta values to be proportional to the
parameter value [float].
Get: Returns the current proportional setting, or 0.0 if
currently using the fixed fit delta values.
Set: Enter the constant factor which will multiply the
parameter value to produce a fit delta. A constant
factor of 0.0 or negative will turn off the use of
proportional fit deltas.
dof -- The degrees of freedom for the fit [int] (GET only).
method -- The fitting algorithm to use [string].
Choices are: "leven", "migrad", "minimize", "monte",
"simplex". The default is "leven".
When setting the method, additional arguments for
<nFitIterations> and <fit critical delta> may also be
entered. Valid formats for entering multiple
arguments are:
# Single string
Fit.method = "migrad 100 .05"
# List of strings
Fit.method = ["migrad","100",".05"]
# List of strings and numbers
Fit.method = ["migrad", 100, .05]
nIterations -- The maximum number of fit iterations prior to query [int].
query -- The fit query setting [string].
"yes": Fit will continue through query.
"no" : Fit will end at query.
"on" : User will be prompted for "y/n" response.
statistic -- Fit statistic value from the most recent fit [float]
(GET only).
statMethod -- The type of fit statistic in use [string].
Valid names: "chi" | "cstat" | "lstat"
weight -- Change the weighting function used in the calculation of
chi-sq [string].
Available functions: "standard", "gehrels",
"churazov", "model"
| def __init__ | ( | self | ) |
| def error | ( | self, | |
| argString | |||
| ) |
Determine confidence intervals of a fit.
Input: argString is a string with identical syntax to the standard
interactive XSPEC error command.
"[[stopat <ntrial> <toler>] [maximum <redchi>]
[<delta fit statistic>] [<model param range>...]]"
where:
<model param range> =::[<modelName>:]<first param> -
<last param>
See the XSPEC manual for a more detailed description.
The results of the error command are stored in the "error" attributes
of the individual Parameter objects.
Examples:
# Estimate the 90% confidence ranges for parameters 1-3
Fit.error("1-3")
# Repeat but with delta fit statistic = 9.0, equivalent to the
# 3 sigma range.
Fit.error("9.0")
# Estimate for parameter 3 after setting the number of trials to 20.
# Note that the tolerance field has to be included (or skipped over).
Fit.error("stop 20,,3")
| def ftest | ( | self, | |
| chisq2, | |||
| dof2, | |||
| chisq1, | |||
| dof1 | |||
| ) |
Calculate the F-statistic and its probability given new and old
values of chisq and number of degrees of freedom (DOF).
Input: chisq2 - float
dof2 - int
chisq1 - float
dof1 - int
Chisq2 and dof2 should come from a new fit, in which an extra model
component was added to (or a frozen parameter thawed from) the
model which gave chisq1 and dof1. If the F-test probability is
low then it is reasonable to add the extra model component.
WARNING: it is not correct to use the F-test statistic to test
for the presence of a line (see Protassov et al 2002, ApJ 571,
545).
Returns: The F-test probability [float].
| def goodness | ( | self, | |
nRealizations = 100, |
|||
sim = False |
|||
| ) |
Perform a Monte Carlo calculation of the goodness-of-fit.
nRealizations -- Number of spectra to simulate [int].
sim -- If False (default), all simulations are drawn from
the best fit model parameter values. If True,
parameters will be drawn from a Gaussian centered
on the best fit.
| def improve | ( | self | ) |
Try to find a new minimum. When Fit.method is set to one of the MINUIT algorithms, this will run the MINUIT 'improve' command. This does nothing when Fit.method is set to Levenberg-Marquardt.
| def perform | ( | self | ) |
Perform fit.
| def renorm | ( | self, | |
setting = None |
|||
| ) |
Renormalize the model to minimize statistic with current parameters
setting -- If None, this will perform an explicit immediate
renormalization. Other options determine when
renormalization will be performed automatically. They
are the following strings:
"auto" - Renormalize after a model command or parameter
change, and at the beginning of a fit.
"prefit" - Renormalize only at the beginning of a fit.
"none" - Perform no automatic renormalizations.
| def show | ( | self | ) |
Show fit information.
| def steppar | ( | self, | |
| argString | |||
| ) |
Perform a steppar run.
Generate the statistic "surface" for 1 or more parameters.
Input: argString is a string with identical syntax to the standard
interactive XSPEC steppar command.
"<step spec> [<step spec> ...]" where:
<step spec> ::= [<log|nolog>] [<current|best>]
[<modName>:]<param index> <low value> <high value> <# steps>
See the XSPEC manual for a more detailed description of specs.
Examples:
# Step parameter 3 from 1.5 to 2.5 in 10 linear steps
Fit.steppar("3 1.5 2.5 10")
# Repeat the above but with logarithmic steps
Fit.steppar("log")
# Step parameter 2 linearly from -.2 to .2 in steps of .02
Fit.steppar("nolog 2 -.2 .2 20")
Turn Bayesian inference on or off [string].
Valid settings are "on", "off" (default), or "cons". "cons" turns Bayesian inference on AND gives ALL parameters a constant prior. Priors can be set for parameters individually through the Parameter object's 'prior' attribute.
The covariance matrix from the most recent fit [tuple of floats] (GET only).
As with standard XSPEC's "tclout covar", this only returns the diagonal and below-diagonal matrix elements.
Critical delta for fit statistic convergence [float].
The absolute change in the fit statistic between iterations, less than which the fit is deemed to have converged.
Set fit delta values to be proportional to the parameter value [float].
Get: Returns the current proportional setting, or 0.0 if
currently using the fixed fit delta values.
Set: Enter the constant factor which will multiply the
parameter value to produce a fit delta. A constant
factor of 0.0 or negative will turn off the use of
proportional fit deltas.
The degrees of freedom for the fit [int] (GET only).
The fitting algorithm to use [string].
Choices are: "leven", "migrad", "minimize", "monte",
"simplex". The default is "leven".
When setting the method, additional arguments for
<nFitIterations> and <fit critical delta> may also be
entered. Valid formats for entering multiple
arguments are:
# Single string
Fit.method = "migrad 100 .05"
# List of strings
Fit.method = ["migrad","100",".05"]
# List of strings and numbers
Fit.method = ["migrad", 100, .05]
The maximum number of fit iterations prior to query [int].
The fit query setting [string].
"yes": Fit will continue through query. "no" : Fit will end at query. "on" : User will be prompted for "y/n" response.
Fit statistic value from the most recent fit [float] (GET only).
The type of fit statistic in use [string].
Valid names: "chi" | "cstat" | "lstat"
Change the weighting function used in the calculation of chi-sq [string].
Available functions: "standard", "gehrels", "churazov", "model"
1.7.5.1