verde.base.least_squares

Contents

verde.base.least_squares#

verde.base.least_squares(jacobian, data, weights, damping=None, copy_jacobian=False)[source]#

Solve a least-squares problem with optional damping regularization.

Scales the Jacobian matrix so that each column has unit variance. This helps keep the regularization parameter in a sensible range. The scaling is undone before returning the estimated parameters so that scaling isn’t required for predictions.

Warning

Setting copy_jacobian to True will copy the Jacobian matrix, doubling the memory required. Use it only if the Jacobian matrix is needed afterward.

Parameters:
jacobian2d-array

The Jacobian/sensitivity/feature matrix.

data1d-array

The data array. Must be a single 1D array. If fitting multiple data components, stack the arrays and the Jacobian matrices.

weightsNone or 1d-array

The data weights. Like the data, this must also be a 1D array. Stack the weights in the same order as the data. Use weights=None to fit without weights.

dampingNone or float

The positive damping (Tikhonov 0th order) regularization parameter. If damping=None, will use scipy.linalg.lstsq to calculate the solution. Otherwise, uses scipy.linalg.solve.

copy_jacobian: bool

If False, the Jacobian matrix will be scaled inplace. If True, the Jacobian matrix will be copied before scaling. Default False.

Returns:
parameters1d-array

The estimated 1D array of parameters that fit the data.