6.3.4. Optimization functions

6.3.4.1. Fitting spectra

class pyspex.optimize.Fit[source]

This is the parent class of all fit related commands.

Variables:
  • stat (basestring) – Fit statistics.

  • cstat (float) – C-statistics value.

  • chisq (float) – Chi-squared value.

  • wstat (float) – W-statistics value (not recommended).

  • nfree (int) – Degrees of freedom.

  • cstatexp (float) – Expected C-statistics value (C-stat only).

  • cstatrms (float) – RMS uncertainty on expected C-stat value.

  • ann_rt (float) – Simulated annealing: rt

  • ann_eps (float) – Simulated annealing: eps

  • ann_t (float) – Simulated annealing: t

  • ann_vm (float) – Simulated annealing: vm

  • ann_ns (int) – Simulated annealing: ns

  • ann_max (int) – Simulated annealing: max evaluations

  • ann_print (int) – Simulated annealing: print flag

fit(niter=100)[source]

Execute the SPEX fit command. The maximum number of iterations (niter) can be optionally set.

Parameters:

niter (int) – Number of fit iterations.

get_method()[source]

Get the current type of statistics being used in the fit, for example chi2, cstat or wstat.

get_statistic()[source]

Get the current type of statistics being used in the fit, for example chi2, cstat or wstat.

print(status)[source]

Print each fit iteration to the console (default is True). The status variable can be either True or False, which means printing is on or off, respectively.

Parameters:

status (bool) – Set fit to high verbosity (True is yes, False is no).

set_ann(param, value)[source]

Set the simulating annealing method parameters.

Parameters:
  • param (str) – Type of annealing parameter (rt, t, eps, vm, ns, max, or print).

  • value (float) – Value of the parameter (will be converted to the nearest int if necessary).

set_method(meth)[source]

Set the desired fit statistics.

Parameters:

stat (str) – Abbreviation for the fit statistics to be used. For example: ‘csta’, ‘chi2’, ‘wsta’.

set_statistic(stat)[source]

Set the desired fit statistics.

Parameters:

stat (str) – Abbreviation for the fit statistics to be used. For example: ‘csta’, ‘chi2’, ‘wsta’.

set_statistic_inst(stat, inst, reg)[source]

Set the desired fit statistics per instrument and region.

Parameters:
  • stat (str) – Abbreviation for the fit statistics to be used. For example: ‘csta’, ‘chi2’, ‘wsta’.

  • inst (int) – Instrument number.

  • reg (int) – Region number.

show()[source]

Print the fit statistics to the terminal.

update()[source]

Get the most recent statistics values from SPEX.

6.3.4.2. Error calculation

class pyspex.optimize.Error[source]

Class to calculate errors for free fit parameters.

Variables:
  • sector (int) – Sector number of parameter

  • component (int) – Component number of parameter

  • parameter (str) – Parameter name

  • value (float) – Parameter value

  • lerr (float) – Lower error boundary

  • uerr (float) – Upper error boundary

  • lc (bool) – Is there a lower C-stat or chi**2 value found?

  • cmin (float) – Lowest C-stat or chi**2 value

  • pmin (float) – Parameter value for which a better C-stat or Chi**2 was found

  • dchi (float) – Delta C-stat or chi**2 to optimize for

  • calculated (bool) – Is the error calculated?

error(isect, icomp, name, dchi=None)[source]

Calculate the error value for a particular parameter.

Parameters:
  • isect (int) – Sector number of the parameter.

  • icomp (int) – Component number of the parameter.

  • name (str) – Parameter name.

  • dchi (float) – (Optional) \Delta\chi^2 value to optimize for (Default: 1.0, 68% errors)

get_value()[source]

Convenience function to return the parameter value and the errors.

Returns:

A tuple with the parameter value, lower error and upper error.

Return type:

tuple

set_dchi(dchi)[source]

Set the delta c-stat or delta chi**2 value that the error search should optimize for. The default value is 1.0.

Parameters:

dchi (float) – \Delta\chi^2 value to optimize for (Default: 1.0, 68% errors)