_fit_coefficients

Signature

_fit_coefficients(
    x: FloatVector,
    y: FloatVector,
    weights: FloatVector,
) -> tuple[float, float, float]

What problem it solves

Computes one update of the weighted linear-fit coefficients: slope, intercept, and weighted variance of x.

Input contract

  • x, y, and weights must already be validated by the caller.

  • weights must contain strictly positive weights.

  • x must have a finite, non-zero weighted variance.

Where it is used

  • in lin_fit for the initial coefficient estimate

  • in lin_fit at each iteration when sigma_x is provided

Failure modes

  • ValueError if the weighted variance of x is not finite

  • ValueError if the weighted variance of x is too close to zero, meaning there are not enough distinct values to estimate the slope

Why it stays private

It is an internal building block of the lin_fit algorithm. Documenting it clarifies the calculation flow, but it would not make much sense as a separate public endpoint.