sora.stats

The Parameters Class

class sora.stats.Parameters[source]

Creates a dictionary of Parameter objects. The structure of this class heavely borrows its structure from parameters.py (lmfit)

The dictionary contains all the parameters necessary to perform the fit of a model/objective function.

Parameters:

dict (dict) – A dictionary of Parameter objects.

_addpar(name, parameter)[source]

Private method to add the Parameter object to the Parameters dictionary.

Parameters:
  • name (string) – A name or label to describe the parameter

  • parameter (Parameter object) – Parameter object containing the parameter values

Raises:

ValueError – Error if passed object is not a valid Parameter object.

add(name, value=None, minval=-inf, maxval=inf, free=True, std=None, initial_value=None)[source]

Include a Parameter values collection into the Parameters dictionary.

Parameters:
  • name (str) – A name or label to describe the parameter

  • value (float, optional) – When first created it contains the initial estimate of the parameter. In a result object it contains the best fit value, by default None.

  • minval (float, optional) – The lower bound used in the parameter variation, by default -inf

  • maxval (float, optional) – The upper bound used in the parameter variation, by default inf

  • free (bool, optional) – Defines if the parameter is allowed to vary, by default True

  • std (float, array) – In the result object it contains the computed uncertainty.

  • initial_value (float) – In the result object it contains the estimate before the fit.

Returns:

object – A Parameters object containing the collection of parameters.

Return type:

Parameters

add_many(*parlist)[source]

Add many parameters using a list of tuples.

Parameters:

*parlist (list of tuple) – A list of tuples containing the parameters in a sequence. The order in each tuple must follow the sequence: (name, value, minval, maxval, free)

Returns:

object – A Parameters object containing the collection of parameters.

Return type:

Parameters

get_bounds(transposed=False)[source]

Method to get the bounds recorded in the Parameters object.

Parameters:

transposed (bool, optional) – Returns the bounds in a transposed array, by default False.

Returns:

array – Tuple array containing the bounds values.

Return type:

tuple

get_names()[source]

Method to get the names of each parameter in the object.

Returns:

list – List of parameters names.

Return type:

str, list

get_uncertainties()[source]

Method to get the uncertainties stored in the Parameters object.

Returns:

list – List of parameters uncertainties.

Return type:

float, list

get_values()[source]

Method to get the values stored in the Parameters object.

Returns:

list – List of parameters values.

Return type:

float

get_varys()[source]

Method to get the FREE values stored in the Parameters object.

Returns:

list – List of FREE parameters values.

Return type:

tuple

remove(name)[source]

Method to remove a Parameter from the Parameters dictionary.

Parameters:

name (str) – The name of the parameter to be removed.

valuesdict()[source]

Method returns a dictionary of parameter and values.

Returns:

dict – Dictionary of parameters names and values.

Return type:

dict

OptimizeResult Class

class sora.stats.OptimizeResult(**kwargs)[source]

An object that contains the results obtained by the fitting procedure

params

The best-fit parameters computed from the fit.

Type:

Parameters object

method

Method used to compute the best fit solution.

Type:

str

var_names

Ordered list of variable parameter names used in optimization, and useful for understanding the values in initial_values and covar.

Type:

list

covar

Scaled covariance matrix from minimization, with rows and columns corresponding to var_names. The covariance matrix is obtained from the approximation of the inverse of the Hessian matrix. This covariance matrix is scaled by the reduced chisqr.

Type:

numpy.ndarray

initial_values

Dictionary of initial values for varying parameters.

Type:

numpy.ndarray

best_fit

List containing best fit values corresponding to var_names.

Type:

numpy.ndarray

std

Array containing estimated N-sigma uncertainties, otherwise inf. Corresponding to var_names. In the least_squares case the formal numeric uncertainties are then derived from the covariance matrix. When uncertainties are unavailable Bootstraping can be used to derive the uncertainties. In this case confidence intervals (CI) limited by the provided sigma (z-score), e.g., 1-sigma CI will return the [0.16,0.84] quantiles as the low and high confidence intervals value.

Type:

numpy.ndarray

bootstrap

If not None, an array containing the bootstraped solutions for each variable (col), by defalut None.

Type:

None, numpy.ndarray

success

True if optimization algorithm converged.

Type:

str

nvars

Number of free variables used in fit.

Type:

int

ndata

Number of data points.

Type:

int

dof

Degrees of freedom in fit (ndata - nvars).

Type:

int

residual

Residual array of the objective function when using the parameters best-fit solution.

Type:

numpy.ndarray

chisqr

A weighted sum of squared deviations. If the objective function does not provide weighed residuals then it only expresses the sum of squared deviations.

Type:

float

redchi

The Reduced chi-square value: i is defined as chi-square per degree of freedom.

Type:

float

scipy

When scipy module is used the scipy.OptimizeResult object is also returned.

Type:

scipy.OptimizeResult object

emcee

Describe

Type:

describe

Returns:

object – A OptimizeResult object containing the collection of the results obtained by the fit.

Return type:

OptimizeResult

summary()[source]

Prints a summary of the results obtained by the fit contained in the OptimizeResult object.