calamari.fitting.models.bent_cable#

calamari.fitting.models.bent_cable(x, x_break, y_break, slope_below, slope_change, gamma)#

Two straight lines joined by a parabolic bend of half-width gamma (a “bent cable”).

y = y_break + slope_below * (x - x_break) + slope_change * q(x), with

q(x) = (x - x_break + gamma)^2 / (4 gamma) for |x - x_break| <= gamma, q(x) = x - x_break above the bend and 0 below it.

This is segmented_linear() with its corner rounded. A sharp-corner fit to a rounded feature can depend on the chosen fitting range. Allowing symmetric rounding can reduce this dependence when that shape is appropriate (see fit_breakpoint() with model="bent_cable"). The slope changes linearly across the bend, from slope_below at x_break - gamma to slope_below + slope_change at x_break + gamma. The model and its first derivative are continuous everywhere, and at gamma = 0 it is exactly segmented_linear().

The parametrisation is the one segmented_linear() uses, so the two compare parameter by parameter. x_break is the centre of the bend, where the two straight arms, extended, meet, and y_break is their value there. It is not the curve’s value at x_break, which is y_break + slope_change * gamma / 4. This is the bent cable of Chiu, Lockhart & Routledge, J. Am. Stat. Assoc. 101, 542 (2006), which the authors write beta0 + beta1 x + beta2 q(x; tau, gamma) (tau is x_break, beta1 is slope_below, beta2 is slope_change, and beta0 = y_break - slope_below * x_break). The basis q is Eq. (2) of Chiu, Lockhart & Routledge, J. Stat. Plan. Inference 127, 143 (2005).

Only the size of gamma matters: the curve uses |gamma|, so a fit without limits (plain fit() or fit_windows()) may report a negative value, meaning the same bend. That also keeps the model defined for every value MIGRAD may try. fit_breakpoint() bounds it to be positive.

Parameters:
  • x (ArrayLike) – Independent variable.

  • x_break (float) – Centre of the bend, where the extended arms meet, in the units of x.

  • y_break (float) – Value of the extended arms where they meet.

  • slope_below (float) – Slope for x < x_break - |gamma|.

  • slope_change (float) – Change of slope across the bend: the slope above x_break + |gamma| is slope_below + slope_change.

  • gamma (float) – Half-width of the bend, in the units of x; 0 gives a sharp corner.

Return type:

NDArray[double]

Returns:

numpy.ndarray – y at each x.

Examples

>>> import numpy as np
>>> from calamari.fitting import bent_cable
>>> x = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
>>> print(bent_cable(x, 2.0, 1.0, 0.5, -1.0, 1.0))
[0.   0.5  0.75 0.5  0. ]