/** * Constrained least squares: `nnls` (Lawson–Hanson active-set non-negative * least squares) and `lsqBounded` (projected-gradient box-constrained least * squares). Both minimize `||Ax - b||_2` subject to simple bound constraints * on `x`, complementing the unconstrained `leastSquares` (`../typed/numeric.ts`). * * @packageDocumentation */ /** Options shared by `nnls` and `lsqBounded`. */ export interface NnlsOptions { /** Convergence tolerance (default 1e-10). */ tol?: number; /** Maximum iterations (default `3 * n`). */ maxIter?: number; } /** Options for `lsqBounded` (same shape as `NnlsOptions`, kept as a distinct alias for clarity). */ export type LsqBoundedOptions = NnlsOptions; /** Result of `nnls` / `lsqBounded`: the solution and its residual norm. */ export interface NnlsResult { /** Solution vector x. */ x: number[]; /** `||Ax - b||_2` at the returned solution. */ residual: number; } /** Alias for `NnlsResult` (used by `lsqBounded`). */ export type LsqBoundedResult = NnlsResult; /** * Non-negative least squares: `min ||Ax - b||_2 s.t. x >= 0`, via the * Lawson–Hanson active-set algorithm. * * Maintains a "passive" set `P` of coordinates allowed to be nonzero (all * others held at 0). Each outer iteration adds to `P` the inactive index * with the most positive gradient component `w_j = (A^T(b - Ax))_j`, solves * the unconstrained least-squares problem restricted to the columns in `P` * (via `leastSquares`), and — if that restricted solution has any * non-positive component — walks back along the line from the current `x` * toward it until the first such component would hit zero, dropping that * index from `P` and re-solving. Terminates when no inactive index has a * positive gradient (KKT optimality) or `maxIter` is exhausted. * * @param A - Matrix (m x n) * @param b - Right-hand side (length m) * @param opts - Options (tol, maxIter; default maxIter = 3n) * @returns `{ x, residual }` with `x >= 0` (up to `tol`) and `residual = ||Ax - b||_2` * * @example * nnls([[1, 0], [0, 1]], [3, -2]) // => { x: [3, 0], residual: 2 } */ export declare function nnls(A: number[][], b: number[], opts?: NnlsOptions): NnlsResult; /** * Box-constrained least squares: `min ||Ax - b||_2 s.t. lower <= x <= upper`, * via projected-gradient descent. * * Each iteration computes the gradient `g = A^T(Ax - b)` of the smooth * objective `f(x) = (1/2)||Ax - b||^2`, takes a candidate step * `x - alpha*g` projected (clipped) into the box, and backtracks * (`alpha /= 2`) until the projected step does not increase `f`. Converges * when the projected-gradient norm `||x - clip(x - g, lower, upper)||` is * below `tol`. * * @param A - Matrix (m x n) * @param b - Right-hand side (length m) * @param lower - Per-component lower bounds (length n) * @param upper - Per-component upper bounds (length n) * @param opts - Options (tol, maxIter; default maxIter = max(200, 20n)) * @returns `{ x, residual }` with `lower <= x <= upper` and `residual = ||Ax - b||_2` * * @example * lsqBounded([[1, 0], [0, 1]], [5, -3], [0, 0], [2, 2]) // => { x: [2, 0], residual: ... } */ export declare function lsqBounded(A: number[][], b: number[], lower: number[], upper: number[], opts?: LsqBoundedOptions): LsqBoundedResult; //# sourceMappingURL=nnls.d.ts.map