@rangefoundry/statistics 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +19 -1
- package/dist/bisect.d.ts +2 -0
- package/dist/bisect.js +15 -0
- package/dist/chi-square.d.ts +6 -0
- package/dist/chi-square.js +75 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +23 -0
- package/dist/f-distribution.d.ts +2 -0
- package/dist/f-distribution.js +10 -0
- package/dist/huber.d.ts +12 -0
- package/dist/huber.js +10 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +10 -0
- package/dist/interval.d.ts +7 -0
- package/dist/interval.js +2 -0
- package/dist/issue.d.ts +5 -0
- package/dist/issue.js +4 -0
- package/dist/least-squares.d.ts +87 -0
- package/dist/least-squares.js +287 -0
- package/dist/percentile.d.ts +2 -0
- package/dist/percentile.js +9 -0
- package/dist/random.d.ts +4 -0
- package/dist/random.js +16 -0
- package/dist/student-t.d.ts +2 -0
- package/dist/student-t.js +82 -0
- package/dist/velocity-statistics.d.ts +22 -0
- package/dist/velocity-statistics.js +72 -0
- package/package.json +44 -4
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
# @rangefoundry/statistics
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The statistics the ballistics models share: chi-square, F and Student t distributions, velocity statistics with the interval of the standard deviation, least squares on log parameters with the identifiability of each, the Huber loss, bisection, and a seeded random generator. An input it refuses throws `InputError` with a typed issue `{ code, params }` (`StatisticsIssue`) and no text, so the caller words it in its language. No runtime dependencies.
|
|
4
|
+
|
|
5
|
+
With Node 26 or later:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @rangefoundry/statistics
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { chiSquareQuantile, seededUniforms, velocityStatistics } from '@rangefoundry/statistics'
|
|
13
|
+
|
|
14
|
+
chiSquareQuantile(0.975, 4) // 11.143...
|
|
15
|
+
velocityStatistics([812, 815, 809, 818])?.standardDeviation // 3.87... (m/s)
|
|
16
|
+
seededUniforms(42)() // the same number in [0, 1) for the same seed
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Changes: https://github.com/RangeFoundry/workbench/blob/main/packages/statistics/CHANGELOG.md
|
|
20
|
+
|
|
21
|
+
License: AGPL-3.0-or-later
|
package/dist/bisect.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** `below(x)` is true while x lies below the root; runs `iterations` halvings, with `stopAtEnds` stopping once the midpoint equals an end of the bracket, and returns the last midpoint; each caller keeps its own count and stop rule. */
|
|
2
|
+
export declare function bisect(below: (x: number) => boolean, bracket: readonly [low: number, high: number], iterations: number, stopAtEnds: boolean): number;
|
package/dist/bisect.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** `below(x)` is true while x lies below the root; runs `iterations` halvings, with `stopAtEnds` stopping once the midpoint equals an end of the bracket, and returns the last midpoint; each caller keeps its own count and stop rule. */
|
|
2
|
+
export function bisect(below, bracket, iterations, stopAtEnds) {
|
|
3
|
+
let [lo, hi] = bracket;
|
|
4
|
+
for (let i = 0; i < iterations; i++) {
|
|
5
|
+
const mid = (lo + hi) / 2;
|
|
6
|
+
if (stopAtEnds && (mid === lo || mid === hi))
|
|
7
|
+
break;
|
|
8
|
+
if (below(mid))
|
|
9
|
+
lo = mid;
|
|
10
|
+
else
|
|
11
|
+
hi = mid;
|
|
12
|
+
}
|
|
13
|
+
return (lo + hi) / 2;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bisect.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** `df` a positive whole number: the series below the mode, 1 minus `chiSquareSurvival` above, where the series would need about x/2 terms. */
|
|
2
|
+
export declare function chiSquareCdf(x: number, df: number): number;
|
|
3
|
+
/** Below the mode 1 minus the series of `chiSquareCdf`; above, the continued fraction of the upper incomplete gamma function (DLMF 8.9.2, https://dlmf.nist.gov/8.9#E2, contracted form) by the modified Lentz method, which keeps the relative accuracy in the upper tail where `1 - chiSquareCdf` is 0. */
|
|
4
|
+
export declare function chiSquareSurvival(x: number, df: number): number;
|
|
5
|
+
/** The `x` with `chiSquareCdf(x, df) = p`, p in (0, 1), by bisection. */
|
|
6
|
+
export declare function chiSquareQuantile(p: number, df: number): number;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** For whole degrees of freedom (`apps/docs/docs/models/groups.md`, "Confidence intervals by shot count"): P(df/2, x/2) by its power series (DLMF 8.2.6, 8.7.1), each term formed in logarithms so that large pooled samples do not underflow. */
|
|
2
|
+
import { bisect } from './bisect.js';
|
|
3
|
+
import { need } from './issue.js';
|
|
4
|
+
/** ln Gamma(a + 1) for a whole or half-whole a >= 0: a finite product down to Gamma(1) or Gamma(3/2). */
|
|
5
|
+
function lnGammaPlusOne(a) {
|
|
6
|
+
let sum = 0;
|
|
7
|
+
let t = a;
|
|
8
|
+
for (; t >= 1; t -= 1)
|
|
9
|
+
sum += Math.log(t);
|
|
10
|
+
return t > 0 ? sum + Math.log(0.5) + 0.5 * Math.log(Math.PI) : sum;
|
|
11
|
+
}
|
|
12
|
+
/** `df` a positive whole number: the series below the mode, 1 minus `chiSquareSurvival` above, where the series would need about x/2 terms. */
|
|
13
|
+
export function chiSquareCdf(x, df) {
|
|
14
|
+
need(Number.isInteger(df) && df > 0, { code: 'degreesOfFreedomNotPositiveWhole', params: {} });
|
|
15
|
+
if (!(x > 0))
|
|
16
|
+
return 0;
|
|
17
|
+
const a = df / 2;
|
|
18
|
+
const z = x / 2;
|
|
19
|
+
if (z >= a + 1)
|
|
20
|
+
return 1 - chiSquareSurvival(x, df);
|
|
21
|
+
const lnZ = Math.log(z);
|
|
22
|
+
// term k: exp(-z) z^(a+k) / Gamma(a+k+1)
|
|
23
|
+
let lnTerm = -z + a * lnZ - lnGammaPlusOne(a);
|
|
24
|
+
let sum = Math.exp(lnTerm);
|
|
25
|
+
for (let k = 1;; k++) {
|
|
26
|
+
lnTerm += lnZ - Math.log(a + k);
|
|
27
|
+
const term = Math.exp(lnTerm);
|
|
28
|
+
sum += term;
|
|
29
|
+
if (a + k > z && term <= 1e-17 * sum)
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return Math.min(sum, 1);
|
|
33
|
+
}
|
|
34
|
+
/** Below the mode 1 minus the series of `chiSquareCdf`; above, the continued fraction of the upper incomplete gamma function (DLMF 8.9.2, https://dlmf.nist.gov/8.9#E2, contracted form) by the modified Lentz method, which keeps the relative accuracy in the upper tail where `1 - chiSquareCdf` is 0. */
|
|
35
|
+
export function chiSquareSurvival(x, df) {
|
|
36
|
+
need(Number.isInteger(df) && df > 0, { code: 'degreesOfFreedomNotPositiveWhole', params: {} });
|
|
37
|
+
if (!(x > 0))
|
|
38
|
+
return 1;
|
|
39
|
+
if (x === Number.POSITIVE_INFINITY)
|
|
40
|
+
return 0;
|
|
41
|
+
const a = df / 2;
|
|
42
|
+
const z = x / 2;
|
|
43
|
+
if (z < a + 1)
|
|
44
|
+
return 1 - chiSquareCdf(x, df);
|
|
45
|
+
const tiny = 1e-300;
|
|
46
|
+
let b = z + 1 - a;
|
|
47
|
+
let c = 1 / tiny;
|
|
48
|
+
let d = 1 / b;
|
|
49
|
+
let h = d;
|
|
50
|
+
for (let i = 1; i < 10000; i++) {
|
|
51
|
+
const an = -i * (i - a);
|
|
52
|
+
b += 2;
|
|
53
|
+
d = an * d + b;
|
|
54
|
+
if (Math.abs(d) < tiny)
|
|
55
|
+
d = tiny;
|
|
56
|
+
c = b + an / c;
|
|
57
|
+
if (Math.abs(c) < tiny)
|
|
58
|
+
c = tiny;
|
|
59
|
+
d = 1 / d;
|
|
60
|
+
const delta = d * c;
|
|
61
|
+
h *= delta;
|
|
62
|
+
if (Math.abs(delta - 1) < 1e-16)
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
return Math.exp(-z + a * Math.log(z) - (lnGammaPlusOne(a) - Math.log(a))) * h;
|
|
66
|
+
}
|
|
67
|
+
/** The `x` with `chiSquareCdf(x, df) = p`, p in (0, 1), by bisection. */
|
|
68
|
+
export function chiSquareQuantile(p, df) {
|
|
69
|
+
need(p > 0 && p < 1, { code: 'probabilityOutsideUnit', params: {} });
|
|
70
|
+
let hi = df + 10 * Math.sqrt(df) + 50;
|
|
71
|
+
while (chiSquareCdf(hi, df) < p)
|
|
72
|
+
hi *= 2;
|
|
73
|
+
return bisect((x) => chiSquareCdf(x, df) < p, [0, hi], 200, true);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=chi-square.js.map
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A typed diagnostic: a code and the values its message needs, empty when it needs none. */
|
|
2
|
+
export type Diagnostic<C extends string = string, P extends object = Record<string, never>> = {
|
|
3
|
+
code: C;
|
|
4
|
+
params: P;
|
|
5
|
+
};
|
|
6
|
+
/** An input outside the model, or a computation that does not finish within the limits its inputs set; a `RangeError`, other errors are defects; raised with a typed `issue` (its code is the message) and no wording, though a subclass with fields of its own (`TruingError`, `ValueError`) may pass a message. */
|
|
7
|
+
export declare class InputError extends RangeError {
|
|
8
|
+
/** The typed refusal; undefined for one raised with an English message. */
|
|
9
|
+
readonly issue: Diagnostic<string, object> | undefined;
|
|
10
|
+
constructor(refusal: string | Diagnostic<string, object>);
|
|
11
|
+
}
|
|
12
|
+
/** Throws an `InputError` with `refusal`, an English message or a typed issue, unless `ok`. */
|
|
13
|
+
export declare function need(ok: boolean, refusal: string | Diagnostic<string, object>): void;
|
|
14
|
+
/** For an index the caller's loop bounds or array sizes keep inside it; a missing entry is a defect in the caller and throws instead of passing `undefined` into arithmetic. */
|
|
15
|
+
export declare function nth<T>(a: ArrayLike<T>, i: number): T;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** An input outside the model, or a computation that does not finish within the limits its inputs set; a `RangeError`, other errors are defects; raised with a typed `issue` (its code is the message) and no wording, though a subclass with fields of its own (`TruingError`, `ValueError`) may pass a message. */
|
|
2
|
+
export class InputError extends RangeError {
|
|
3
|
+
/** The typed refusal; undefined for one raised with an English message. */
|
|
4
|
+
issue;
|
|
5
|
+
constructor(refusal) {
|
|
6
|
+
super(typeof refusal === 'string' ? refusal : refusal.code);
|
|
7
|
+
this.name = 'InputError';
|
|
8
|
+
this.issue = typeof refusal === 'string' ? undefined : refusal;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Throws an `InputError` with `refusal`, an English message or a typed issue, unless `ok`. */
|
|
12
|
+
export function need(ok, refusal) {
|
|
13
|
+
if (!ok)
|
|
14
|
+
throw new InputError(refusal);
|
|
15
|
+
}
|
|
16
|
+
/** For an index the caller's loop bounds or array sizes keep inside it; a missing entry is a defect in the caller and throws instead of passing `undefined` into arithmetic. */
|
|
17
|
+
export function nth(a, i) {
|
|
18
|
+
const v = a[i];
|
|
19
|
+
if (v === undefined)
|
|
20
|
+
throw new RangeError(`index ${i} outside an array of ${a.length}`);
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** With 2 and `m` degrees of freedom, in closed form: the distribution function is 1 - I_k(m/2, 1) with k = m / (m + 2x) (NIST/SEMATECH 1.3.6.6.5), and I_k(a, 1) = k^a (DLMF 8.17.1 and 8.17.2 at b = 1) (`apps/docs/docs/models/groups.md`, "Dispersion and prediction ellipses"). */
|
|
2
|
+
import { need } from './issue.js';
|
|
3
|
+
/** The `x` at which the distribution function of F(2, m) is `p`; p in (0, 1), m above 0. */
|
|
4
|
+
export function fQuantileTwoNumeratorDegrees(p, m) {
|
|
5
|
+
need(p > 0 && p < 1, { code: 'probabilityOutsideUnit', params: {} });
|
|
6
|
+
need(m > 0, { code: 'degreesOfFreedomNotPositive', params: {} });
|
|
7
|
+
// expm1 keeps precision for large m, where (1 - p)^(-2/m) is close to 1
|
|
8
|
+
return (m / 2) * Math.expm1((-2 / m) * Math.log1p(-p));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=f-distribution.js.map
|
package/dist/huber.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Huber loss for `logLeastSquares`, `apps/docs/docs/models/least-squares.md`, "Huber loss". */
|
|
2
|
+
/** Huber loss on the first `count` weighted residuals; the rest stay quadratic. */
|
|
3
|
+
export interface HuberLoss {
|
|
4
|
+
/** Residuals beyond this many sigmas count linearly. */
|
|
5
|
+
threshold: number;
|
|
6
|
+
/** Number of leading observations the loss applies to. */
|
|
7
|
+
count: number;
|
|
8
|
+
}
|
|
9
|
+
/** The cost: the Huber loss on the first `count` residuals, squares on the rest. */
|
|
10
|
+
export declare const huberCost: (r: number[], { threshold, count }: HuberLoss) => number;
|
|
11
|
+
/** Square roots of the reweighting weights: 1, or sqrt(k/|r|) beyond the threshold. */
|
|
12
|
+
export declare const huberRoots: (r: number[], huber: HuberLoss | undefined) => number[];
|
package/dist/huber.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Huber loss for `logLeastSquares`, `apps/docs/docs/models/least-squares.md`, "Huber loss". */
|
|
2
|
+
/** Huber loss of a weighted residual: r^2 up to `k`, then 2k|r| - k^2. */
|
|
3
|
+
const huberLoss = (r, k) => (Math.abs(r) <= k ? r * r : 2 * k * Math.abs(r) - k * k);
|
|
4
|
+
/** The cost: the Huber loss on the first `count` residuals, squares on the rest. */
|
|
5
|
+
export const huberCost = (r, { threshold, count }) => r.reduce((sum, x, i) => sum + (i < count ? huberLoss(x, threshold) : x * x), 0);
|
|
6
|
+
/** Square roots of the reweighting weights: 1, or sqrt(k/|r|) beyond the threshold. */
|
|
7
|
+
export const huberRoots = (r, huber) => r.map((x, i) => huber && i < huber.count && Math.abs(x) > huber.threshold
|
|
8
|
+
? Math.sqrt(huber.threshold / Math.abs(x))
|
|
9
|
+
: 1);
|
|
10
|
+
//# sourceMappingURL=huber.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { bisect } from './bisect.ts';
|
|
2
|
+
export { chiSquareCdf, chiSquareQuantile, chiSquareSurvival } from './chi-square.ts';
|
|
3
|
+
export { type Diagnostic, InputError, need, nth } from './errors.ts';
|
|
4
|
+
export { fQuantileTwoNumeratorDegrees } from './f-distribution.ts';
|
|
5
|
+
export type { HuberLoss } from './huber.ts';
|
|
6
|
+
export type { Interval } from './interval.ts';
|
|
7
|
+
export type { StatisticsIssue } from './issue.ts';
|
|
8
|
+
export { checkLogFitLimits, type Identifiability, identifiability, type LogFitFailure, type LogFitInput, type LogFitResult, type LogFitStop, logLeastSquares, } from './least-squares.ts';
|
|
9
|
+
export { percentile } from './percentile.ts';
|
|
10
|
+
export { normalsFrom, seededUniforms } from './random.ts';
|
|
11
|
+
export { studentTwoSidedQuantile } from './student-t.ts';
|
|
12
|
+
export { shotsNeeded, type VelocityStatistics, velocityStatistics } from './velocity-statistics.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { bisect } from './bisect.js';
|
|
2
|
+
export { chiSquareCdf, chiSquareQuantile, chiSquareSurvival } from './chi-square.js';
|
|
3
|
+
export { InputError, need, nth } from './errors.js';
|
|
4
|
+
export { fQuantileTwoNumeratorDegrees } from './f-distribution.js';
|
|
5
|
+
export { checkLogFitLimits, identifiability, logLeastSquares, } from './least-squares.js';
|
|
6
|
+
export { percentile } from './percentile.js';
|
|
7
|
+
export { normalsFrom, seededUniforms } from './random.js';
|
|
8
|
+
export { studentTwoSidedQuantile } from './student-t.js';
|
|
9
|
+
export { shotsNeeded, velocityStatistics } from './velocity-statistics.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/dist/interval.js
ADDED
package/dist/issue.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Diagnostic } from './errors.ts';
|
|
2
|
+
/** Why a function of this package refuses its input. */
|
|
3
|
+
export type StatisticsIssue = Diagnostic<'probabilityOutsideUnit'> | Diagnostic<'levelOutsideUnit'> | Diagnostic<'confidenceLevelOutsideUnit'> | Diagnostic<'degreesOfFreedomNotPositive'> | Diagnostic<'degreesOfFreedomNotPositiveWhole'> | Diagnostic<'maxIterationsNotPositiveInteger'> | Diagnostic<'maxConditionOutOfRange'> | Diagnostic<'velocitiesNotFinite'> | Diagnostic<'relativeHalfWidthBelowMinimum'> | Diagnostic<'relativeHalfWidthOutOfReach'>;
|
|
4
|
+
/** `need` with an issue of this package. */
|
|
5
|
+
export declare const need: (ok: boolean, issue: StatisticsIssue) => void;
|
package/dist/issue.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Weighted least squares on log parameters by Levenberg-Marquardt with central-difference Jacobians, a conditioning check and the parameter covariance (`apps/docs/docs/models/least-squares.md`). */
|
|
2
|
+
import { type HuberLoss } from './huber.ts';
|
|
3
|
+
/** Parameter uncertainty and collinearity measures of a weighted Jacobian. */
|
|
4
|
+
export interface Identifiability {
|
|
5
|
+
/** Standard errors of the parameters with all others free, per unit parameter; Infinity for a parameter in the null direction of a singular design. */
|
|
6
|
+
standardUncertainty: number[];
|
|
7
|
+
/** Standard errors with all other parameters known: 1 over the column norm. */
|
|
8
|
+
conditionalSigma: number[];
|
|
9
|
+
/** Correlation matrix of the parameters. */
|
|
10
|
+
correlation: number[][];
|
|
11
|
+
/** Variance inflation factors: `standardUncertainty` squared over `conditionalSigma` squared; Infinity where `standardUncertainty` is. */
|
|
12
|
+
varianceInflation: number[];
|
|
13
|
+
/** Condition number of the column-scaled information, as in the fit; Infinity when singular. */
|
|
14
|
+
conditionNumber: number;
|
|
15
|
+
/** Eigenvector of the smallest eigenvalue of the column-scaled information. */
|
|
16
|
+
direction: number[];
|
|
17
|
+
}
|
|
18
|
+
/** From a weighted Jacobian (rows observations, columns parameters, none zero; `apps/docs/docs/models/least-squares.md`, "Identifiability of a weighted Jacobian"): singular when the smallest eigenvalue of the column-scaled information is at most 1e-12 of the largest; eigenvalues floored there keep the correlations finite, and a parameter whose null-direction share would raise its variance inflation above 1 gets Infinity for `standardUncertainty` and `varianceInflation`, the condition number Infinity. */
|
|
19
|
+
export declare function identifiability(j: number[][]): Identifiability;
|
|
20
|
+
/** Why a fit cannot continue; passed to `LogFitInput.fail`. */
|
|
21
|
+
export type LogFitFailure = 'unresolved' | 'ill-conditioned' | 'unreachable' | 'not-converged';
|
|
22
|
+
/** `stalled`: an accepted step whose cost fell by less than the tolerance (or to 0), or a rejected step that raised it by at most the tolerance where the linear model predicted a decrease within it too; `smallStep`: a step below 1e-8 in every log parameter. */
|
|
23
|
+
export type LogFitStop = 'stalled' | 'smallStep';
|
|
24
|
+
/** Inputs of `logLeastSquares`. */
|
|
25
|
+
export interface LogFitInput {
|
|
26
|
+
/** Parameter count. */
|
|
27
|
+
parameterCount: number;
|
|
28
|
+
/** Observed values. */
|
|
29
|
+
observed: readonly number[];
|
|
30
|
+
/** Standard deviation of each observation, in the unit of `observed`; 1 where unweighted. */
|
|
31
|
+
standardUncertainty: readonly number[];
|
|
32
|
+
/** Whether every observation has its own standard uncertainty; otherwise the covariance is scaled. */
|
|
33
|
+
weighted: boolean;
|
|
34
|
+
/** Per observation: weighted Jacobian entries below it are noise, per unit log parameter. */
|
|
35
|
+
floor: readonly number[];
|
|
36
|
+
/** Predicted values at theta = 0, from the caller's own first evaluation. */
|
|
37
|
+
first: readonly number[];
|
|
38
|
+
/** Null for a rejected candidate, `current` the accepted iterate; with `run` only that run's values, otherwise all runs stacked. */
|
|
39
|
+
predict: (trial: number[], current: number[], run?: number) => readonly number[] | null;
|
|
40
|
+
/** Observation count of each run in stacking order; one run of all observations when absent. */
|
|
41
|
+
runs?: readonly number[];
|
|
42
|
+
/** Whether parameter `j` moves run `run`'s predictions; its Jacobian entries elsewhere are 0. */
|
|
43
|
+
moves?: (j: number, run: number) => boolean;
|
|
44
|
+
/** On the first `count` observations (the rest stay quadratic): residuals beyond `threshold` sigmas count linearly; needs `weighted` (`apps/docs/docs/models/least-squares.md`, "Huber loss"). */
|
|
45
|
+
huber?: HuberLoss;
|
|
46
|
+
/** Iterations before the fit fails with `'not-converged'`. */
|
|
47
|
+
maxIterations: number;
|
|
48
|
+
/** Largest condition number of the column-scaled Jacobian before `'ill-conditioned'`. */
|
|
49
|
+
maxCondition: number;
|
|
50
|
+
/** Relative decrease of the cost below which an accepted step ends the fit; default 1e-12. */
|
|
51
|
+
tolerance?: number;
|
|
52
|
+
/** Throws the caller's error for a failure at log parameters `theta`. */
|
|
53
|
+
fail: (reason: LogFitFailure, theta: number[], extra?: {
|
|
54
|
+
conditionNumber?: number;
|
|
55
|
+
unresolved?: number[];
|
|
56
|
+
direction?: number[];
|
|
57
|
+
}) => never;
|
|
58
|
+
}
|
|
59
|
+
/** Throws an `InputError` unless `maxIterations` is a positive integer and `maxCondition` is finite and at least 1, the condition number of a one-parameter fit; for callers that refuse their options before any run. */
|
|
60
|
+
export declare function checkLogFitLimits(maxIterations: number, maxCondition: number): void;
|
|
61
|
+
/** Solution of `logLeastSquares`. */
|
|
62
|
+
export interface LogFitResult {
|
|
63
|
+
/** Log parameters at the solution. */
|
|
64
|
+
theta: number[];
|
|
65
|
+
/** Sum of squared weighted residuals at the solution, whatever the loss. */
|
|
66
|
+
chiSquare: number;
|
|
67
|
+
/** The minimized cost: `chiSquare`, or with `huber` the sum of the Huber losses. */
|
|
68
|
+
loss: number;
|
|
69
|
+
/** Predicted values at the solution: the last accepted candidate's, or `first` without one. */
|
|
70
|
+
predicted: readonly number[];
|
|
71
|
+
/** Condition number of the column-scaled Jacobian at the solution. */
|
|
72
|
+
conditionNumber: number;
|
|
73
|
+
/** Iterations taken. */
|
|
74
|
+
iterations: number;
|
|
75
|
+
/** The rule that ended the loop. */
|
|
76
|
+
stop: LogFitStop;
|
|
77
|
+
/** Whether the down-weighted rows (residual beyond the Huber threshold) stayed the same over the last accepted step; true without `huber` and without an accepted step. */
|
|
78
|
+
weightsSettled: boolean;
|
|
79
|
+
/** Covariance of theta; absent with n = p and no standard uncertainties. */
|
|
80
|
+
covariance?: number[][];
|
|
81
|
+
/** Square roots of the covariance diagonal of theta; absent like `covariance`. */
|
|
82
|
+
standardUncertainty?: number[];
|
|
83
|
+
/** Correlation matrix of theta; absent like `standardUncertainty`. */
|
|
84
|
+
correlation?: number[][];
|
|
85
|
+
}
|
|
86
|
+
/** Levenberg-Marquardt on the log parameters, starting at theta = 0 (`apps/docs/docs/models/least-squares.md`, "Levenberg-Marquardt step"). */
|
|
87
|
+
export declare function logLeastSquares(fit: LogFitInput): LogFitResult;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/** Weighted least squares on log parameters by Levenberg-Marquardt with central-difference Jacobians, a conditioning check and the parameter covariance (`apps/docs/docs/models/least-squares.md`). */
|
|
2
|
+
import { nth } from './errors.js';
|
|
3
|
+
import { huberCost, huberRoots } from './huber.js';
|
|
4
|
+
import { need } from './issue.js';
|
|
5
|
+
/** Whether the off-diagonal part of `m` is negligible against its diagonal. */
|
|
6
|
+
function isDiagonal(m) {
|
|
7
|
+
const n = m.length;
|
|
8
|
+
let off = 0;
|
|
9
|
+
let diag = 0;
|
|
10
|
+
for (let i = 0; i < n; i++) {
|
|
11
|
+
const row = nth(m, i);
|
|
12
|
+
diag += nth(row, i) ** 2;
|
|
13
|
+
for (let j = i + 1; j < n; j++)
|
|
14
|
+
off += nth(row, j) ** 2;
|
|
15
|
+
}
|
|
16
|
+
return off <= 1e-32 * diag;
|
|
17
|
+
}
|
|
18
|
+
/** One Jacobi rotation of `m` that zeroes entry (p, q), accumulated into the vectors `v`. */
|
|
19
|
+
function rotate(m, v, p, q) {
|
|
20
|
+
const n = m.length;
|
|
21
|
+
const mp = nth(m, p);
|
|
22
|
+
const mq = nth(m, q);
|
|
23
|
+
const theta = (nth(mq, q) - nth(mp, p)) / (2 * nth(mp, q));
|
|
24
|
+
const t = (theta < 0 ? -1 : 1) / (Math.abs(theta) + Math.sqrt(theta * theta + 1));
|
|
25
|
+
const c = 1 / Math.sqrt(t * t + 1);
|
|
26
|
+
const s = t * c;
|
|
27
|
+
for (const mk of m) {
|
|
28
|
+
const kp = nth(mk, p);
|
|
29
|
+
const kq = nth(mk, q);
|
|
30
|
+
mk[p] = c * kp - s * kq;
|
|
31
|
+
mk[q] = s * kp + c * kq;
|
|
32
|
+
}
|
|
33
|
+
for (let k = 0; k < n; k++) {
|
|
34
|
+
const pk = nth(mp, k);
|
|
35
|
+
const qk = nth(mq, k);
|
|
36
|
+
mp[k] = c * pk - s * qk;
|
|
37
|
+
mq[k] = s * pk + c * qk;
|
|
38
|
+
}
|
|
39
|
+
for (const vk of v) {
|
|
40
|
+
const kp = nth(vk, p);
|
|
41
|
+
const kq = nth(vk, q);
|
|
42
|
+
vk[p] = c * kp - s * kq;
|
|
43
|
+
vk[q] = s * kp + c * kq;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** One cyclic Jacobi sweep: a rotation for each nonzero entry above the diagonal of `m`. */
|
|
47
|
+
function jacobiSweep(m, v) {
|
|
48
|
+
const n = m.length;
|
|
49
|
+
for (let p = 0; p < n - 1; p++)
|
|
50
|
+
for (let q = p + 1; q < n; q++)
|
|
51
|
+
if (nth(nth(m, p), q) !== 0)
|
|
52
|
+
rotate(m, v, p, q);
|
|
53
|
+
}
|
|
54
|
+
/** Cyclic Jacobi eigen decomposition of a symmetric matrix; vectors[i][k]: entry i of vector k. */
|
|
55
|
+
function eigen(a) {
|
|
56
|
+
const m = a.map((r) => [...r]);
|
|
57
|
+
const v = a.map((row, i) => row.map((_x, j) => (i === j ? 1 : 0)));
|
|
58
|
+
for (let sweep = 0; sweep < 100; sweep++) {
|
|
59
|
+
if (isDiagonal(m))
|
|
60
|
+
break;
|
|
61
|
+
jacobiSweep(m, v);
|
|
62
|
+
}
|
|
63
|
+
return { values: m.map((r, i) => nth(r, i)), vectors: v };
|
|
64
|
+
}
|
|
65
|
+
/** Inverse of a symmetric positive definite matrix through its eigen decomposition. */
|
|
66
|
+
function inverse(a) {
|
|
67
|
+
const { values, vectors } = eigen(a);
|
|
68
|
+
return vectors.map((vi) => vectors.map((vj) => values.reduce((sum, l, k) => sum + (nth(vi, k) * nth(vj, k)) / l, 0)));
|
|
69
|
+
}
|
|
70
|
+
const transposeTimes = (j, b) => nth(j, 0).map((_row, r) => nth(b, 0).map((_column, c) => j.reduce((s, row, i) => s + nth(row, r) * nth(nth(b, i), c), 0)));
|
|
71
|
+
/** From a weighted Jacobian (rows observations, columns parameters, none zero; `apps/docs/docs/models/least-squares.md`, "Identifiability of a weighted Jacobian"): singular when the smallest eigenvalue of the column-scaled information is at most 1e-12 of the largest; eigenvalues floored there keep the correlations finite, and a parameter whose null-direction share would raise its variance inflation above 1 gets Infinity for `standardUncertainty` and `varianceInflation`, the condition number Infinity. */
|
|
72
|
+
export function identifiability(j) {
|
|
73
|
+
const f = transposeTimes(j, j);
|
|
74
|
+
const d = f.map((row, i) => Math.sqrt(nth(row, i)));
|
|
75
|
+
const r = f.map((row, i) => row.map((x, k) => x / (nth(d, i) * nth(d, k))));
|
|
76
|
+
const { values, vectors } = eigen(r);
|
|
77
|
+
const top = Math.max(...values);
|
|
78
|
+
// NaN eigenvalues make this -1: reads at it are NaN, as the fit treats them
|
|
79
|
+
const lo = values.indexOf(Math.min(...values));
|
|
80
|
+
const floor = 1e-12 * top;
|
|
81
|
+
const singular = (values[lo] ?? Number.NaN) <= floor;
|
|
82
|
+
const lambda = values.map((l) => Math.max(l, floor));
|
|
83
|
+
const inv = r.map((_row, a) => r.map((_column, b) => lambda.reduce((s, l, k) => s + (nth(nth(vectors, a), k) * nth(nth(vectors, b), k)) / l, 0)));
|
|
84
|
+
const unbounded = (a) => singular && (nth(vectors, a)[lo] ?? Number.NaN) ** 2 > floor;
|
|
85
|
+
return {
|
|
86
|
+
standardUncertainty: inv.map((row, a) => unbounded(a) ? Infinity : Math.sqrt(nth(row, a)) / nth(d, a)),
|
|
87
|
+
conditionalSigma: d.map((x) => 1 / x),
|
|
88
|
+
correlation: inv.map((row, a) => row.map((x, b) => x / Math.sqrt(nth(nth(inv, a), a) * nth(nth(inv, b), b)))),
|
|
89
|
+
varianceInflation: inv.map((row, a) => (unbounded(a) ? Infinity : nth(row, a))),
|
|
90
|
+
conditionNumber: singular ? Infinity : Math.sqrt(top / (values[lo] ?? Number.NaN)),
|
|
91
|
+
direction: vectors.map((row) => row[lo] ?? Number.NaN),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Throws an `InputError` unless `maxIterations` is a positive integer and `maxCondition` is finite and at least 1, the condition number of a one-parameter fit; for callers that refuse their options before any run. */
|
|
95
|
+
export function checkLogFitLimits(maxIterations, maxCondition) {
|
|
96
|
+
need(Number.isInteger(maxIterations) && maxIterations > 0, {
|
|
97
|
+
code: 'maxIterationsNotPositiveInteger',
|
|
98
|
+
params: {},
|
|
99
|
+
});
|
|
100
|
+
need(Number.isFinite(maxCondition) && maxCondition >= 1, {
|
|
101
|
+
code: 'maxConditionOutOfRange',
|
|
102
|
+
params: {},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const lambda0 = 1e-3;
|
|
106
|
+
/** Central-difference step in the log parameters. */
|
|
107
|
+
const step = 1e-3;
|
|
108
|
+
/** Weighted Jacobian at the log parameters `at` by central differences; rows: observations. */
|
|
109
|
+
function jacobian(fit, stacking, at) {
|
|
110
|
+
const { observed, standardUncertainty: sigma, predict, fail } = fit;
|
|
111
|
+
const { runs, start, moves } = stacking;
|
|
112
|
+
const columns = at.map((_, j) => {
|
|
113
|
+
const up = at.map((x, k) => (k === j ? x + step : x));
|
|
114
|
+
const down = at.map((x, k) => (k === j ? x - step : x));
|
|
115
|
+
return runs.flatMap((count, run) => {
|
|
116
|
+
if (!moves(j, run))
|
|
117
|
+
return Array.from({ length: count }, () => 0);
|
|
118
|
+
const a = predict(up, at, run);
|
|
119
|
+
const b = predict(down, at, run);
|
|
120
|
+
if (!a || !b)
|
|
121
|
+
return fail('unreachable', at);
|
|
122
|
+
return a.map((v, i) => (v - nth(b, i)) / (2 * step * nth(sigma, nth(start, run) + i)));
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return observed.map((_, i) => columns.map((c) => nth(c, i)));
|
|
126
|
+
}
|
|
127
|
+
/** Unresolved columns and the condition number of the column-scaled normal matrix (`apps/docs/docs/models/least-squares.md`, "Conditioning check"); calls `fit.fail` on either finding, else returns the condition number. */
|
|
128
|
+
function checkConditioning(fit, j, at) {
|
|
129
|
+
const { floor, maxCondition, fail } = fit;
|
|
130
|
+
const norms = at.map((_, k) => Math.hypot(...j.map((row) => nth(row, k))));
|
|
131
|
+
const largest = Math.max(...norms);
|
|
132
|
+
const unresolved = norms.flatMap((d, k) => d === 0 || d < 1e-9 * largest || j.every((row, i) => Math.abs(nth(row, k)) < nth(floor, i))
|
|
133
|
+
? [k]
|
|
134
|
+
: []);
|
|
135
|
+
if (unresolved.length > 0)
|
|
136
|
+
fail('unresolved', at, { unresolved });
|
|
137
|
+
const scaled = j.map((row) => row.map((x, k) => x / nth(norms, k)));
|
|
138
|
+
const { values, vectors } = eigen(transposeTimes(scaled, scaled));
|
|
139
|
+
// NaN eigenvalues make this -1: reads at it are NaN, as the fit treats them
|
|
140
|
+
const lo = values.indexOf(Math.min(...values));
|
|
141
|
+
const smallest = values[lo] ?? Number.NaN;
|
|
142
|
+
const condition = smallest > 0 ? Math.sqrt(Math.max(...values) / smallest) : Infinity;
|
|
143
|
+
if (!(condition <= maxCondition))
|
|
144
|
+
fail('ill-conditioned', at, {
|
|
145
|
+
conditionNumber: condition,
|
|
146
|
+
direction: vectors.map((row) => row[lo] ?? Number.NaN),
|
|
147
|
+
});
|
|
148
|
+
return condition;
|
|
149
|
+
}
|
|
150
|
+
/** Covariance of the log parameters from the Jacobian at the solution, times `scale`. */
|
|
151
|
+
function parameterCovariance(j, scale) {
|
|
152
|
+
return inverse(transposeTimes(j, j)).map((row) => row.map((x) => x * scale));
|
|
153
|
+
}
|
|
154
|
+
const scaled = (m, w) => m.map((row, i) => row.map((x) => x * nth(w, i)));
|
|
155
|
+
/** The Levenberg-Marquardt step from the weighted Jacobian `jw` and weighted residuals `rw`, damped by `lambda`. */
|
|
156
|
+
function levenbergMarquardtStep(jw, rw, lambda) {
|
|
157
|
+
const a = transposeTimes(jw, jw);
|
|
158
|
+
const g = transposeTimes(jw, rw.map((x) => [x])).map((row) => nth(row, 0));
|
|
159
|
+
const damped = a.map((row, k) => row.map((x, l) => (k === l ? x * (1 + lambda) : x)));
|
|
160
|
+
const inv = inverse(damped);
|
|
161
|
+
return inv.map((row) => -row.reduce((s, x, l) => s + x * nth(g, l), 0));
|
|
162
|
+
}
|
|
163
|
+
/** The covariance of a fit with its standard errors and correlations. */
|
|
164
|
+
function covarianceSummary(covariance) {
|
|
165
|
+
return {
|
|
166
|
+
covariance,
|
|
167
|
+
standardUncertainty: covariance.map((row, k) => Math.sqrt(nth(row, k))),
|
|
168
|
+
correlation: covariance.map((row, k) => row.map((x, l) => x / Math.sqrt(nth(nth(covariance, k), k) * nth(nth(covariance, l), l)))),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** Fails with `not-converged` once `iterations` reaches the limit. */
|
|
172
|
+
function checkIterations(fit, iterations, j, theta) {
|
|
173
|
+
if (iterations < fit.maxIterations)
|
|
174
|
+
return;
|
|
175
|
+
// a parameter that ran to where it has no effect is unresolved, not slow
|
|
176
|
+
checkConditioning(fit, j, theta);
|
|
177
|
+
fit.fail('not-converged', theta);
|
|
178
|
+
}
|
|
179
|
+
/** Whether an accepted step from cost `cost` to `next` is too small to continue. */
|
|
180
|
+
const stalled = (cost, next, tolerance) => (cost - next) / cost < tolerance || next === 0;
|
|
181
|
+
/** The covariance, standard errors and correlations at the solution; none without residual degrees of freedom. */
|
|
182
|
+
function covarianceOf(fit, jw, cost, dof) {
|
|
183
|
+
if (!(fit.weighted || dof > 0))
|
|
184
|
+
return {};
|
|
185
|
+
return covarianceSummary(parameterCovariance(jw, fit.weighted ? 1 : cost / dof));
|
|
186
|
+
}
|
|
187
|
+
/** The chi-square of weighted residuals: the sum of their squares. */
|
|
188
|
+
const chiSquareOf = (r) => r.reduce((s, x) => s + x * x, 0);
|
|
189
|
+
function modelOf(fit) {
|
|
190
|
+
const { observed, standardUncertainty: sigma, huber } = fit;
|
|
191
|
+
const { runs = [observed.length], moves = () => true } = fit;
|
|
192
|
+
const start = runs.map((_count, k) => runs.slice(0, k).reduce((t, c) => t + c, 0));
|
|
193
|
+
return {
|
|
194
|
+
fit,
|
|
195
|
+
stacking: { runs, start, moves },
|
|
196
|
+
residuals: (values) => values.map((v, i) => (v - nth(observed, i)) / nth(sigma, i)),
|
|
197
|
+
cost: (r) => (huber ? huberCost(r, huber) : chiSquareOf(r)),
|
|
198
|
+
roots: (r) => huberRoots(r, huber),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** The start at theta = 0, after the conditioning check of its Jacobian. */
|
|
202
|
+
function startState(m) {
|
|
203
|
+
const theta = Array.from({ length: m.fit.parameterCount }, () => 0);
|
|
204
|
+
const r = m.residuals(m.fit.first);
|
|
205
|
+
const cost = m.cost(r);
|
|
206
|
+
const j = jacobian(m.fit, m.stacking, theta);
|
|
207
|
+
checkConditioning(m.fit, j, theta);
|
|
208
|
+
const iteration = { current: true, lambda: lambda0, iterations: 0, weightsSettled: true };
|
|
209
|
+
return { theta, predicted: m.fit.first, r, cost, j, ...iteration };
|
|
210
|
+
}
|
|
211
|
+
/** Whether the Huber loss treats the same rows as outliers in `a` and `b`. */
|
|
212
|
+
function sameRows(m, a, b) {
|
|
213
|
+
const wb = m.roots(b);
|
|
214
|
+
return m.roots(a).every((w, i) => w < 1 === nth(wb, i) < 1);
|
|
215
|
+
}
|
|
216
|
+
/** Moves to the `accepted` parameters, prediction and cost and lowers the damping; `stalled` when the cost fell by less than `tolerance` of itself, else the Jacobian there. */
|
|
217
|
+
function acceptStep(m, s, accepted, tolerance) {
|
|
218
|
+
const before = s.r;
|
|
219
|
+
s.theta = accepted.theta;
|
|
220
|
+
s.predicted = accepted.predicted;
|
|
221
|
+
s.r = m.residuals(accepted.predicted);
|
|
222
|
+
s.weightsSettled = sameRows(m, before, s.r);
|
|
223
|
+
s.lambda /= 10;
|
|
224
|
+
s.current = false;
|
|
225
|
+
const done = stalled(s.cost, accepted.cost, tolerance);
|
|
226
|
+
s.cost = accepted.cost;
|
|
227
|
+
if (done)
|
|
228
|
+
return 'stalled';
|
|
229
|
+
s.j = jacobian(m.fit, m.stacking, s.theta);
|
|
230
|
+
s.current = true;
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
/** The decrease of `rw`'s sum of squares that the linear model predicts for the step `delta` damped by `lambda`, relative to that sum: MINPACK's `prered`, `|Jw delta|^2 + 2 lambda delta' diag(Jw'Jw) delta`, free of the cancellation of a difference of sums. */
|
|
234
|
+
function predictedDecrease(jw, rw, delta, lambda) {
|
|
235
|
+
const along = jw.reduce((t, row) => t + row.reduce((u, x, k) => u + x * nth(delta, k), 0) ** 2, 0);
|
|
236
|
+
const damped = delta.reduce((t, d, k) => t + jw.reduce((u, row) => u + nth(row, k) ** 2, 0) * d * d, 0);
|
|
237
|
+
return (along + 2 * lambda * damped) / chiSquareOf(rw);
|
|
238
|
+
}
|
|
239
|
+
/** One Levenberg-Marquardt iteration: a step that lowers the cost is taken, else the damping grows. */
|
|
240
|
+
function iterate(m, s, tolerance) {
|
|
241
|
+
checkIterations(m.fit, s.iterations, s.j, s.theta);
|
|
242
|
+
s.iterations++;
|
|
243
|
+
const w = m.roots(s.r);
|
|
244
|
+
const jw = scaled(s.j, w);
|
|
245
|
+
const rw = s.r.map((x, i) => x * nth(w, i));
|
|
246
|
+
const delta = levenbergMarquardtStep(jw, rw, s.lambda);
|
|
247
|
+
const small = Math.max(...delta.map(Math.abs)) < 1e-8;
|
|
248
|
+
const candidate = s.theta.map((x, k) => x + nth(delta, k));
|
|
249
|
+
const p = small ? null : m.fit.predict(candidate, s.theta);
|
|
250
|
+
const next = p ? m.cost(m.residuals(p)) : Infinity;
|
|
251
|
+
if (p && next < s.cost)
|
|
252
|
+
return acceptStep(m, s, { theta: candidate, predicted: p, cost: next }, tolerance);
|
|
253
|
+
if (small)
|
|
254
|
+
return 'smallStep';
|
|
255
|
+
// MINPACK lmder's info = 1 on a rejected step: a predicted decrease checked too, so a step into a flat region far from the minimum goes on
|
|
256
|
+
if (p &&
|
|
257
|
+
(next - s.cost) / s.cost <= tolerance &&
|
|
258
|
+
predictedDecrease(jw, rw, delta, s.lambda) <= tolerance)
|
|
259
|
+
return 'stalled';
|
|
260
|
+
s.lambda *= 10;
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
/** Levenberg-Marquardt on the log parameters, starting at theta = 0 (`apps/docs/docs/models/least-squares.md`, "Levenberg-Marquardt step"). */
|
|
264
|
+
export function logLeastSquares(fit) {
|
|
265
|
+
checkLogFitLimits(fit.maxIterations, fit.maxCondition);
|
|
266
|
+
const m = modelOf(fit);
|
|
267
|
+
const s = startState(m);
|
|
268
|
+
const tolerance = fit.tolerance ?? 1e-12;
|
|
269
|
+
let stop;
|
|
270
|
+
while (stop === undefined)
|
|
271
|
+
stop = iterate(m, s, tolerance);
|
|
272
|
+
if (!s.current)
|
|
273
|
+
s.j = jacobian(fit, m.stacking, s.theta);
|
|
274
|
+
const condition = checkConditioning(fit, s.j, s.theta);
|
|
275
|
+
return {
|
|
276
|
+
theta: s.theta,
|
|
277
|
+
chiSquare: chiSquareOf(s.r),
|
|
278
|
+
loss: s.cost,
|
|
279
|
+
predicted: s.predicted,
|
|
280
|
+
conditionNumber: condition,
|
|
281
|
+
iterations: s.iterations,
|
|
282
|
+
stop,
|
|
283
|
+
weightsSettled: s.weightsSettled,
|
|
284
|
+
...covarianceOf(fit, scaled(s.j, m.roots(s.r)), s.cost, fit.observed.length - fit.parameterCount),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=least-squares.js.map
|