Package SloppyCell :: Module Model_mod :: Class Model
[hide private]

Class Model

source code


A Model object connects a set of experimental data with the objects used to
model that data.

Most importantly, a Model can calculate a cost for a given set of 
parameters, characterizing how well those parameters fit the data contained
within the model.

Instance Methods [hide private]
 
__init__(self, expts, calcs)
expts A sequence of Experiments to be fit to.
source code
 
compile(self)
Compile all the calculations contained within the Model.
source code
 
copy(self) source code
 
__repr__(self) source code
 
get_params(self)
Return a copy of the current model parameters
source code
 
get_ICs(self)
Get the initial conditions currently present in a model for dynamic variables that are not assigned variables.
source code
 
set_ICs(self, ics)
Sets the initial conditions into the model.
source code
 
_evaluate(self, params, T=1)
Evaluate the cost for the model, returning the intermediate residuals, and chi-squared.
source code
 
res(self, params)
Return the residual values of the model fit given a set of parameters
source code
 
res_log_params(self, log_params)
Return the residual values given the logarithm of the parameters
source code
 
res_dict(self, params)
Return the residual values of the model fit given a set of parameters in dictionary form.
source code
 
chisq(self, params)
Return the sum of the squares of the residuals for the model
source code
 
redchisq(self, params)
Return chi-squared divided by the number of degrees of freedom
source code
 
cost(self, params)
Return the cost (1/2 chisq) of the model
source code
 
cost_log_params(self, log_params)
Return the cost given the logarithm of the input parameters
source code
 
free_energy(self, params, T) source code
 
_notify(self, **args)
Call all observers with the given arguments.
source code
 
attach_observer(self, obs_key, observer)
Add an observer to be notified by this Model.
source code
 
detach_observer(self, obs_key)
Remove an observer from the Model.
source code
 
get_observers(self)
Return the KeyedList of observers for this model.
source code
 
reset_observers(self)
Call reset() for all attached observers.
source code
 
resDict(self, params)
Return the residual values of the model fit given a set of parameters in dictionary form.
source code
 
AddResidual(self, res) source code
 
Force(self, params, epsf, relativeScale=False, stepSizeCutoff=None)
Force(parameters, epsilon factor) -> list
source code
 
gradient_sens(self, params)
Return the gradient of the cost, d_cost/d_param as a KeyedList.
source code
 
gradient_log_params_sens(self, log_params)
Return the gradient of the cost wrt log parameters, d_cost/d_log_param as a KeyedList.
source code
dictionary

CalculateForAllDataPoints(parameters)
Gets a dictionary of measured independent variables indexed by calculation from the ExperimentCollection and passes it to the CalculationCollection.
source code
dictionary

CalculateSensitivitiesForAllDataPoints(parameters)
Gets a dictionary of measured independent variables indexed by calculation from the ExperimentCollection and passes it to the CalculationCollection.
source code
 
ComputeInternalVariables(self, T=1) source code
 
compute_scale_factors(self, T)
Compute the scale factors for the current parameters and return a dict.
source code
 
_compute_sf_and_sfent_for_expt(self, expt, T) source code
 
_integral_theorytheory(self, var, theory_traj, uncert_traj, interval) source code
 
_integral_theorydata(self, var, theory_traj, data_traj, uncert_traj, interval) source code
dictionary

ComputeInternalVariableDerivs()
Returns the scale factor derivatives w.r.t.
source code
 
jacobian_log_params_sens(self, log_params)
Return a KeyedList of the derivatives of the model residuals w.r.t.
source code
 
jacobian_sens(self, params)
Return a KeyedList of the derivatives of the model residuals w.r.t.
source code
 
jacobian_fd(self, params, eps, relativeScale=False, stepSizeCutoff=None)
Return a KeyedList of the derivatives of the model residuals w.r.t.
source code
dictionary

GetJacobian(parameters)
Gets a dictionary of the sensitivities at the time points of the independent variables for the measured dependent variables for each calculation and experiment.
source code
 
Jacobian(self, params, epsf, relativeScale=False, stepSizeCutoff=None)
Finite difference the residual dictionary to get a dictionary for the Jacobian.
source code
 
GetJandJtJ(self, params) source code
 
GetJandJtJInLogParameters(self, params) source code
 
hessian_elem(self, func, f0, params, i, j, epsi, epsj, relativeScale, stepSizeCutoff, verbose)
Return the second partial derivative for func w.r.t.
source code
 
hessian(self, params, epsf, relativeScale=True, stepSizeCutoff=None, jacobian=None, verbose=False)
Returns the hessian of the model.
source code
 
hessian_log_params(self, params, eps, relativeScale=False, stepSizeCutoff=1e-6, verbose=False)
Returns the hessian of the model in log parameters.
source code
 
CalcHessianInLogParameters(self, params, eps, relativeScale=False, stepSizeCutoff=1e-6, verbose=False) source code
 
CalcHessian(self, params, epsf, relativeScale=True, stepSizeCutoff=None, jacobian=None, verbose=False)
Finite difference the residual dictionary to get a dictionary for the Hessian.
source code
 
CalcResidualResponseArray(self, j, h)
Calculate the Residual Response array.
source code
 
CalcParameterResponseToResidualArray(self, j, h)
Calculate the parameter response to residual array.
source code
 
SetExperimentCollection(self, exptColl) source code
 
get_expts(self) source code
 
set_var_optimizable(self, var, is_optimizable) source code
 
GetExperimentCollection(self) source code
 
SetCalculationCollection(self, calcColl) source code
 
get_calcs(self) source code
 
GetCalculationCollection(self) source code
 
GetScaleFactors(self) source code
 
GetResiduals(self) source code
 
GetCalculatedValues(self) source code
 
GetInternalVariables(self) source code
Class Variables [hide private]
  imag_cutoff = 1e-8
Method Details [hide private]

__init__(self, expts, calcs)
(Constructor)

source code 

expts  A sequence of Experiments to be fit to.
calcs  A sequence of calculation objects referred to by the 
       Experiments.

get_ICs(self)

source code 

Get the initial conditions currently present in a model
for dynamic variables that are not assigned variables.

Outputs:
  KeyedList with keys (calcName,varName) --> initialValue

set_ICs(self, ics)

source code 

Sets the initial conditions into the model. Uses the input
format defined by 'getICs'.

Inputs:
 ics -- Initial conditions to set in KeyedList form:
          keys: (calcName, varName) --> intialValue

Outputs:
 None

_evaluate(self, params, T=1)

source code 

Evaluate the cost for the model, returning the intermediate residuals,
and chi-squared.

(Summing up the residuals is a negligible amount of work. This 
 arrangment makes notification of observers much simpler.)

redchisq(self, params)

source code 

Return chi-squared divided by the number of degrees of freedom

Question: Are priors to be included in the N data points?
          How do scale factors change the number of d.o.f.?

Force(self, params, epsf, relativeScale=False, stepSizeCutoff=None)

source code 

Force(parameters, epsilon factor) -> list

Returns a list containing the numerical gradient of the cost with
respect to each parameter (in the parameter order of the
CalculationCollection). Each element of the gradient is:
    cost(param + eps) - cost(param - eps)/(2 * eps).
If relativeScale is False then epsf is the stepsize used (it should
already be multiplied by typicalValues before Jacobian is called)
If relativeScale is True then epsf is multiplied by params.
The two previous statements hold for both scalar and vector valued
epsf.

gradient_sens(self, params)

source code 

Return the gradient of the cost, d_cost/d_param as a KeyedList.

This method uses sensitivity integration, so it only applies to
ReactionNetworks.

gradient_log_params_sens(self, log_params)

source code 

Return the gradient of the cost wrt log parameters, d_cost/d_log_param
as a KeyedList.

This method uses sensitivity integration, so it only applies to
ReactionNetworks.

CalculateForAllDataPoints(parameters)

source code 
Gets a dictionary of measured independent variables indexed by 
calculation from the ExperimentCollection and passes it to the
CalculationCollection. The returned dictionary is of the form:
 dictionary[experiment][calculation][dependent variable]
           [independent variabled] -> calculated value.

Returns:
dictionary

CalculateSensitivitiesForAllDataPoints(parameters)

source code 
Gets a dictionary of measured independent variables indexed by
calculation from the ExperimentCollection and passes it to the
CalculationCollection. The returned dictionary is of the form:
 dictionary[experiment][calculation][dependent variable]
           [independent variabled][parameter] -> sensitivity.

Returns:
dictionary

compute_scale_factors(self, T)

source code 

Compute the scale factors for the current parameters and return a dict.

The dictionary is of the form dict[exptId][varId] = scale_factor

ComputeInternalVariableDerivs()

source code 
Returns the scale factor derivatives w.r.t. parameters
appropriate for each chemical in each
experiment, given the current parameters. The returned dictionary
is of the form: internalVarsDerivs['scaleFactors']                 = dict[experiment][chemical][parametername] -> derivative.

Returns:
dictionary

jacobian_log_params_sens(self, log_params)

source code 

Return a KeyedList of the derivatives of the model residuals w.r.t.
the lograithms of the parameters parameters.

The method uses the sensitivity integration. As such, it will only
work with ReactionNetworks.

The KeyedList is of the form:
    kl.get(resId) = [dres/dlogp1, dres/dlogp2...]

jacobian_sens(self, params)

source code 

Return a KeyedList of the derivatives of the model residuals w.r.t.
parameters.

The method uses the sensitivity integration. As such, it will only
work with ReactionNetworks.

The KeyedList is of the form:
    kl[resId] = [dres/dp1, dres/dp2...]

jacobian_fd(self, params, eps, relativeScale=False, stepSizeCutoff=None)

source code 

Return a KeyedList of the derivatives of the model residuals w.r.t.
parameters.

The method uses finite differences.

Inputs:
 params -- Parameters about which to calculate the jacobian
 eps -- Step size to take, may be vector or scalar.
 relativeScale -- If true, the eps is taken to be the fractional
                  change in parameter to use in finite differences.
 stepSizeCutoff -- Minimum step size to take.

GetJacobian(parameters)

source code 
Gets a dictionary of the sensitivities at the time points of
the independent variables for the measured dependent variables
for each calculation and experiment.
Form:
dictionary[(experiment,calculation,dependent variable,
independent variable)] -> result

result is a vector of length number of parameters containing
the sensitivity at that time point, in the order of the ordered
parameters

Returns:
dictionary

Jacobian(self, params, epsf, relativeScale=False, stepSizeCutoff=None)

source code 

Finite difference the residual dictionary to get a dictionary
for the Jacobian. It will be indexed the same as the residuals.
Note: epsf is either a scalar or an array.
If relativeScale is False then epsf is the stepsize used (it should
already be multiplied by typicalValues before Jacobian is called)
If relativeScale is True then epsf is multiplied by params.
The two previous statements hold for both scalar and vector valued
epsf.

hessian_elem(self, func, f0, params, i, j, epsi, epsj, relativeScale, stepSizeCutoff, verbose)

source code 

Return the second partial derivative for func w.r.t. parameters i and j

f0: The value of the function at params
eps: Sets the stepsize to try
relativeScale: If True, step i is of size p[i] * eps, otherwise it is
               eps
stepSizeCutoff: The minimum stepsize to take

hessian(self, params, epsf, relativeScale=True, stepSizeCutoff=None, jacobian=None, verbose=False)

source code 

Returns the hessian of the model.

epsf: Sets the stepsize to try
relativeScale: If True, step i is of size p[i] * eps, otherwise it is
               eps
stepSizeCutoff: The minimum stepsize to take
jacobian: If the jacobian is passed, it will be used to estimate
          the step size to take.
vebose: If True, a message will be printed with each hessian element
        calculated

hessian_log_params(self, params, eps, relativeScale=False, stepSizeCutoff=1e-6, verbose=False)

source code 

Returns the hessian of the model in log parameters.

eps: Sets the stepsize to try
relativeScale: If True, step i is of size p[i] * eps, otherwise it is
               eps
stepSizeCutoff: The minimum stepsize to take
vebose: If True, a message will be printed with each hessian element
        calculated

CalcHessian(self, params, epsf, relativeScale=True, stepSizeCutoff=None, jacobian=None, verbose=False)

source code 

Finite difference the residual dictionary to get a dictionary
for the Hessian. It will be indexed the same as the residuals.
Note: epsf is either a scalar or an array.
If relativeScale is False then epsf is the stepsize used (it should
already be multiplied by typicalValues before Jacobian is called)
If relativeScale is True then epsf is multiplied by params.
The two previous statements hold for both scalar and vector valued
epsf.

CalcResidualResponseArray(self, j, h)

source code 

Calculate the Residual Response array. This array represents the change
in a residual obtained by a finite change in a data value.

Inputs:
(self, j, h)
j -- jacobian matrix to use
h -- hessian matrix to use

Outputs:
response -- The response array

CalcParameterResponseToResidualArray(self, j, h)

source code 

Calculate the parameter response to residual array. This array
represents the change in parameter resulting from a change in data
(residual).

Inputs:
(self, j, h)
j -- jacobian matrix to use
h -- hessian matrix to use

Outputs:
response -- The response array