lumicks.pylake.fitting.model.Model¶
-
class
Model(name, model_function, dependent=None, independent=None, jacobian=None, derivative=None, eqn=None, eqn_tex=None, **kwargs)¶ -
__init__(name, model_function, dependent=None, independent=None, jacobian=None, derivative=None, eqn=None, eqn_tex=None, **kwargs)¶ Model constructor. A Model must be named, and this name will appear in the model parameters.
Ideally a jacobian and derivative w.r.t. the independent variable are provided with every model. This will allow much higher performance when fitting. Jacobians and derivatives are automatically propagated to composite models, inversions of models etc. provided that all participating models have jacobians and derivatives specified.
Parameters: - name : str
Name for the model. This name will be prefixed to the model parameter names.
- model_function : callable
Function containing the model function. Must return the model prediction given values for the independent variable and parameters.
- dependent : str (optional)
Name of the dependent variable
- independent : str (optional)
Name of the independent variable
- jacobian : callable (optional)
Function which computes the first order derivatives with respect to the parameters for this model. When supplied, this function is used to speed up the optimization considerably.
- derivative : callable (optional)
Function which computes the first order derivative with respect to the independent parameter. When supplied this speeds up model inversions considerably.
- eqn : str (optional)
Equation that this model is specified by.
- eqn_tex : str (optional)
Equation that this model is specified by using TeX formatting.
- **kwargs
Key pairs containing parameter defaults. For instance, Lc=Parameter(…)
Examples
from lumicks import pylake dna_model = pylake.inverted_odijk("DNA") fit = pylake.FdFit(dna_model) fit.add_data("my data", force, distance) fit["DNA/Lp"].lower_bound = 35 # Set lower bound for DNA Lp fit["DNA/Lp"].upper_bound = 80 # Set upper bound for DNA Lp fit.fit() fit.plot("my data", "k--") # Plot the fitted model
Methods
__init__(name, model_function[, dependent, …])Model constructor. derivative(independent, param_vector)Return derivative w.r.t. get_formatted_equation_string(tex)invert([independent_min, independent_max, …])Invert this model (swap dependent and independent parameter). jacobian(independent, param_vector)Return model sensitivities at specific values for the independent variable. plot(params, independent[, fmt])Plot this model for a specific data set. subtract_independent_offset()Subtract a constant offset from independent variable of this model. verify_derivative(independent, params[, dx])Verify this model’s derivative with respect to the independent variable by comparing it to the derivative obtained with finite differencing. verify_jacobian(independent, params[, plot, …])Verify this model’s Jacobian with respect to the independent variable by comparing it to the Jacobian obtained with finite differencing. Attributes
defaultshas_derivativeReturns true if the model can return an analytically computed derivative w.r.t. has_jacobianReturns true if the model can return an analytically computed Jacobian. parameter_names-
__call__(independent, params)¶ Evaluate the model for specific parameters
Parameters: - independent : array_like
- params :
pylake.fitting.Params
-
derivative(independent, param_vector)¶ Return derivative w.r.t. the independent variable at specific values for the independent variable. Returns None when the model does not have an appropriately defined derivative.
Parameters: - independent : array_like
Values for the independent variable at which the derivative needs to be returned.
- param_vector : array_like
Parameter vector at which to simulate.
-
invert(independent_min=0.0, independent_max=inf, interpolate=False)¶ Invert this model (swap dependent and independent parameter).
-
jacobian(independent, param_vector)¶ Return model sensitivities at specific values for the independent variable. Returns None when the model does not have an appropriately defined Jacobian.
Parameters: - independent : array_like
Values for the independent variable at which the Jacobian needs to be returned.
- param_vector : array_like
Parameter vector at which to simulate.
-
plot(params, independent, fmt='', **kwargs)¶ Plot this model for a specific data set.
Parameters: - params : Params
Parameter set, typically obtained from a Fit.
- independent : array_like
Array of values for the independent variable.
- fmt : str (optional)
Plot formatting string (see
matplotlib.pyplot.plotdocumentation).- **kwargs :
Forwarded to
~matplotlib.pyplot.plot.
Examples
dna_model = pylake.inverted_odijk("DNA") # Use an inverted Odijk eWLC model. fit = pylake.FdFit(dna_model) fit.add_data("data1", force1, distance1) fit.add_data("data2", force2, distance2, {"DNA/Lc": "DNA/Lc_RecA"}) fit.fit() # Option 1 fit.plot("data 1", 'k--', distance1) # Plot model simulations for data set 1 fit.plot("data 2", 'k--', distance2) # Plot model simulations for data set 2 # Option 2 dna_model.plot(fit["data1"], distance1, 'k--') # Plot model simulations for data set 1 dna_model.plot(fit["data2"], distance2, 'k--') # Plot model simulations for data set 2
-
subtract_independent_offset()¶ Subtract a constant offset from independent variable of this model.
-
verify_derivative(independent, params, dx=1e-06, **kwargs)¶ Verify this model’s derivative with respect to the independent variable by comparing it to the derivative obtained with finite differencing.
Parameters: - independent : array_like
Values for the independent variable at which to compare the derivative.
- params : array_like
Parameter vector at which to compare the derivative.
- dx : float
Finite difference excursion.
-
verify_jacobian(independent, params, plot=False, verbose=True, dx=1e-06, **kwargs)¶ Verify this model’s Jacobian with respect to the independent variable by comparing it to the Jacobian obtained with finite differencing.
Parameters: - independent : array_like
Values for the independent variable at which to compare the Jacobian.
- params : array_like
Parameter vector at which to compare the Jacobian.
- plot : bool
Plot the results (default = False)
- verbose : bool
Print the result (default = True)
- dx : float
Finite difference excursion.
- **kwargs :
Forwarded to
~matplotlib.pyplot.plot.
-
has_derivative¶ Returns true if the model can return an analytically computed derivative w.r.t. the independent variable.
-
has_jacobian¶ Returns true if the model can return an analytically computed Jacobian.
-