pyhctsa.robust.bf_exp_fit

pyhctsa.robust.bf_exp_fit(x, y, with_offset=True, max_rate=20)

Global least-squares fit of a*exp(b*x) + c by variable projection (hctsa BF_ExpFit).

For a given rate b the best a (and c) follow in closed form, so only b is searched: on a grid of 401 rates between -max_rate/range(x) and max_rate/range(x) (including 0, a constant), then refined by 40 golden-section steps around the best grid point. The result is the global optimum within the allowed range of rates and needs no starting point. If the best rate is at the edge of the range, b is that limiting value.

Parameters:
x : array-like

Predictor and data (same length).

y : array-like

Predictor and data (same length).

with_offset : bool, optional

Fit a*exp(b*x) + c (default) or a*exp(b*x).

max_rate : float, optional

Largest allowed |b| in units of 1/range(x) (default 20).

Returns:

a, b, c (c = 0 without offset), r2 (in [0,1]), adjr2, rmse (sqrt(SSE/(n-p)), p = 3 or 2). All NaN if y is constant (to within 1e-12 of its largest magnitude, so that rounding differences between equal values are not fitted) or not finite, or if there are not more points than parameters.

Return type:

dict