Model

lumicks.pylake.fitting.model.Model

class Model(name, model_function, dependent='y', independent=None, jacobian=None, derivative=None, eqn=None, eqn_tex=None, dependent_unit='au', independent_unit='au', **kwargs)
__call__(independent, params)

Evaluate the model for specific parameters

Parameters:
  • independent (array_like) –

  • params (lumicks.pylake.fitting.parameters.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.

This operation swaps the dependent and independent parameter and should be avoided if a faster alternative (such as an analytically inverted model) exists.

By default, this function returns an inverted version of the model, where the function is inverted for each point using a least squares optimizer. Alternatively, one can use an interpolation method to perform the inversion (here the relation is interpolated using a spline and the result is looked up). Note that for the interpolation method, the range used for the independent variable must be known a-priori.

Parameters:
  • independent_min (float) – Minimum value for the independent variable over which to interpolate. Only used when interpolate is set to True.

  • independent_max (float) – Maximum value for the independent variable over which to interpolate. Only used when interpolate is set to True.

  • interpolate (bool) – Use interpolation method rather than numerical inversion.

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.plot() documentation).

  • **kwargs – Forwarded to matplotlib.pyplot.plot().

Examples

dna_model = pylake.ewlc_odijk_force("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().

property has_derivative

Returns True if the model can return an analytically computed derivative w.r.t. the independent variable.

property has_jacobian

Returns True if the model can return an analytically computed Jacobian.