@ac-kit/math-analysis 0.2.0 → 0.3.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +85 -2
  3. package/dist/differentiation/finite-difference.d.ts +41 -0
  4. package/dist/differentiation/finite-difference.d.ts.map +1 -0
  5. package/dist/differentiation/finite-difference.js +53 -0
  6. package/dist/differentiation/finite-difference.js.map +1 -0
  7. package/dist/differentiation/gradient.d.ts +73 -0
  8. package/dist/differentiation/gradient.d.ts.map +1 -0
  9. package/dist/differentiation/gradient.js +167 -0
  10. package/dist/differentiation/gradient.js.map +1 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +16 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/interpolation/barycentric-interpolator.d.ts +29 -0
  16. package/dist/interpolation/barycentric-interpolator.d.ts.map +1 -0
  17. package/dist/interpolation/barycentric-interpolator.js +94 -0
  18. package/dist/interpolation/barycentric-interpolator.js.map +1 -0
  19. package/dist/legendre/_legendre-kernel.d.ts +22 -0
  20. package/dist/legendre/_legendre-kernel.d.ts.map +1 -0
  21. package/dist/legendre/_legendre-kernel.js +232 -0
  22. package/dist/legendre/_legendre-kernel.js.map +1 -0
  23. package/dist/legendre/legendre-fully-normalized.d.ts +52 -0
  24. package/dist/legendre/legendre-fully-normalized.d.ts.map +1 -0
  25. package/dist/legendre/legendre-fully-normalized.js +62 -0
  26. package/dist/legendre/legendre-fully-normalized.js.map +1 -0
  27. package/dist/legendre/legendre-index.d.ts +27 -0
  28. package/dist/legendre/legendre-index.d.ts.map +1 -0
  29. package/dist/legendre/legendre-index.js +31 -0
  30. package/dist/legendre/legendre-index.js.map +1 -0
  31. package/dist/legendre/legendre-schmidt.d.ts +37 -0
  32. package/dist/legendre/legendre-schmidt.d.ts.map +1 -0
  33. package/dist/legendre/legendre-schmidt.js +47 -0
  34. package/dist/legendre/legendre-schmidt.js.map +1 -0
  35. package/dist/ode/runge-kutta4.d.ts +46 -0
  36. package/dist/ode/runge-kutta4.d.ts.map +1 -0
  37. package/dist/ode/runge-kutta4.js +85 -0
  38. package/dist/ode/runge-kutta4.js.map +1 -0
  39. package/dist/optimize/_more-thuente.d.ts +95 -0
  40. package/dist/optimize/_more-thuente.d.ts.map +1 -0
  41. package/dist/optimize/_more-thuente.js +333 -0
  42. package/dist/optimize/_more-thuente.js.map +1 -0
  43. package/dist/optimize/_wolfe-line-search.d.ts +85 -0
  44. package/dist/optimize/_wolfe-line-search.d.ts.map +1 -0
  45. package/dist/optimize/_wolfe-line-search.js +193 -0
  46. package/dist/optimize/_wolfe-line-search.js.map +1 -0
  47. package/dist/optimize/bfgs.d.ts +262 -0
  48. package/dist/optimize/bfgs.d.ts.map +1 -0
  49. package/dist/optimize/bfgs.js +418 -0
  50. package/dist/optimize/bfgs.js.map +1 -0
  51. package/dist/optimize/lbfgs.d.ts +199 -0
  52. package/dist/optimize/lbfgs.d.ts.map +1 -0
  53. package/dist/optimize/lbfgs.js +383 -0
  54. package/dist/optimize/lbfgs.js.map +1 -0
  55. package/dist/optimize/levenberg-marquardt.d.ts +78 -0
  56. package/dist/optimize/levenberg-marquardt.d.ts.map +1 -0
  57. package/dist/optimize/levenberg-marquardt.js +204 -0
  58. package/dist/optimize/levenberg-marquardt.js.map +1 -0
  59. package/dist/optimize/nelder-mead.d.ts +68 -0
  60. package/dist/optimize/nelder-mead.d.ts.map +1 -0
  61. package/dist/optimize/nelder-mead.js +198 -0
  62. package/dist/optimize/nelder-mead.js.map +1 -0
  63. package/dist/quadrature/adaptive-quadrature.d.ts +53 -0
  64. package/dist/quadrature/adaptive-quadrature.d.ts.map +1 -0
  65. package/dist/quadrature/adaptive-quadrature.js +175 -0
  66. package/dist/quadrature/adaptive-quadrature.js.map +1 -0
  67. package/dist/quadrature/gauss-legendre.d.ts +27 -0
  68. package/dist/quadrature/gauss-legendre.d.ts.map +1 -0
  69. package/dist/quadrature/gauss-legendre.js +111 -0
  70. package/dist/quadrature/gauss-legendre.js.map +1 -0
  71. package/dist/quadrature/simpsons-rule.d.ts +27 -0
  72. package/dist/quadrature/simpsons-rule.d.ts.map +1 -0
  73. package/dist/quadrature/simpsons-rule.js +44 -0
  74. package/dist/quadrature/simpsons-rule.js.map +1 -0
  75. package/dist/roots/_grown.d.ts.map +1 -1
  76. package/dist/roots/_grown.js +0 -1
  77. package/dist/roots/_grown.js.map +1 -1
  78. package/dist/roots/_level-search.d.ts +19 -2
  79. package/dist/roots/_level-search.d.ts.map +1 -1
  80. package/dist/roots/_level-search.js +47 -23
  81. package/dist/roots/_level-search.js.map +1 -1
  82. package/dist/roots/find-level-bands.js +1 -1
  83. package/dist/roots/find-level-bands.js.map +1 -1
  84. package/dist/roots/find-level-crossings.d.ts +4 -2
  85. package/dist/roots/find-level-crossings.d.ts.map +1 -1
  86. package/dist/roots/find-level-crossings.js +4 -10
  87. package/dist/roots/find-level-crossings.js.map +1 -1
  88. package/dist/roots/newton-raphson.d.ts +31 -0
  89. package/dist/roots/newton-raphson.d.ts.map +1 -0
  90. package/dist/roots/newton-raphson.js +69 -0
  91. package/dist/roots/newton-raphson.js.map +1 -0
  92. package/dist/series/sum-series.d.ts +43 -0
  93. package/dist/series/sum-series.d.ts.map +1 -0
  94. package/dist/series/sum-series.js +70 -0
  95. package/dist/series/sum-series.js.map +1 -0
  96. package/package.json +8 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legendre-schmidt.d.ts","sourceRoot":"","sources":["../../src/legendre/legendre-schmidt.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,cAAc,CAAC,EAAE,YAAY,GAC3B,YAAY,CAcd"}
@@ -0,0 +1,47 @@
1
+ import { LEGENDRE_COLATITUDE_, legendreCheck_, legendreFillNaN_, legendreKernel_, } from "./_legendre-kernel.js";
2
+ /**
3
+ * Writes the Schmidt semi-normalised associated Legendre functions `Pₙᵐ(cos θ)`
4
+ * of every degree `n ≤ maxDegree` and order `0 ≤ m ≤ n` into `out`, in the
5
+ * order of {@link legendreIndex}, and their derivatives `dPₙᵐ/dθ` with respect
6
+ * to the colatitude `θ` into `derivativesOut` when given. Returns `out`.
7
+ *
8
+ * The normalisation of geomagnetism (the World Magnetic Model, the IGRF): `Pₙᵐ
9
+ * = √((2 − δₘ₀)(n − m)! / (n + m)!) Pₙₘ`, so that `Σₘ (Pₙᵐ)² = 1` for every
10
+ * degree, without the Condon–Shortley phase `(−1)ᵐ`. It is
11
+ * {@link legendreFullyNormalized}'s divided by `√(2n + 1)`, and shares its
12
+ * recursion, so it is as stable: to degree 2190 and beyond (2700) at every
13
+ * colatitude, and with derivatives exact at the poles.
14
+ *
15
+ * O(maxDegree²) time; O(maxDegree) memory for a table of integer square roots
16
+ * kept between calls. Nothing is allocated once that table is large enough.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const values = new Float64Array(legendreTableLength(12));
21
+ * const derivatives = new Float64Array(legendreTableLength(12));
22
+ * legendreSchmidt(values, 12, Math.PI / 3, derivatives);
23
+ * values[legendreIndex(1, 1)]; // sin θ = 0.8660254037844386
24
+ * derivatives[legendreIndex(1, 0)]; // −sin θ
25
+ * ```;
26
+ *
27
+ * @param out Receives the values; entries past {@link legendreTableLength}
28
+ * `(maxDegree)` are left alone.
29
+ * @param maxDegree The highest degree, a non-negative integer.
30
+ * @param colatitude `θ`, radians in `[0, π]`; `NaN` fills both tables with
31
+ * `NaN`.
32
+ * @param derivativesOut Receives `dPₙᵐ/dθ`; must not overlap `out`.
33
+ * @throws {RangeError} When `maxDegree` is not a non-negative integer, a table
34
+ * is too short for it, the tables overlap or `colatitude` is outside `[0,
35
+ * π]`; nothing is written.
36
+ */
37
+ export function legendreSchmidt(out, maxDegree, colatitude, derivativesOut) {
38
+ LEGENDRE_COLATITUDE_[0] = colatitude;
39
+ const length = legendreCheck_("legendreSchmidt", out, derivativesOut, maxDegree);
40
+ if (colatitude !== colatitude) {
41
+ legendreFillNaN_(out, derivativesOut, length);
42
+ return out;
43
+ }
44
+ legendreKernel_(out, derivativesOut, maxDegree, true);
45
+ return out;
46
+ }
47
+ //# sourceMappingURL=legendre-schmidt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legendre-schmidt.js","sourceRoot":"","sources":["../../src/legendre/legendre-schmidt.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,eAAe,GACf,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,eAAe,CAC9B,GAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,cAA6B;IAE7B,oBAAoB,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC;IACrC,MAAM,MAAM,GAAG,cAAc,CAC5B,iBAAiB,EACjB,GAAG,EACH,cAAc,EACd,SAAS,CACT,CAAC;IACF,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC/B,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,eAAe,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACtD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The right-hand side of `y′ = f(t, y)` for a system of `n` equations: writes
3
+ * the derivative of the state `y` at time `t` into `out`. `y` must not be
4
+ * modified, and `out` is never `y`.
5
+ */
6
+ export type OdeSystem = (t: number, y: Float64Array, out: Float64Array) => void;
7
+ /** A trajectory: `steps + 1` times and the state at each, row by row. */
8
+ export type OdeTrajectory = {
9
+ /** The times, from the start to the end of the span. */
10
+ readonly t: Float64Array;
11
+ /** The states, `t.length × dimension`, row-major: row `i` is `y(t[i])`. */
12
+ readonly y: Float64Array;
13
+ /** The number of equations. */
14
+ readonly dimension: number;
15
+ };
16
+ /**
17
+ * Integrates the system `y′ = f(t, y)` from `y(tSpan[0]) = y0` to `tSpan[1]`
18
+ * with the classical fourth-order Runge–Kutta method, in `steps` equal steps:
19
+ * the standard fixed-step integrator, error `O(h⁴)`, four evaluations of `f`
20
+ * per step. A scalar equation is a system of one.
21
+ *
22
+ * The span may run backwards (`tSpan[1] < tSpan[0]`). Each time is computed
23
+ * from the start and the step index, not accumulated, so the last one is
24
+ * exactly `tSpan[1]`. The trajectory is the only allocation besides four stage
25
+ * vectors; `f` writes into a buffer it is given.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * // The harmonic oscillator y″ = −y as a system: (y, y′)′ = (y′, −y).
30
+ * const { y } = rungeKutta4((t, state, out) => {
31
+ * out[0] = state[1]!;
32
+ * out[1] = -state[0]!;
33
+ * }, [1, 0], [0, Math.PI], 100);
34
+ * // y.at(-2) ≈ −1 = cos π
35
+ * ```;
36
+ *
37
+ * @param f The right-hand side.
38
+ * @param y0 The initial state.
39
+ * @param tSpan The start and end times.
40
+ * @param steps The number of steps, a positive integer.
41
+ * @returns The times and states of the trajectory.
42
+ * @throws {RangeError} When `steps` is not a positive integer, `y0` is empty,
43
+ * or a time is not finite.
44
+ */
45
+ export declare function rungeKutta4(f: OdeSystem, y0: ArrayLike<number>, tSpan: readonly [number, number], steps: number): OdeTrajectory;
46
+ //# sourceMappingURL=runge-kutta4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runge-kutta4.d.ts","sourceRoot":"","sources":["../../src/ode/runge-kutta4.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;AAEhF,yEAAyE;AACzE,MAAM,MAAM,aAAa,GAAG;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC;IACzB,+BAA+B;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAC1B,CAAC,EAAE,SAAS,EACZ,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EACrB,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,KAAK,EAAE,MAAM,GACX,aAAa,CA+Df"}
@@ -0,0 +1,85 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ /**
3
+ * Integrates the system `y′ = f(t, y)` from `y(tSpan[0]) = y0` to `tSpan[1]`
4
+ * with the classical fourth-order Runge–Kutta method, in `steps` equal steps:
5
+ * the standard fixed-step integrator, error `O(h⁴)`, four evaluations of `f`
6
+ * per step. A scalar equation is a system of one.
7
+ *
8
+ * The span may run backwards (`tSpan[1] < tSpan[0]`). Each time is computed
9
+ * from the start and the step index, not accumulated, so the last one is
10
+ * exactly `tSpan[1]`. The trajectory is the only allocation besides four stage
11
+ * vectors; `f` writes into a buffer it is given.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // The harmonic oscillator y″ = −y as a system: (y, y′)′ = (y′, −y).
16
+ * const { y } = rungeKutta4((t, state, out) => {
17
+ * out[0] = state[1]!;
18
+ * out[1] = -state[0]!;
19
+ * }, [1, 0], [0, Math.PI], 100);
20
+ * // y.at(-2) ≈ −1 = cos π
21
+ * ```;
22
+ *
23
+ * @param f The right-hand side.
24
+ * @param y0 The initial state.
25
+ * @param tSpan The start and end times.
26
+ * @param steps The number of steps, a positive integer.
27
+ * @returns The times and states of the trajectory.
28
+ * @throws {RangeError} When `steps` is not a positive integer, `y0` is empty,
29
+ * or a time is not finite.
30
+ */
31
+ export function rungeKutta4(f, y0, tSpan, steps) {
32
+ if (!Number.isSafeInteger(steps) || steps < 1) {
33
+ throw new RangeError(`rungeKutta4: steps must be a positive integer, got ${describeValue(steps)}`);
34
+ }
35
+ const dimension = y0.length;
36
+ if (dimension === 0) {
37
+ throw new RangeError("rungeKutta4: the initial state is empty");
38
+ }
39
+ const [start, end] = tSpan;
40
+ if (start - start !== 0 || end - end !== 0) {
41
+ throw new RangeError(`rungeKutta4: the span [${start}, ${end}] is not finite`);
42
+ }
43
+ const times = new Float64Array(steps + 1);
44
+ const states = new Float64Array((steps + 1) * dimension);
45
+ for (let index = 0; index < dimension; index++) {
46
+ states[index] = y0[index];
47
+ }
48
+ times[0] = start;
49
+ const h = (end - start) / steps;
50
+ const state = new Float64Array(dimension);
51
+ const stage = new Float64Array(dimension);
52
+ const k1 = new Float64Array(dimension);
53
+ const k2 = new Float64Array(dimension);
54
+ const k3 = new Float64Array(dimension);
55
+ const k4 = new Float64Array(dimension);
56
+ state.set(states.subarray(0, dimension));
57
+ for (let step = 0; step < steps; step++) {
58
+ const t = times[step];
59
+ const half = t + h / 2;
60
+ const next = step + 1 === steps ? end : start + (step + 1) * h;
61
+ f(t, state, k1);
62
+ for (let index = 0; index < dimension; index++) {
63
+ stage[index] = state[index] + (h / 2) * k1[index];
64
+ }
65
+ f(half, stage, k2);
66
+ for (let index = 0; index < dimension; index++) {
67
+ stage[index] = state[index] + (h / 2) * k2[index];
68
+ }
69
+ f(half, stage, k3);
70
+ for (let index = 0; index < dimension; index++) {
71
+ stage[index] = state[index] + h * k3[index];
72
+ }
73
+ f(next, stage, k4);
74
+ const row = (step + 1) * dimension;
75
+ for (let index = 0; index < dimension; index++) {
76
+ const value = state[index] +
77
+ (h / 6) * (k1[index] + 2 * k2[index] + 2 * k3[index] + k4[index]);
78
+ state[index] = value;
79
+ states[row + index] = value;
80
+ }
81
+ times[step + 1] = next;
82
+ }
83
+ return { t: times, y: states, dimension };
84
+ }
85
+ //# sourceMappingURL=runge-kutta4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runge-kutta4.js","sourceRoot":"","sources":["../../src/ode/runge-kutta4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAmB7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,WAAW,CAC1B,CAAY,EACZ,EAAqB,EACrB,KAAgC,EAChC,KAAa;IAEb,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,UAAU,CACnB,sDAAsD,aAAa,CAAC,KAAK,CAAC,EAAE,CAC5E,CAAC;IACH,CAAC;IACD,MAAM,SAAS,GAAG,EAAE,CAAC,MAAM,CAAC;IAC5B,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,UAAU,CAAC,yCAAyC,CAAC,CAAC;IACjE,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;IAC3B,IAAI,KAAK,GAAG,KAAK,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,UAAU,CACnB,0BAA0B,KAAK,KAAK,GAAG,iBAAiB,CACxD,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACzD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC;QAChD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAE,CAAC;IAC5B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;IACD,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,95 @@
1
+ /** The step is still being searched for: evaluate at `stp` and call again. */
2
+ export declare const SEARCH_CONTINUE_ = 0;
3
+ /** `stp` satisfies the strong Wolfe conditions. */
4
+ export declare const SEARCH_CONVERGED_ = 1;
5
+ /**
6
+ * No further progress is possible (rounding errors, the interval of uncertainty
7
+ * below `xtol`, or a step bound reached): the caller falls back on the best
8
+ * point it evaluated.
9
+ */
10
+ export declare const SEARCH_STALLED_ = 2;
11
+ /**
12
+ * The line search of Moré and Thuente (_ACM TOMS_ 20(3), 1994), as MINPACK-2's
13
+ * `dcsrch`/`dcstep`: a step `stp > 0` along a descent direction satisfying the
14
+ * strong Wolfe conditions
15
+ *
16
+ * ```text
17
+ * φ(stp) ≤ φ(0) + ftol · stp · φ′(0) (sufficient decrease)
18
+ * |φ′(stp)| ≤ gtol · |φ′(0)| (curvature)
19
+ * ```
20
+ *
21
+ * By safeguarded cubic and quadratic interpolation inside an interval of
22
+ * uncertainty that it brackets and shrinks. A state machine driven by its
23
+ * caller, as `dcsrch` is: set `stp`, `value` and `slope` (φ(0) and φ′(0) < 0),
24
+ * call {@link start}; then repeatedly evaluate φ and φ′ at `stp`, store them in
25
+ * `value` and `slope`, and call {@link iterate}, which answers with a
26
+ * `SEARCH_…` code and the next `stp`.
27
+ *
28
+ * Every number passes through fields, never arguments or return values: a
29
+ * double crossing a call the engine does not inline is boxed. For the same
30
+ * reason {@link step_} uses no `Math.sign`, `Math.max` or `Math.sqrt`: a search
31
+ * runs a few times a minimisation, so it stays in the engine's mid tier
32
+ * (Maglev), which calls those builtins with boxed doubles (`Math.sign` on Node
33
+ * 24 and 26, the other two on Node 24). Sign tests, comparisons and `** 0.5`
34
+ * stand in for them. `** 0.5` equals `Math.sqrt` for every finite or NaN
35
+ * radicand, the only kind it is given.
36
+ */
37
+ export declare class MoreThuente_ {
38
+ /** The sufficient-decrease constant `ftol` (Wolfe's `c₁`). */
39
+ ftol: number;
40
+ /** The curvature constant `gtol` (Wolfe's `c₂`), above `ftol`. */
41
+ gtol: number;
42
+ /** The relative width of the interval of uncertainty that stops the search. */
43
+ xtol: number;
44
+ /** The least step. */
45
+ stpmin: number;
46
+ /** The largest step. */
47
+ stpmax: number;
48
+ /** The step to evaluate next; the initial step before {@link start}. */
49
+ stp: number;
50
+ /** `φ(stp)`, written by the caller; `φ(0)` before {@link start}. */
51
+ value: number;
52
+ /** `φ′(stp)`, written by the caller; `φ′(0)` before {@link start}. */
53
+ slope: number;
54
+ private brackt_;
55
+ private stage_;
56
+ private finit_;
57
+ private ginit_;
58
+ private gtest_;
59
+ private stx_;
60
+ private fx_;
61
+ private gx_;
62
+ private sty_;
63
+ private fy_;
64
+ private gy_;
65
+ private stmin_;
66
+ private stmax_;
67
+ private width_;
68
+ private width1_;
69
+ /** The least step found not finite; trial steps stay below it. */
70
+ private limit_;
71
+ constructor();
72
+ /** Starts a search from `value = φ(0)` and `slope = φ′(0) < 0` at `stp`. */
73
+ start(): void;
74
+ /**
75
+ * The caller found `φ` or `φ′` not finite at `stp`: halves the step back
76
+ * towards the best one so far, and keeps every later trial below it.
77
+ */
78
+ retreat(): void;
79
+ /**
80
+ * One step of `dcsrch` with `value` and `slope` evaluated at `stp`.
81
+ *
82
+ * @returns A `SEARCH_…` code; with {@link SEARCH_CONTINUE_}, the next trial
83
+ * step in `stp`.
84
+ */
85
+ iterate(): number;
86
+ /**
87
+ * `dcstep`: from the interval ends `(stx, fx, gx)`, `(sty, fy, gy)` and the
88
+ * trial `(stp, value, slope)`, a safeguarded new trial step into `stp`, the
89
+ * interval updated to keep a minimiser inside. Its step bounds are the
90
+ * stage's `stmin_` and `stmax_`, as `dcsrch` passes them, not the global
91
+ * ones.
92
+ */
93
+ private step_;
94
+ }
95
+ //# sourceMappingURL=_more-thuente.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":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AAC,KAAK;CA4Ib"}
@@ -0,0 +1,333 @@
1
+ /** The step is still being searched for: evaluate at `stp` and call again. */
2
+ export const SEARCH_CONTINUE_ = 0;
3
+ /** `stp` satisfies the strong Wolfe conditions. */
4
+ export const SEARCH_CONVERGED_ = 1;
5
+ /**
6
+ * No further progress is possible (rounding errors, the interval of uncertainty
7
+ * below `xtol`, or a step bound reached): the caller falls back on the best
8
+ * point it evaluated.
9
+ */
10
+ export const SEARCH_STALLED_ = 2;
11
+ const EXTRAPOLATE_LOWER_ = 1.1;
12
+ const EXTRAPOLATE_UPPER_ = 4;
13
+ const BISECT_SHRINK_ = 0.66;
14
+ /**
15
+ * The line search of Moré and Thuente (_ACM TOMS_ 20(3), 1994), as MINPACK-2's
16
+ * `dcsrch`/`dcstep`: a step `stp > 0` along a descent direction satisfying the
17
+ * strong Wolfe conditions
18
+ *
19
+ * ```text
20
+ * φ(stp) ≤ φ(0) + ftol · stp · φ′(0) (sufficient decrease)
21
+ * |φ′(stp)| ≤ gtol · |φ′(0)| (curvature)
22
+ * ```
23
+ *
24
+ * By safeguarded cubic and quadratic interpolation inside an interval of
25
+ * uncertainty that it brackets and shrinks. A state machine driven by its
26
+ * caller, as `dcsrch` is: set `stp`, `value` and `slope` (φ(0) and φ′(0) < 0),
27
+ * call {@link start}; then repeatedly evaluate φ and φ′ at `stp`, store them in
28
+ * `value` and `slope`, and call {@link iterate}, which answers with a
29
+ * `SEARCH_…` code and the next `stp`.
30
+ *
31
+ * Every number passes through fields, never arguments or return values: a
32
+ * double crossing a call the engine does not inline is boxed. For the same
33
+ * reason {@link step_} uses no `Math.sign`, `Math.max` or `Math.sqrt`: a search
34
+ * runs a few times a minimisation, so it stays in the engine's mid tier
35
+ * (Maglev), which calls those builtins with boxed doubles (`Math.sign` on Node
36
+ * 24 and 26, the other two on Node 24). Sign tests, comparisons and `** 0.5`
37
+ * stand in for them. `** 0.5` equals `Math.sqrt` for every finite or NaN
38
+ * radicand, the only kind it is given.
39
+ */
40
+ export class MoreThuente_ {
41
+ /** The sufficient-decrease constant `ftol` (Wolfe's `c₁`). */
42
+ ftol = 1e-4;
43
+ /** The curvature constant `gtol` (Wolfe's `c₂`), above `ftol`. */
44
+ gtol = 0.9;
45
+ /** The relative width of the interval of uncertainty that stops the search. */
46
+ xtol = 0.1;
47
+ /** The least step. */
48
+ stpmin = 0.5;
49
+ /** The largest step. */
50
+ stpmax = 0.5;
51
+ /** The step to evaluate next; the initial step before {@link start}. */
52
+ stp = 0.5;
53
+ /** `φ(stp)`, written by the caller; `φ(0)` before {@link start}. */
54
+ value = 0.5;
55
+ /** `φ′(stp)`, written by the caller; `φ′(0)` before {@link start}. */
56
+ slope = 0.5;
57
+ brackt_ = false;
58
+ stage_ = 1;
59
+ finit_ = 0.5;
60
+ ginit_ = 0.5;
61
+ gtest_ = 0.5;
62
+ stx_ = 0.5;
63
+ fx_ = 0.5;
64
+ gx_ = 0.5;
65
+ sty_ = 0.5;
66
+ fy_ = 0.5;
67
+ gy_ = 0.5;
68
+ stmin_ = 0.5;
69
+ stmax_ = 0.5;
70
+ width_ = 0.5;
71
+ width1_ = 0.5;
72
+ /** The least step found not finite; trial steps stay below it. */
73
+ limit_ = 0.5;
74
+ // Fields start at 0.5 so that the engine gives them a double
75
+ // representation from the first write, never a small-integer one it must
76
+ // later widen.
77
+ constructor() {
78
+ this.stpmin = 0;
79
+ this.stpmax = 1e10;
80
+ this.stp = 1;
81
+ }
82
+ /** Starts a search from `value = φ(0)` and `slope = φ′(0) < 0` at `stp`. */
83
+ start() {
84
+ const stp = this.stp;
85
+ this.brackt_ = false;
86
+ this.stage_ = 1;
87
+ this.finit_ = this.value;
88
+ this.ginit_ = this.slope;
89
+ this.gtest_ = this.ftol * this.slope;
90
+ this.width_ = this.stpmax - this.stpmin;
91
+ this.width1_ = this.width_ / 0.5;
92
+ this.stx_ = 0;
93
+ this.fx_ = this.value;
94
+ this.gx_ = this.slope;
95
+ this.sty_ = 0;
96
+ this.fy_ = this.value;
97
+ this.gy_ = this.slope;
98
+ this.stmin_ = 0;
99
+ this.stmax_ = stp + EXTRAPOLATE_UPPER_ * stp;
100
+ this.limit_ = Number.POSITIVE_INFINITY;
101
+ }
102
+ /**
103
+ * The caller found `φ` or `φ′` not finite at `stp`: halves the step back
104
+ * towards the best one so far, and keeps every later trial below it.
105
+ */
106
+ retreat() {
107
+ const stp = this.stp;
108
+ if (stp < this.limit_) {
109
+ this.limit_ = stp;
110
+ }
111
+ this.stp = this.stx_ + 0.5 * (stp - this.stx_);
112
+ }
113
+ /**
114
+ * One step of `dcsrch` with `value` and `slope` evaluated at `stp`.
115
+ *
116
+ * @returns A `SEARCH_…` code; with {@link SEARCH_CONTINUE_}, the next trial
117
+ * step in `stp`.
118
+ */
119
+ iterate() {
120
+ const stp = this.stp;
121
+ const f = this.value;
122
+ const g = this.slope;
123
+ const ftest = this.finit_ + stp * this.gtest_;
124
+ if (this.stage_ === 1 && f <= ftest && g >= 0) {
125
+ this.stage_ = 2;
126
+ }
127
+ if (this.brackt_ &&
128
+ (stp <= this.stmin_ ||
129
+ stp >= this.stmax_ ||
130
+ this.stmax_ - this.stmin_ <= this.xtol * this.stmax_)) {
131
+ return SEARCH_STALLED_;
132
+ }
133
+ if (stp === this.stpmax && f <= ftest && g <= this.gtest_) {
134
+ return SEARCH_STALLED_;
135
+ }
136
+ if (stp === this.stpmin && (f > ftest || g >= this.gtest_)) {
137
+ return SEARCH_STALLED_;
138
+ }
139
+ if (f <= ftest && Math.abs(g) <= this.gtol * -this.ginit_) {
140
+ return SEARCH_CONVERGED_;
141
+ }
142
+ // In the first stage, while no step has both decreased enough and turned
143
+ // upwards, interpolate the modified function ψ(α) = φ(α) − φ(0) −
144
+ // ftol·α·φ′(0), whose minimisers satisfy the conditions too.
145
+ if (this.stage_ === 1 && f <= this.fx_ && f > ftest) {
146
+ const gtest = this.gtest_;
147
+ this.fx_ -= this.stx_ * gtest;
148
+ this.fy_ -= this.sty_ * gtest;
149
+ this.gx_ -= gtest;
150
+ this.gy_ -= gtest;
151
+ this.value = f - stp * gtest;
152
+ this.slope = g - gtest;
153
+ this.step_();
154
+ this.fx_ += this.stx_ * gtest;
155
+ this.fy_ += this.sty_ * gtest;
156
+ this.gx_ += gtest;
157
+ this.gy_ += gtest;
158
+ }
159
+ else {
160
+ this.step_();
161
+ }
162
+ let next = this.stp;
163
+ if (this.brackt_) {
164
+ const span = Math.abs(this.sty_ - this.stx_);
165
+ if (span >= BISECT_SHRINK_ * this.width1_) {
166
+ next = this.stx_ + 0.5 * (this.sty_ - this.stx_);
167
+ }
168
+ this.width1_ = this.width_;
169
+ this.width_ = span;
170
+ this.stmin_ = this.stx_ < this.sty_ ? this.stx_ : this.sty_;
171
+ this.stmax_ = this.stx_ < this.sty_ ? this.sty_ : this.stx_;
172
+ }
173
+ else {
174
+ this.stmin_ = next + EXTRAPOLATE_LOWER_ * (next - this.stx_);
175
+ this.stmax_ = next + EXTRAPOLATE_UPPER_ * (next - this.stx_);
176
+ }
177
+ if (next < this.stpmin) {
178
+ next = this.stpmin;
179
+ }
180
+ if (next > this.stpmax) {
181
+ next = this.stpmax;
182
+ }
183
+ if (next >= this.limit_) {
184
+ next = this.stx_ + 0.5 * (this.limit_ - this.stx_);
185
+ }
186
+ if (this.brackt_ &&
187
+ (next <= this.stmin_ ||
188
+ next >= this.stmax_ ||
189
+ this.stmax_ - this.stmin_ <= this.xtol * this.stmax_)) {
190
+ next = this.stx_;
191
+ }
192
+ this.stp = next;
193
+ return SEARCH_CONTINUE_;
194
+ }
195
+ /**
196
+ * `dcstep`: from the interval ends `(stx, fx, gx)`, `(sty, fy, gy)` and the
197
+ * trial `(stp, value, slope)`, a safeguarded new trial step into `stp`, the
198
+ * interval updated to keep a minimiser inside. Its step bounds are the
199
+ * stage's `stmin_` and `stmax_`, as `dcsrch` passes them, not the global
200
+ * ones.
201
+ */
202
+ step_() {
203
+ const stx = this.stx_;
204
+ const fx = this.fx_;
205
+ const dx = this.gx_;
206
+ const sty = this.sty_;
207
+ const fy = this.fy_;
208
+ const dy = this.gy_;
209
+ const stp = this.stp;
210
+ const fp = this.value;
211
+ const dp = this.slope;
212
+ // dcstep's `sgnd = dp · (dx / |dx|) < 0`.
213
+ const opposite = dx > 0 ? dp < 0 : dx < 0 && dp > 0;
214
+ const absDx = Math.abs(dx);
215
+ const absDp = Math.abs(dp);
216
+ let stpf;
217
+ if (fp > fx) {
218
+ // A higher value: the minimum is bracketed. The cubic step if it is
219
+ // closer to stx than the quadratic one, else their midpoint.
220
+ const theta = (3 * (fx - fp)) / (stp - stx) + dx + dp;
221
+ const absTheta = Math.abs(theta);
222
+ let s = absTheta > absDx ? absTheta : absDx;
223
+ s = s > absDp ? s : absDp;
224
+ let gamma = s * ((theta / s) * (theta / s) - (dx / s) * (dp / s)) ** 0.5;
225
+ if (stp < stx) {
226
+ gamma = -gamma;
227
+ }
228
+ const p = gamma - dx + theta;
229
+ const q = gamma - dx + gamma + dp;
230
+ const stpc = stx + (p / q) * (stp - stx);
231
+ const stpq = stx + (dx / ((fx - fp) / (stp - stx) + dx) / 2) * (stp - stx);
232
+ stpf =
233
+ Math.abs(stpc - stx) < Math.abs(stpq - stx)
234
+ ? stpc
235
+ : stpc + (stpq - stpc) / 2;
236
+ this.brackt_ = true;
237
+ }
238
+ else if (opposite) {
239
+ // Derivatives of opposite sign: bracketed. The step farther from stp.
240
+ const theta = (3 * (fx - fp)) / (stp - stx) + dx + dp;
241
+ const absTheta = Math.abs(theta);
242
+ let s = absTheta > absDx ? absTheta : absDx;
243
+ s = s > absDp ? s : absDp;
244
+ let gamma = s * ((theta / s) * (theta / s) - (dx / s) * (dp / s)) ** 0.5;
245
+ if (stp > stx) {
246
+ gamma = -gamma;
247
+ }
248
+ const p = gamma - dp + theta;
249
+ const q = gamma - dp + gamma + dx;
250
+ const stpc = stp + (p / q) * (stx - stp);
251
+ const stpq = stp + (dp / (dp - dx)) * (stx - stp);
252
+ stpf = Math.abs(stpc - stp) > Math.abs(stpq - stp) ? stpc : stpq;
253
+ this.brackt_ = true;
254
+ }
255
+ else if (absDp < absDx) {
256
+ // A lower value, same-sign derivative of decreasing magnitude.
257
+ const theta = (3 * (fx - fp)) / (stp - stx) + dx + dp;
258
+ const absTheta = Math.abs(theta);
259
+ let s = absTheta > absDx ? absTheta : absDx;
260
+ s = s > absDp ? s : absDp;
261
+ const radicand = (theta / s) * (theta / s) - (dx / s) * (dp / s);
262
+ let gamma = s * (radicand > 0 ? radicand : 0) ** 0.5;
263
+ if (stp > stx) {
264
+ gamma = -gamma;
265
+ }
266
+ const p = gamma - dp + theta;
267
+ const q = gamma + (dx - dp) + gamma;
268
+ const r = p / q;
269
+ let stpc;
270
+ if (r < 0 && gamma !== 0) {
271
+ stpc = stp + r * (stx - stp);
272
+ }
273
+ else if (stp > stx) {
274
+ stpc = this.stmax_;
275
+ }
276
+ else {
277
+ stpc = this.stmin_;
278
+ }
279
+ const stpq = stp + (dp / (dp - dx)) * (stx - stp);
280
+ if (this.brackt_) {
281
+ const bound = stp + BISECT_SHRINK_ * (sty - stp);
282
+ stpf = Math.abs(stpc - stp) < Math.abs(stpq - stp) ? stpc : stpq;
283
+ if (stp > stx) {
284
+ stpf = stpf < bound ? stpf : bound;
285
+ }
286
+ else {
287
+ stpf = stpf > bound ? stpf : bound;
288
+ }
289
+ }
290
+ else {
291
+ stpf = Math.abs(stpc - stp) > Math.abs(stpq - stp) ? stpc : stpq;
292
+ stpf = stpf < this.stmax_ ? stpf : this.stmax_;
293
+ stpf = stpf > this.stmin_ ? stpf : this.stmin_;
294
+ }
295
+ }
296
+ else if (this.brackt_) {
297
+ // A lower value, same-sign derivative not decreasing: the cubic step
298
+ // through the other end.
299
+ const theta = (3 * (fp - fy)) / (sty - stp) + dy + dp;
300
+ const absTheta = Math.abs(theta);
301
+ const absDy = Math.abs(dy);
302
+ let s = absTheta > absDy ? absTheta : absDy;
303
+ s = s > absDp ? s : absDp;
304
+ let gamma = s * ((theta / s) * (theta / s) - (dy / s) * (dp / s)) ** 0.5;
305
+ if (stp > sty) {
306
+ gamma = -gamma;
307
+ }
308
+ const p = gamma - dp + theta;
309
+ const q = gamma - dp + gamma + dy;
310
+ stpf = stp + (p / q) * (sty - stp);
311
+ }
312
+ else {
313
+ stpf = stp > stx ? this.stmax_ : this.stmin_;
314
+ }
315
+ if (fp > fx) {
316
+ this.sty_ = stp;
317
+ this.fy_ = fp;
318
+ this.gy_ = dp;
319
+ }
320
+ else {
321
+ if (opposite) {
322
+ this.sty_ = stx;
323
+ this.fy_ = fx;
324
+ this.gy_ = dx;
325
+ }
326
+ this.stx_ = stp;
327
+ this.fx_ = fp;
328
+ this.gx_ = dp;
329
+ }
330
+ this.stp = stpf;
331
+ }
332
+ }
333
+ //# sourceMappingURL=_more-thuente.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_more-thuente.js","sourceRoot":"","sources":["../../src/optimize/_more-thuente.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,mDAAmD;AACnD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAEnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,YAAY;IACxB,8DAA8D;IACvD,IAAI,GAAG,IAAI,CAAC;IACnB,kEAAkE;IAC3D,IAAI,GAAG,GAAG,CAAC;IAClB,+EAA+E;IACxE,IAAI,GAAG,GAAG,CAAC;IAClB,sBAAsB;IACf,MAAM,GAAG,GAAG,CAAC;IACpB,wBAAwB;IACjB,MAAM,GAAG,GAAG,CAAC;IACpB,wEAAwE;IACjE,GAAG,GAAG,GAAG,CAAC;IACjB,oEAAoE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