parameter_trace

lumicks.pylake.parameter_trace

parameter_trace(model, params, inverted_parameter, independent, dependent, **kwargs)

Fit a model with respect to one parameter for each data point.

This function fits a unique parameter value for every data point in this data-set while keeping all other parameters fixed. This can be used to for example invert the model with respect to the contour length or some other parameter.

Note

Inverting the model with respect to a particular parameter enforces any bounds defined for that parameter in params. Results can only be trusted for values where the parameter estimate does not hit these bounds. Note that Pylake will issue a warning whenever this condition is met.

For example, when creating a worm-like chain model the parameter contour length has a lower bound of the length of one base pair by default, since zero and negative values are non-physical. If the contour length is then estimated to be exactly at the lower bound by this function, a warning is issued. Note that these bounds can be modified by changing them through the lower_bound and upper_bound attributes of a Parameter.

Parameters:
  • model (Model) – Fitting model.

  • params (Params) – Model parameters.

  • inverted_parameter (str) – Parameter to invert.

  • independent (array_like) – Vector of values for the independent variable

  • dependent (array_like) – Vector of values for the dependent variable

  • **kwargs – Forwarded to scipy.optimize.least_squares

Returns:

parameter_trace – Array of fitted parameter values for the parameter being fitted.

Return type:

np.ndarray

Raises:
  • ValueError – If specifying a parameter to invert over (inverted_parameter) that is not part of the model.

  • ValueError – If a parameter required for model simulation is missing from the supplied parameters in params.

  • ValueError – If parameters are provided that do not have a lower_bound or upper_bound property.

Examples

# Define the model to be fitted
model = pylake.ewlc_odijk_force("model") + pylake.force_offset("model")

# Fit the overall model first
model.add_data("dataset1", f=force_data, d=distance_data)
current_fit = pylake.FdFit(model)
data_handle = current_fit.add_data("my data", force, distance)
current_fit.fit()

# Calculate a per data point contour length
lcs = parameter_trace(model, current_fit[data_handle], "model/Lc", distance, force)

# Alternatively, if rather than a reference curve to fit, you have model parameters, you
# can use a Params dictionary obtained from a model directly.
model2 = lk.ewlc_odijk_distance("m")

model2["m/Lp"].value = 50
model2["m/St"].value = 1200
model2["m/Lc"].value = 5

lk.parameter_trace(model2, model2.defaults, "m/Lc", force, distance)