pyhctsa.robust.bf_fit_density_curve

pyhctsa.robust.bf_fit_density_curve(x, p, model)

Deterministic least-squares fit of a simple curve to a density (hctsa BF_FitDensityCurve).

Fits a Gaussian, a sum of two Gaussians, an exponential or a power law to a density (or histogram) p at the points x by minimizing the sum of squared differences. No random starts and no toolbox optimizer: each model starts at a fixed point computed from the data, and a Levenberg-Marquardt iteration with analytic Jacobians descends to the nearest minimum.

Models: 'exp' (a*exp(b*t), t = (x - mean(x))/std(x), started from the p^2-weighted line of log p against t), 'power' (t = log(x/mean(x)), positive x), 'gauss' (the better of two starts: the distribution’s mean and standard deviation; its peak and half the standard deviation) and 'gauss2' (started from bf_gauss_mix2(); equally spaced x).

Parameters:
x : array-like

The positions (e.g. bin centers).

p : array-like

The density at each position.

model : {'gauss', 'gauss2', 'exp', 'power'}

Returns:

The fitted curve at each x.

Return type:

numpy.ndarray