itcsimlib.itc_fit module

Provides model parameter optimization to fit experimental data.

class itcsimlib.itc_fit.ITCFit(sim, method='simplex', method_args={}, verbose=False)[source]

Bases: object

A class for optimizing model parameters to accurately fit experimental data.

model

The model to use for fitting the experimental data.

Type:ITCModel
bounds

A parameter-name keyed dict of low and high bounds to enforce during fitting (retrieved from the model itself, or explicitly provided by the user).

Type:dict of tuples
chisq

The most recently evaluated goodness-of-fit chisquare.

Type:float
set_sim(sim)[source]

Sets the simulator to use for fitting.

get_sim()[source]

Returns the simulator used for fitting.

add_bounds(param, low=None, high=None)[source]

Add low and/or high boundaries for the specified parameter.

Parameters:
  • param (string) – The name of the parameter to create the boundary for
  • low (float) – The lower boundary for the parameter, or None for no boundary
  • high (float) – The upper boundary for the parameter, or None for no boundary
Returns:

Return type:

None

Notes

Implementation of parameter boundaries is fit method dependent and can be unpredictable. Use at your own risk, and sparingly.

optimize(params=[], callback=None, update_fits=False, use_bounds=True)[source]

Optimize the specified parameters.

Parameters:
  • params (dict of strings) – The names of the model parameters to optimize.
  • callback (function) – A callback function to call at each optimization step, will be passed a vector of the current parameter values.
  • update_fits (boolean) – Update the dQ_fit attributes of the experiments in the simulator object?
Returns:

A parameter-name keyed dict of optimized values, and the corresponding goodness-of-fit.

Return type:

(dict,float)

estimate(params, method='bootstrap', *args, **kwargs)[source]

Wrapper for the two methods of estimating uncertainties in the fitted parameter values

Parameters:
  • params (list of strings) – The names of the model parameters to find intervals for.
  • method (string) – The method to use for interval estimation (either “sigma” or “bootstrap”)
  • *args – Positional arguments to pass to either estimate_sigma or estimate_bootstrap
  • **kwargs – Keyword arguments to pass to either estimate_sigma or estimate_bootstrap
Returns:

A parameter-name keyed dict of tuples consisting of the mean and standard deviation, or high and low values of the provided parameters.

Return type:

dict of tuples

estimate_sigma(params=[], params_opt=None, sigma=None, stdevs=1, estimate=0.1, rootfinder='bisect', tolerance=0.001)[source]

Generate high and low parameter value estimates for optimized parameters according to the provided criterion

Parameters:
  • params (list of strings) – The names of the model parameters to find intervals for.
  • params_opt (list of strings) – The names of the model parameters to optimize. Setting to None implies that all available model parameters will be optimized (except the parameter that is being evaluated).
  • sigma (float) – The critical chisq value of the overall fit to use for estimating a parameter’s expected maximum and minimum (to be used in lieu of the stdevs parameter)
  • stdevs (int) – The number of standard deviations above the best-fit chi-square value to use as the critical cutoff for estimating a parameter’s expected maximum and minimum (to be used in lieu of the sigma parameter)
  • estimate (float) – A guess of how large the change from the optimized parameter values should be (up or down) in order to generate the critical chi-square value.
  • rootfinder (string) – The algorithm used to find the root of the target function (“bisect” or “secant”)
  • tolerance (float) – The tolerance (in standard deviations) used to find the critical parameter values. Smaller numbers mean a more accurate estimation of a parameter’s estimated maximum and minimum values.
Returns:

A parameter-name keyed dict of tuples consisting of the high and low estimates for each of the parameters in the “params” argument.

Return type:

(dict of tuples)

estimate_bootstrap(params=[], bootstraps=100, randomize=0.1, callback=None, logfile=None)[source]

Generate confidence intervals for optimized parameters by bootstrapping (also known as jackknife estimation)

Parameters:
  • params (list of strings) – The names of the model parameters to find intervals for.
  • bootstraps (int) – The number of synthetic datasets to refit.
  • randomize (float) – A fraction by which to perturb the starting parameters before optimization.
  • callback (function) – A callback function to call at each optimization step, will be passed a vector of the current parameter values.
  • logfile (string) – A file path to write the optimized parameter values for each bootstrap dataset
Returns:

A parameter-name keyed dict of tuples consisting of the mean and standard deviation of the optimized values.

Return type:

(dict of tuples)