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), withq(x) = (x - x_break + gamma)^2 / (4 gamma)for|x - x_break| <= gamma,q(x) = x - x_breakabove the bend and0below 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 (seefit_breakpoint()withmodel="bent_cable"). The slope changes linearly across the bend, fromslope_belowatx_break - gammatoslope_below + slope_changeatx_break + gamma. The model and its first derivative are continuous everywhere, and atgamma = 0it is exactlysegmented_linear().The parametrisation is the one
segmented_linear()uses, so the two compare parameter by parameter.x_breakis the centre of the bend, where the two straight arms, extended, meet, andy_breakis their value there. It is not the curve’s value atx_break, which isy_break + slope_change * gamma / 4. This is the bent cable of Chiu, Lockhart & Routledge, J. Am. Stat. Assoc. 101, 542 (2006), which the authors writebeta0 + beta1 x + beta2 q(x; tau, gamma)(tauisx_break,beta1isslope_below,beta2isslope_change, andbeta0 = y_break - slope_below * x_break). The basisqis Eq. (2) of Chiu, Lockhart & Routledge, J. Stat. Plan. Inference 127, 143 (2005).Only the size of
gammamatters: the curve uses|gamma|, so a fit without limits (plainfit()orfit_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 ofx.y_break (
float) – Value of the extended arms where they meet.slope_below (
float) – Slope forx < x_break - |gamma|.slope_change (
float) – Change of slope across the bend: the slope abovex_break + |gamma|isslope_below + slope_change.gamma (
float) – Half-width of the bend, in the units ofx;0gives a sharp corner.
- Return type:
- Returns:
numpy.ndarray–yat eachx.
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. ]