@danielsimonjr/mathts-functions 0.45.0 → 0.47.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/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +511 -181
- package/dist/linalg-extra.d.ts +10 -4
- package/dist/linalg-extra.d.ts.map +1 -1
- package/dist/numeric/krylov.d.ts +47 -9
- package/dist/numeric/krylov.d.ts.map +1 -1
- package/dist/numeric/svds.d.ts +32 -0
- package/dist/numeric/svds.d.ts.map +1 -0
- package/dist/probability/util/gammaSample.d.ts +19 -0
- package/dist/probability/util/gammaSample.d.ts.map +1 -0
- package/dist/stats/gaussian-process.d.ts +49 -0
- package/dist/stats/gaussian-process.d.ts.map +1 -0
- package/dist/stats/multivariate-sampling.d.ts +41 -0
- package/dist/stats/multivariate-sampling.d.ts.map +1 -0
- package/dist/typed/dist-objects.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -36,10 +36,12 @@ export { newton, secant, halley } from './numeric/open-root-finders.js';
|
|
|
36
36
|
export type { NewtonOptions, SecantOptions, HalleyOptions } from './numeric/open-root-finders.js';
|
|
37
37
|
export { fsolve, root } from './numeric/fsolve.js';
|
|
38
38
|
export type { FsolveOptions } from './numeric/fsolve.js';
|
|
39
|
-
export { cg, minres, gmres, bicgstab } from './numeric/krylov.js';
|
|
39
|
+
export { cg, minres, gmres, bicgstab, incompleteLU, incompleteCholesky } from './numeric/krylov.js';
|
|
40
40
|
export type { LinearOperatorInput, Preconditioner, KrylovOptions, GmresOptions, KrylovResult, } from './numeric/krylov.js';
|
|
41
41
|
export { eigsh } from './numeric/eigsh.js';
|
|
42
42
|
export type { EigshOperatorInput, EigshOptions, EigshResult } from './numeric/eigsh.js';
|
|
43
|
+
export { svds } from './numeric/svds.js';
|
|
44
|
+
export type { SvdsOptions, SvdsResult } from './numeric/svds.js';
|
|
43
45
|
export { thomasSolve, solveBanded, toeplitzSolve, ldl } from './numeric/structured-solvers.js';
|
|
44
46
|
export type { LDLResult } from './numeric/structured-solvers.js';
|
|
45
47
|
export { funm, cosm, sinm, complexCos, complexSin } from './numeric/matrix-functions.js';
|
|
@@ -116,4 +118,8 @@ export { mvnPdf, mvnSample } from './stats/mvn.js';
|
|
|
116
118
|
export type { MvnVector, MvnCov, MvnSampleOptions } from './stats/mvn.js';
|
|
117
119
|
export { tTestPower } from './stats/power-analysis.js';
|
|
118
120
|
export type { TTestPowerAlternative, TTestPowerOptions } from './stats/power-analysis.js';
|
|
121
|
+
export { gaussianProcessRegression, gpRegression } from './stats/gaussian-process.js';
|
|
122
|
+
export type { GPKernel, GPOptions, GPPrediction, GPModel } from './stats/gaussian-process.js';
|
|
123
|
+
export { dirichletSample, dirichletPdf, wishartSample } from './stats/multivariate-sampling.js';
|
|
124
|
+
export type { SampleSeedOptions } from './stats/multivariate-sampling.js';
|
|
119
125
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,cAAc,kBAAkB,CAAC;AAKjC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAOzC,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGlG,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,eAAe,GACh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EAAE,MAAM,kCAAkC,CAAC;AAChG,YAAY,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15178,6 +15178,34 @@ async function eigenvectorCentrality(adj, opts) {
|
|
|
15178
15178
|
|
|
15179
15179
|
// src/typed/dist-objects.ts
|
|
15180
15180
|
import { computePool as computePool9 } from "@danielsimonjr/mathts-parallel";
|
|
15181
|
+
|
|
15182
|
+
// src/probability/util/gammaSample.ts
|
|
15183
|
+
function normalSampleRng(rng) {
|
|
15184
|
+
const u1 = rng();
|
|
15185
|
+
const u2 = rng();
|
|
15186
|
+
return Math.sqrt(-2 * Math.log(u1 < 1e-300 ? 1e-300 : u1)) * Math.cos(2 * Math.PI * u2);
|
|
15187
|
+
}
|
|
15188
|
+
function gammaSampleRng(alpha, rng) {
|
|
15189
|
+
if (alpha < 1) {
|
|
15190
|
+
return gammaSampleRng(alpha + 1, rng) * Math.pow(rng(), 1 / alpha);
|
|
15191
|
+
}
|
|
15192
|
+
const d = alpha - 1 / 3;
|
|
15193
|
+
const c = 1 / Math.sqrt(9 * d);
|
|
15194
|
+
for (; ; ) {
|
|
15195
|
+
let x;
|
|
15196
|
+
let v;
|
|
15197
|
+
do {
|
|
15198
|
+
x = normalSampleRng(rng);
|
|
15199
|
+
v = 1 + c * x;
|
|
15200
|
+
} while (v <= 0);
|
|
15201
|
+
v = v * v * v;
|
|
15202
|
+
const u = rng();
|
|
15203
|
+
if (u < 1 - 0.0331 * (x * x) * (x * x)) return d * v;
|
|
15204
|
+
if (Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v))) return d * v;
|
|
15205
|
+
}
|
|
15206
|
+
}
|
|
15207
|
+
|
|
15208
|
+
// src/typed/dist-objects.ts
|
|
15181
15209
|
var DIST_WORKER_THRESHOLD = 1e5;
|
|
15182
15210
|
var SQRT_2PI = Math.sqrt(2 * Math.PI);
|
|
15183
15211
|
function _normalCdfStd(z) {
|
|
@@ -15425,49 +15453,13 @@ function betaDist(alpha, beta_) {
|
|
|
15425
15453
|
};
|
|
15426
15454
|
}
|
|
15427
15455
|
function _gammaRandom(alpha) {
|
|
15428
|
-
|
|
15429
|
-
return _gammaRandom(alpha + 1) * Math.pow(Math.random(), 1 / alpha);
|
|
15430
|
-
}
|
|
15431
|
-
const d = alpha - 1 / 3;
|
|
15432
|
-
const c = 1 / Math.sqrt(9 * d);
|
|
15433
|
-
while (true) {
|
|
15434
|
-
let x;
|
|
15435
|
-
let v;
|
|
15436
|
-
do {
|
|
15437
|
-
x = _normalRandom();
|
|
15438
|
-
v = 1 + c * x;
|
|
15439
|
-
} while (v <= 0);
|
|
15440
|
-
v = v * v * v;
|
|
15441
|
-
const u = Math.random();
|
|
15442
|
-
if (u < 1 - 0.0331 * (x * x) * (x * x)) return d * v;
|
|
15443
|
-
if (Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v))) return d * v;
|
|
15444
|
-
}
|
|
15456
|
+
return gammaSampleRng(alpha, Math.random);
|
|
15445
15457
|
}
|
|
15446
15458
|
function _normalRandom() {
|
|
15447
|
-
|
|
15448
|
-
const u2 = Math.random();
|
|
15449
|
-
return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
|
|
15459
|
+
return normalSampleRng(Math.random);
|
|
15450
15460
|
}
|
|
15451
15461
|
function _gammaRandomRng(alpha, rng) {
|
|
15452
|
-
|
|
15453
|
-
return _gammaRandomRng(alpha + 1, rng) * Math.pow(rng(), 1 / alpha);
|
|
15454
|
-
}
|
|
15455
|
-
const d = alpha - 1 / 3;
|
|
15456
|
-
const c = 1 / Math.sqrt(9 * d);
|
|
15457
|
-
while (true) {
|
|
15458
|
-
let x;
|
|
15459
|
-
let v;
|
|
15460
|
-
do {
|
|
15461
|
-
const u1 = rng();
|
|
15462
|
-
const u2 = rng();
|
|
15463
|
-
x = Math.sqrt(-2 * Math.log(u1 < 1e-300 ? 1e-300 : u1)) * Math.cos(2 * Math.PI * u2);
|
|
15464
|
-
v = 1 + c * x;
|
|
15465
|
-
} while (v <= 0);
|
|
15466
|
-
v = v * v * v;
|
|
15467
|
-
const u = rng();
|
|
15468
|
-
if (u < 1 - 0.0331 * (x * x) * (x * x)) return d * v;
|
|
15469
|
-
if (Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v))) return d * v;
|
|
15470
|
-
}
|
|
15462
|
+
return gammaSampleRng(alpha, rng);
|
|
15471
15463
|
}
|
|
15472
15464
|
function binomialDist(n, p) {
|
|
15473
15465
|
if (!Number.isInteger(n) || n < 0)
|
|
@@ -45090,54 +45082,15 @@ function tukeyHSD(groups, alpha = 0.05) {
|
|
|
45090
45082
|
}
|
|
45091
45083
|
|
|
45092
45084
|
// src/linalg-extra.ts
|
|
45093
|
-
import { DenseMatrix as DenseMatrix6, lu as lu3 } from "@danielsimonjr/mathts-matrix";
|
|
45085
|
+
import { DenseMatrix as DenseMatrix6, lu as lu3, matrixSchur as matrixSchur2 } from "@danielsimonjr/mathts-matrix";
|
|
45094
45086
|
var _inv = inv;
|
|
45095
45087
|
var _eigs = eigs;
|
|
45096
45088
|
var _multiply = multiply;
|
|
45097
45089
|
var _qr = qr;
|
|
45098
45090
|
var transposeArr = (A) => A[0].map((_, j) => A.map((r) => r[j]));
|
|
45099
|
-
var identityArr = (n) => Array.from({ length: n }, (_, i) => Array.from({ length: n }, (_2, j) => i === j ? 1 : 0));
|
|
45100
45091
|
function realSchur(M) {
|
|
45101
|
-
const
|
|
45102
|
-
|
|
45103
|
-
let U = identityArr(n);
|
|
45104
|
-
let m = n;
|
|
45105
|
-
const normM = Math.max(...M.map((r) => r.reduce((s, v) => s + Math.abs(v), 0)), 1e-300);
|
|
45106
|
-
for (let iter = 0; iter < 8e3 && m > 1; iter++) {
|
|
45107
|
-
if (Math.abs(A[m - 1][m - 2]) < 1e-14 * (Math.abs(A[m - 2][m - 2]) + Math.abs(A[m - 1][m - 1]) || normM)) {
|
|
45108
|
-
A[m - 1][m - 2] = 0;
|
|
45109
|
-
m--;
|
|
45110
|
-
continue;
|
|
45111
|
-
}
|
|
45112
|
-
const a = A[m - 2][m - 2];
|
|
45113
|
-
const b = A[m - 2][m - 1];
|
|
45114
|
-
const c = A[m - 1][m - 2];
|
|
45115
|
-
const d = A[m - 1][m - 1];
|
|
45116
|
-
const delta = (a - d) / 2;
|
|
45117
|
-
const disc = delta * delta + b * c;
|
|
45118
|
-
if (disc < 0) {
|
|
45119
|
-
if (m === 2) break;
|
|
45120
|
-
if (Math.abs(A[m - 2][m - 3]) < 1e-14 * (Math.abs(A[m - 3][m - 3]) + Math.abs(a) || normM)) {
|
|
45121
|
-
A[m - 2][m - 3] = 0;
|
|
45122
|
-
m -= 2;
|
|
45123
|
-
continue;
|
|
45124
|
-
}
|
|
45125
|
-
}
|
|
45126
|
-
const denom = Math.abs(delta) + Math.sqrt(Math.abs(disc));
|
|
45127
|
-
const s = disc >= 0 && denom > 1e-300 ? d - (Math.sign(delta) || 1) * (b * c) / denom : d;
|
|
45128
|
-
const As = A.map((r, i) => r.map((v, j) => v - (i === j ? s : 0)));
|
|
45129
|
-
const { Q: Q2, R } = _qr(As);
|
|
45130
|
-
A = _multiply(R, Q2).map((r, i) => r.map((v, j) => v + (i === j ? s : 0)));
|
|
45131
|
-
U = _multiply(U, Q2);
|
|
45132
|
-
}
|
|
45133
|
-
for (let i = 2; i < n; i++) {
|
|
45134
|
-
for (let j = 0; j < i - 1; j++) {
|
|
45135
|
-
if (Math.abs(A[i][j]) > 1e-8 * (1 + Math.abs(A[i][i]) + Math.abs(A[j][j]))) {
|
|
45136
|
-
throw new Error("realSchur: QR iteration failed to converge to (quasi-)triangular form");
|
|
45137
|
-
}
|
|
45138
|
-
}
|
|
45139
|
-
}
|
|
45140
|
-
return { U, S: A };
|
|
45092
|
+
const { Q: Q2, T } = matrixSchur2(DenseMatrix6.fromArray(M));
|
|
45093
|
+
return { U: Q2.toArray(), S: T.toArray() };
|
|
45141
45094
|
}
|
|
45142
45095
|
var arr3 = (x) => Array.isArray(x) ? x : Array.from(x);
|
|
45143
45096
|
function generalizedEig(A, B) {
|
|
@@ -45476,9 +45429,14 @@ function resolvePreconditioner(a, preconditioner) {
|
|
|
45476
45429
|
if (typeof preconditioner === "function") return preconditioner;
|
|
45477
45430
|
if (!isDenseMatrix2(a)) {
|
|
45478
45431
|
throw new Error(
|
|
45479
|
-
|
|
45432
|
+
`krylov: '${preconditioner}' preconditioner requires a dense matrix (it reads A's entries) \u2014 pass a custom preconditioner function when using a matvec operator`
|
|
45480
45433
|
);
|
|
45481
45434
|
}
|
|
45435
|
+
if (preconditioner === "jacobi") return makeJacobi(a);
|
|
45436
|
+
if (preconditioner === "ilu") return makeILU0(a);
|
|
45437
|
+
return makeIC0(a);
|
|
45438
|
+
}
|
|
45439
|
+
function makeJacobi(a) {
|
|
45482
45440
|
const n = a.length;
|
|
45483
45441
|
const invDiag = new Array(n);
|
|
45484
45442
|
for (let i = 0; i < n; i++) {
|
|
@@ -45492,6 +45450,102 @@ function resolvePreconditioner(a, preconditioner) {
|
|
|
45492
45450
|
}
|
|
45493
45451
|
return (r) => r.map((v, i) => v * invDiag[i]);
|
|
45494
45452
|
}
|
|
45453
|
+
function sparsityPattern(a) {
|
|
45454
|
+
return a.map((row2, i) => row2.map((v, j) => v !== 0 || i === j));
|
|
45455
|
+
}
|
|
45456
|
+
function incompleteLU(a) {
|
|
45457
|
+
const n = a.length;
|
|
45458
|
+
const pattern = sparsityPattern(a);
|
|
45459
|
+
const LU = a.map((row2) => row2.slice());
|
|
45460
|
+
for (let i = 0; i < n; i++) {
|
|
45461
|
+
for (let k = 0; k < i; k++) {
|
|
45462
|
+
if (!pattern[i][k]) continue;
|
|
45463
|
+
if (Math.abs(LU[k][k]) < 1e-300) {
|
|
45464
|
+
throw new Error(`incompleteLU: ILU(0) zero pivot at U[${k}][${k}] \u2014 matrix needs pivoting`);
|
|
45465
|
+
}
|
|
45466
|
+
const lik = LU[i][k] / LU[k][k];
|
|
45467
|
+
LU[i][k] = lik;
|
|
45468
|
+
for (let j = k + 1; j < n; j++) {
|
|
45469
|
+
if (!pattern[i][j]) continue;
|
|
45470
|
+
LU[i][j] -= lik * LU[k][j];
|
|
45471
|
+
}
|
|
45472
|
+
}
|
|
45473
|
+
if (Math.abs(LU[i][i]) < 1e-300) {
|
|
45474
|
+
throw new Error(`incompleteLU: ILU(0) zero pivot at U[${i}][${i}] \u2014 matrix needs pivoting`);
|
|
45475
|
+
}
|
|
45476
|
+
}
|
|
45477
|
+
const L = Array.from(
|
|
45478
|
+
{ length: n },
|
|
45479
|
+
(_, i) => Array.from({ length: n }, (_2, j) => j < i ? LU[i][j] : j === i ? 1 : 0)
|
|
45480
|
+
);
|
|
45481
|
+
const U = Array.from(
|
|
45482
|
+
{ length: n },
|
|
45483
|
+
(_, i) => Array.from({ length: n }, (_2, j) => j >= i ? LU[i][j] : 0)
|
|
45484
|
+
);
|
|
45485
|
+
return { L, U };
|
|
45486
|
+
}
|
|
45487
|
+
function incompleteCholesky(a) {
|
|
45488
|
+
const n = a.length;
|
|
45489
|
+
const src = a;
|
|
45490
|
+
const pattern = sparsityPattern(src);
|
|
45491
|
+
const L = Array.from({ length: n }, () => new Array(n).fill(0));
|
|
45492
|
+
for (let i = 0; i < n; i++) {
|
|
45493
|
+
for (let j = 0; j <= i; j++) {
|
|
45494
|
+
if (!pattern[i][j]) continue;
|
|
45495
|
+
let sum3 = src[i][j];
|
|
45496
|
+
for (let k = 0; k < j; k++) sum3 -= L[i][k] * L[j][k];
|
|
45497
|
+
if (i === j) {
|
|
45498
|
+
if (sum3 <= 0) {
|
|
45499
|
+
throw new Error(
|
|
45500
|
+
`incompleteCholesky: IC(0) requires a symmetric positive-definite matrix (non-positive pivot ${sum3} at ${i}) \u2014 use ILU(0) for indefinite/nonsymmetric A`
|
|
45501
|
+
);
|
|
45502
|
+
}
|
|
45503
|
+
L[i][i] = Math.sqrt(sum3);
|
|
45504
|
+
} else {
|
|
45505
|
+
L[i][j] = sum3 / L[j][j];
|
|
45506
|
+
}
|
|
45507
|
+
}
|
|
45508
|
+
}
|
|
45509
|
+
return { L };
|
|
45510
|
+
}
|
|
45511
|
+
function makeILU0(a) {
|
|
45512
|
+
const { L, U } = incompleteLU(a);
|
|
45513
|
+
const n = a.length;
|
|
45514
|
+
return (r) => {
|
|
45515
|
+
const y = new Array(n).fill(0);
|
|
45516
|
+
for (let i = 0; i < n; i++) {
|
|
45517
|
+
let s = r[i];
|
|
45518
|
+
for (let j = 0; j < i; j++) s -= L[i][j] * y[j];
|
|
45519
|
+
y[i] = s;
|
|
45520
|
+
}
|
|
45521
|
+
const x = new Array(n).fill(0);
|
|
45522
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
45523
|
+
let s = y[i];
|
|
45524
|
+
for (let j = i + 1; j < n; j++) s -= U[i][j] * x[j];
|
|
45525
|
+
x[i] = s / U[i][i];
|
|
45526
|
+
}
|
|
45527
|
+
return x;
|
|
45528
|
+
};
|
|
45529
|
+
}
|
|
45530
|
+
function makeIC0(a) {
|
|
45531
|
+
const { L } = incompleteCholesky(a);
|
|
45532
|
+
const n = a.length;
|
|
45533
|
+
return (r) => {
|
|
45534
|
+
const y = new Array(n).fill(0);
|
|
45535
|
+
for (let i = 0; i < n; i++) {
|
|
45536
|
+
let s = r[i];
|
|
45537
|
+
for (let j = 0; j < i; j++) s -= L[i][j] * y[j];
|
|
45538
|
+
y[i] = s / L[i][i];
|
|
45539
|
+
}
|
|
45540
|
+
const x = new Array(n).fill(0);
|
|
45541
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
45542
|
+
let s = y[i];
|
|
45543
|
+
for (let j = i + 1; j < n; j++) s -= L[j][i] * x[j];
|
|
45544
|
+
x[i] = s / L[i][i];
|
|
45545
|
+
}
|
|
45546
|
+
return x;
|
|
45547
|
+
};
|
|
45548
|
+
}
|
|
45495
45549
|
function defaultMaxIter(n) {
|
|
45496
45550
|
return Math.min(n * 10, 1e3);
|
|
45497
45551
|
}
|
|
@@ -45545,103 +45599,55 @@ function minres(a, b, opts) {
|
|
|
45545
45599
|
const tol = opts?.tol ?? 1e-10;
|
|
45546
45600
|
const maxIter = opts?.maxIter ?? defaultMaxIter(n);
|
|
45547
45601
|
const bNorm = norm25(b);
|
|
45548
|
-
const
|
|
45549
|
-
|
|
45550
|
-
let
|
|
45551
|
-
|
|
45552
|
-
|
|
45553
|
-
|
|
45554
|
-
|
|
45555
|
-
|
|
45556
|
-
|
|
45557
|
-
|
|
45558
|
-
|
|
45559
|
-
|
|
45560
|
-
|
|
45561
|
-
|
|
45562
|
-
|
|
45563
|
-
let
|
|
45564
|
-
let
|
|
45602
|
+
const x = opts?.x0 ? opts.x0.slice() : zeros2(n);
|
|
45603
|
+
let r1 = subtract2(b, matvec2(x));
|
|
45604
|
+
let y = applyM(r1);
|
|
45605
|
+
const beta1 = Math.sqrt(Math.max(0, dot2(r1, y)));
|
|
45606
|
+
const residual0 = relativeResidualNorm(norm25(r1), bNorm);
|
|
45607
|
+
if (residual0 < tol || beta1 < 1e-300) {
|
|
45608
|
+
return { x, iterations: 0, converged: residual0 < tol, residual: residual0 };
|
|
45609
|
+
}
|
|
45610
|
+
let oldb = 0;
|
|
45611
|
+
let beta2 = beta1;
|
|
45612
|
+
let dbar = 0;
|
|
45613
|
+
let epsln = 0;
|
|
45614
|
+
let phibar = beta1;
|
|
45615
|
+
let cs = -1;
|
|
45616
|
+
let sn = 0;
|
|
45617
|
+
let w = zeros2(n);
|
|
45618
|
+
let w2 = zeros2(n);
|
|
45619
|
+
let r2 = r1.slice();
|
|
45565
45620
|
let iterations = 0;
|
|
45566
|
-
for (let
|
|
45567
|
-
iterations =
|
|
45568
|
-
const
|
|
45569
|
-
|
|
45570
|
-
|
|
45571
|
-
const
|
|
45572
|
-
|
|
45573
|
-
|
|
45574
|
-
|
|
45575
|
-
|
|
45576
|
-
|
|
45577
|
-
|
|
45578
|
-
const
|
|
45579
|
-
const
|
|
45580
|
-
|
|
45581
|
-
|
|
45582
|
-
|
|
45583
|
-
|
|
45584
|
-
|
|
45585
|
-
|
|
45586
|
-
|
|
45587
|
-
|
|
45588
|
-
const
|
|
45589
|
-
|
|
45590
|
-
|
|
45591
|
-
let
|
|
45592
|
-
|
|
45593
|
-
|
|
45594
|
-
|
|
45595
|
-
|
|
45596
|
-
if (residual < bestResidual) {
|
|
45597
|
-
bestResidual = residual;
|
|
45598
|
-
bestX = xCandidate;
|
|
45599
|
-
}
|
|
45600
|
-
if (residual < tol) {
|
|
45601
|
-
return { x: xCandidate, iterations: k, converged: true, residual };
|
|
45602
|
-
}
|
|
45603
|
-
if (betaNext < 1e-300) break;
|
|
45604
|
-
betas.push(betaNext);
|
|
45605
|
-
V.push(scale(1 / betaNext, p));
|
|
45606
|
-
Z.push(scale(1 / betaNext, zRaw));
|
|
45607
|
-
}
|
|
45608
|
-
return { x: bestX, iterations, converged: bestResidual < tol, residual: bestResidual };
|
|
45609
|
-
}
|
|
45610
|
-
function solveLeastSquaresQR(T, rhs) {
|
|
45611
|
-
const m = T.length;
|
|
45612
|
-
const n = T[0]?.length ?? 0;
|
|
45613
|
-
const R = T.map((row2) => row2.slice());
|
|
45614
|
-
const c = rhs.slice();
|
|
45615
|
-
for (let k = 0; k < n; k++) {
|
|
45616
|
-
let normX = 0;
|
|
45617
|
-
for (let i = k; i < m; i++) normX += R[i][k] * R[i][k];
|
|
45618
|
-
normX = Math.sqrt(normX);
|
|
45619
|
-
if (normX < 1e-300) continue;
|
|
45620
|
-
const alpha = R[k][k] >= 0 ? -normX : normX;
|
|
45621
|
-
const v = new Array(m).fill(0);
|
|
45622
|
-
v[k] = R[k][k] - alpha;
|
|
45623
|
-
for (let i = k + 1; i < m; i++) v[i] = R[i][k];
|
|
45624
|
-
let vNormSq = 0;
|
|
45625
|
-
for (let i = k; i < m; i++) vNormSq += v[i] * v[i];
|
|
45626
|
-
if (vNormSq < 1e-300) continue;
|
|
45627
|
-
for (let j = k; j < n; j++) {
|
|
45628
|
-
let dotVR = 0;
|
|
45629
|
-
for (let i = k; i < m; i++) dotVR += v[i] * R[i][j];
|
|
45630
|
-
const factor2 = 2 * dotVR / vNormSq;
|
|
45631
|
-
for (let i = k; i < m; i++) R[i][j] -= factor2 * v[i];
|
|
45632
|
-
}
|
|
45633
|
-
let dotVC = 0;
|
|
45634
|
-
for (let i = k; i < m; i++) dotVC += v[i] * c[i];
|
|
45635
|
-
const factorC = 2 * dotVC / vNormSq;
|
|
45636
|
-
for (let i = k; i < m; i++) c[i] -= factorC * v[i];
|
|
45637
|
-
}
|
|
45638
|
-
const y = new Array(n).fill(0);
|
|
45639
|
-
for (let i = n - 1; i >= 0; i--) {
|
|
45640
|
-
let sum3 = c[i];
|
|
45641
|
-
for (let j = i + 1; j < n; j++) sum3 -= R[i][j] * y[j];
|
|
45642
|
-
y[i] = Math.abs(R[i][i]) > 1e-300 ? sum3 / R[i][i] : 0;
|
|
45643
|
-
}
|
|
45644
|
-
return y;
|
|
45621
|
+
for (let iter = 1; iter <= maxIter; iter++) {
|
|
45622
|
+
iterations = iter;
|
|
45623
|
+
const v = scale(1 / beta2, y);
|
|
45624
|
+
y = matvec2(v);
|
|
45625
|
+
if (iter >= 2) y = axpy(-beta2 / oldb, r1, y);
|
|
45626
|
+
const alfa = dot2(v, y);
|
|
45627
|
+
y = axpy(-alfa / beta2, r2, y);
|
|
45628
|
+
r1 = r2;
|
|
45629
|
+
r2 = y;
|
|
45630
|
+
y = applyM(r2);
|
|
45631
|
+
oldb = beta2;
|
|
45632
|
+
beta2 = Math.sqrt(Math.max(0, dot2(r2, y)));
|
|
45633
|
+
const oldeps = epsln;
|
|
45634
|
+
const delta = cs * dbar + sn * alfa;
|
|
45635
|
+
const gbar = sn * dbar - cs * alfa;
|
|
45636
|
+
epsln = sn * beta2;
|
|
45637
|
+
dbar = -cs * beta2;
|
|
45638
|
+
const gamma2 = Math.max(Math.sqrt(gbar * gbar + beta2 * beta2), 1e-300);
|
|
45639
|
+
cs = gbar / gamma2;
|
|
45640
|
+
sn = beta2 / gamma2;
|
|
45641
|
+
const phi = cs * phibar;
|
|
45642
|
+
phibar = sn * phibar;
|
|
45643
|
+
const w1 = w2;
|
|
45644
|
+
w2 = w;
|
|
45645
|
+
w = scale(1 / gamma2, subtract2(subtract2(v, scale(oldeps, w1)), scale(delta, w2)));
|
|
45646
|
+
for (let i = 0; i < n; i++) x[i] += phi * w[i];
|
|
45647
|
+
if (phibar / beta1 < tol || beta2 < 1e-300) break;
|
|
45648
|
+
}
|
|
45649
|
+
const residual = relativeResidual(matvec2, x, b, bNorm);
|
|
45650
|
+
return { x, iterations, converged: residual < tol, residual };
|
|
45645
45651
|
}
|
|
45646
45652
|
function gmres(a, b, opts) {
|
|
45647
45653
|
const n = b.length;
|
|
@@ -45939,6 +45945,67 @@ function eigsh(a, k = 1, opts) {
|
|
|
45939
45945
|
return { eigenvalues, eigenvectors };
|
|
45940
45946
|
}
|
|
45941
45947
|
|
|
45948
|
+
// src/numeric/svds.ts
|
|
45949
|
+
function matvecA(A, x) {
|
|
45950
|
+
return A.map((row2) => {
|
|
45951
|
+
let s = 0;
|
|
45952
|
+
for (let j = 0; j < row2.length; j++) s += row2[j] * x[j];
|
|
45953
|
+
return s;
|
|
45954
|
+
});
|
|
45955
|
+
}
|
|
45956
|
+
function matvecAt(A, y, n) {
|
|
45957
|
+
const out = new Array(n).fill(0);
|
|
45958
|
+
for (let i = 0; i < A.length; i++) {
|
|
45959
|
+
const yi = y[i];
|
|
45960
|
+
const row2 = A[i];
|
|
45961
|
+
for (let j = 0; j < n; j++) out[j] += row2[j] * yi;
|
|
45962
|
+
}
|
|
45963
|
+
return out;
|
|
45964
|
+
}
|
|
45965
|
+
function norm27(v) {
|
|
45966
|
+
let s = 0;
|
|
45967
|
+
for (let i = 0; i < v.length; i++) s += v[i] * v[i];
|
|
45968
|
+
return Math.sqrt(s);
|
|
45969
|
+
}
|
|
45970
|
+
function svds(A, k = 1, opts) {
|
|
45971
|
+
const m = A.length;
|
|
45972
|
+
const n = A[0]?.length ?? 0;
|
|
45973
|
+
if (m === 0 || n === 0 || A.some((row2) => row2.length !== n)) {
|
|
45974
|
+
throw new Error("svds: A must be a non-empty rectangular matrix");
|
|
45975
|
+
}
|
|
45976
|
+
const minDim = Math.min(m, n);
|
|
45977
|
+
if (!Number.isInteger(k) || k < 1 || k > minDim) {
|
|
45978
|
+
throw new Error(`svds: k must be an integer between 1 and min(m,n)=${minDim}, got ${k}`);
|
|
45979
|
+
}
|
|
45980
|
+
const tol = opts?.tol ?? 1e-10;
|
|
45981
|
+
const useAtA = m >= n;
|
|
45982
|
+
const dim = useAtA ? n : m;
|
|
45983
|
+
const normalOp = useAtA ? (x) => matvecAt(A, matvecA(A, x), n) : (x) => matvecA(A, matvecAt(A, x, n));
|
|
45984
|
+
const { eigenvalues, eigenvectors } = eigsh(normalOp, k, {
|
|
45985
|
+
which: "LM",
|
|
45986
|
+
n: dim,
|
|
45987
|
+
tol,
|
|
45988
|
+
maxIter: opts?.maxIter
|
|
45989
|
+
});
|
|
45990
|
+
const s = eigenvalues.map((lambda) => Math.sqrt(Math.max(0, lambda)));
|
|
45991
|
+
const primaryDim = dim;
|
|
45992
|
+
const otherDim = useAtA ? m : n;
|
|
45993
|
+
const primary = Array.from(
|
|
45994
|
+
{ length: primaryDim },
|
|
45995
|
+
() => new Array(k).fill(0)
|
|
45996
|
+
);
|
|
45997
|
+
const other = Array.from({ length: otherDim }, () => new Array(k).fill(0));
|
|
45998
|
+
for (let col = 0; col < k; col++) {
|
|
45999
|
+
const pvec = eigenvectors.map((row2) => row2[col]);
|
|
46000
|
+
for (let i = 0; i < primaryDim; i++) primary[i][col] = pvec[i];
|
|
46001
|
+
let ovec = useAtA ? matvecA(A, pvec) : matvecAt(A, pvec, n);
|
|
46002
|
+
const nrm = norm27(ovec);
|
|
46003
|
+
ovec = nrm > 1e-300 ? ovec.map((v) => v / nrm) : ovec;
|
|
46004
|
+
for (let i = 0; i < otherDim; i++) other[i][col] = ovec[i];
|
|
46005
|
+
}
|
|
46006
|
+
return useAtA ? { U: other, s, V: primary } : { U: primary, s, V: other };
|
|
46007
|
+
}
|
|
46008
|
+
|
|
45942
46009
|
// src/numeric/structured-solvers.ts
|
|
45943
46010
|
function thomasSolve(sub2, diag2, sup, d) {
|
|
45944
46011
|
const n = diag2.length;
|
|
@@ -47618,7 +47685,7 @@ function levenbergMarquardt(residual, x0, opts = {}) {
|
|
|
47618
47685
|
let x = Array.from(x0);
|
|
47619
47686
|
let lambda = 1e-3;
|
|
47620
47687
|
const h = 1e-7;
|
|
47621
|
-
const
|
|
47688
|
+
const norm28 = (v) => v.reduce((s, c) => s + c * c, 0);
|
|
47622
47689
|
const jacobian2 = (xc, r0) => {
|
|
47623
47690
|
const m = r0.length;
|
|
47624
47691
|
const J = Array.from({ length: m }, () => new Array(n).fill(0));
|
|
@@ -47631,7 +47698,7 @@ function levenbergMarquardt(residual, x0, opts = {}) {
|
|
|
47631
47698
|
return J;
|
|
47632
47699
|
};
|
|
47633
47700
|
let r = residual(x);
|
|
47634
|
-
let cost =
|
|
47701
|
+
let cost = norm28(r);
|
|
47635
47702
|
let iter = 0;
|
|
47636
47703
|
for (; iter < maxIter; iter++) {
|
|
47637
47704
|
const J = jacobian2(x, r);
|
|
@@ -47662,7 +47729,7 @@ function levenbergMarquardt(residual, x0, opts = {}) {
|
|
|
47662
47729
|
}
|
|
47663
47730
|
const xNew = x.map((v, i) => v + delta[i]);
|
|
47664
47731
|
const rNew = residual(xNew);
|
|
47665
|
-
const costNew =
|
|
47732
|
+
const costNew = norm28(rNew);
|
|
47666
47733
|
if (costNew < cost) {
|
|
47667
47734
|
x = xNew;
|
|
47668
47735
|
r = rNew;
|
|
@@ -51959,6 +52026,261 @@ function tTestPower(effectSize, nobsOrPower, alpha, opts = {}) {
|
|
|
51959
52026
|
if (!(nobs > 1)) throw new Error("tTestPower: nobs must be greater than 1");
|
|
51960
52027
|
return powerAt(effectSize, nobs, alpha, alt);
|
|
51961
52028
|
}
|
|
52029
|
+
|
|
52030
|
+
// src/stats/gaussian-process.ts
|
|
52031
|
+
var SQRT3 = Math.sqrt(3);
|
|
52032
|
+
var SQRT5 = Math.sqrt(5);
|
|
52033
|
+
function euclidean2(a, b) {
|
|
52034
|
+
let s = 0;
|
|
52035
|
+
for (let i = 0; i < a.length; i++) {
|
|
52036
|
+
const d = a[i] - b[i];
|
|
52037
|
+
s += d * d;
|
|
52038
|
+
}
|
|
52039
|
+
return Math.sqrt(s);
|
|
52040
|
+
}
|
|
52041
|
+
function makeKernel(kernel, ell, sf2) {
|
|
52042
|
+
switch (kernel) {
|
|
52043
|
+
case "rbf":
|
|
52044
|
+
return (a, b) => {
|
|
52045
|
+
const r = euclidean2(a, b);
|
|
52046
|
+
return sf2 * Math.exp(-(r * r) / (2 * ell * ell));
|
|
52047
|
+
};
|
|
52048
|
+
case "matern32":
|
|
52049
|
+
return (a, b) => {
|
|
52050
|
+
const u = SQRT3 * euclidean2(a, b) / ell;
|
|
52051
|
+
return sf2 * (1 + u) * Math.exp(-u);
|
|
52052
|
+
};
|
|
52053
|
+
case "matern52":
|
|
52054
|
+
return (a, b) => {
|
|
52055
|
+
const r = euclidean2(a, b);
|
|
52056
|
+
const u = SQRT5 * r / ell;
|
|
52057
|
+
return sf2 * (1 + u + 5 * r * r / (3 * ell * ell)) * Math.exp(-u);
|
|
52058
|
+
};
|
|
52059
|
+
default:
|
|
52060
|
+
throw new Error(`gaussianProcessRegression: unknown kernel '${String(kernel)}'`);
|
|
52061
|
+
}
|
|
52062
|
+
}
|
|
52063
|
+
function forwardSolve(L, b) {
|
|
52064
|
+
const n = b.length;
|
|
52065
|
+
const x = new Array(n);
|
|
52066
|
+
for (let i = 0; i < n; i++) {
|
|
52067
|
+
let s = b[i];
|
|
52068
|
+
for (let j = 0; j < i; j++) s -= L[i][j] * x[j];
|
|
52069
|
+
x[i] = s / L[i][i];
|
|
52070
|
+
}
|
|
52071
|
+
return x;
|
|
52072
|
+
}
|
|
52073
|
+
function backSolveTranspose(L, b) {
|
|
52074
|
+
const n = b.length;
|
|
52075
|
+
const x = new Array(n);
|
|
52076
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
52077
|
+
let s = b[i];
|
|
52078
|
+
for (let j = i + 1; j < n; j++) s -= L[j][i] * x[j];
|
|
52079
|
+
x[i] = s / L[i][i];
|
|
52080
|
+
}
|
|
52081
|
+
return x;
|
|
52082
|
+
}
|
|
52083
|
+
function normalizeTrainingInputs(X, y) {
|
|
52084
|
+
if (!Array.isArray(X) || X.length === 0) {
|
|
52085
|
+
throw new Error("gaussianProcessRegression: X must be a non-empty array of feature vectors");
|
|
52086
|
+
}
|
|
52087
|
+
if (y.length !== X.length) {
|
|
52088
|
+
throw new Error(
|
|
52089
|
+
`gaussianProcessRegression: y length ${y.length} must match number of rows ${X.length}`
|
|
52090
|
+
);
|
|
52091
|
+
}
|
|
52092
|
+
const dim = X[0].length;
|
|
52093
|
+
if (dim === 0) throw new Error("gaussianProcessRegression: feature vectors must be non-empty");
|
|
52094
|
+
const Xa = X.map((row2) => {
|
|
52095
|
+
if (row2.length !== dim) {
|
|
52096
|
+
throw new Error("gaussianProcessRegression: all feature vectors must have the same length");
|
|
52097
|
+
}
|
|
52098
|
+
return [...row2];
|
|
52099
|
+
});
|
|
52100
|
+
return { Xa, ya: [...y], dim };
|
|
52101
|
+
}
|
|
52102
|
+
function gaussianProcessRegression(X, y, options = {}) {
|
|
52103
|
+
const kernel = options.kernel ?? "rbf";
|
|
52104
|
+
const ell = options.lengthScale ?? 1;
|
|
52105
|
+
const sf2 = options.signalVariance ?? 1;
|
|
52106
|
+
const noise = options.noise ?? 1e-10;
|
|
52107
|
+
if (!(ell > 0)) throw new Error("gaussianProcessRegression: lengthScale must be positive");
|
|
52108
|
+
if (!(sf2 > 0)) throw new Error("gaussianProcessRegression: signalVariance must be positive");
|
|
52109
|
+
if (!(noise >= 0)) throw new Error("gaussianProcessRegression: noise must be non-negative");
|
|
52110
|
+
const { Xa, ya } = normalizeTrainingInputs(X, y);
|
|
52111
|
+
const n = Xa.length;
|
|
52112
|
+
const k = makeKernel(kernel, ell, sf2);
|
|
52113
|
+
const K = Array.from({ length: n }, () => new Array(n).fill(0));
|
|
52114
|
+
for (let i = 0; i < n; i++) {
|
|
52115
|
+
for (let j = i; j < n; j++) {
|
|
52116
|
+
const kij = k(Xa[i], Xa[j]);
|
|
52117
|
+
K[i][j] = kij;
|
|
52118
|
+
K[j][i] = kij;
|
|
52119
|
+
}
|
|
52120
|
+
K[i][i] += noise;
|
|
52121
|
+
}
|
|
52122
|
+
const { L } = cholesky(K);
|
|
52123
|
+
const Linvy = forwardSolve(L, ya);
|
|
52124
|
+
const alphaBar = backSolveTranspose(L, Linvy);
|
|
52125
|
+
let logDetHalf = 0;
|
|
52126
|
+
for (let i = 0; i < n; i++) logDetHalf += Math.log(L[i][i]);
|
|
52127
|
+
let yTa = 0;
|
|
52128
|
+
for (let i = 0; i < n; i++) yTa += ya[i] * alphaBar[i];
|
|
52129
|
+
const logMarginalLikelihood = -0.5 * yTa - logDetHalf - n / 2 * Math.log(2 * Math.PI);
|
|
52130
|
+
return {
|
|
52131
|
+
kernel,
|
|
52132
|
+
logMarginalLikelihood,
|
|
52133
|
+
predict(Xstar) {
|
|
52134
|
+
const m = Xstar.length;
|
|
52135
|
+
const mean7 = new Array(m);
|
|
52136
|
+
const variance2 = new Array(m);
|
|
52137
|
+
const std2 = new Array(m);
|
|
52138
|
+
for (let t = 0; t < m; t++) {
|
|
52139
|
+
const xt = Xstar[t];
|
|
52140
|
+
if (xt.length !== Xa[0].length) {
|
|
52141
|
+
throw new Error("gaussianProcessRegression.predict: test point dimensionality mismatch");
|
|
52142
|
+
}
|
|
52143
|
+
const ks = new Array(n);
|
|
52144
|
+
for (let i = 0; i < n; i++) ks[i] = k(Xa[i], xt);
|
|
52145
|
+
let mu = 0;
|
|
52146
|
+
for (let i = 0; i < n; i++) mu += ks[i] * alphaBar[i];
|
|
52147
|
+
const v = forwardSolve(L, ks);
|
|
52148
|
+
let vtv = 0;
|
|
52149
|
+
for (let i = 0; i < n; i++) vtv += v[i] * v[i];
|
|
52150
|
+
const kss = k(xt, xt);
|
|
52151
|
+
const varT = Math.max(kss - vtv, 0);
|
|
52152
|
+
mean7[t] = mu;
|
|
52153
|
+
variance2[t] = varT;
|
|
52154
|
+
std2[t] = Math.sqrt(varT);
|
|
52155
|
+
}
|
|
52156
|
+
return { mean: mean7, variance: variance2, std: std2 };
|
|
52157
|
+
}
|
|
52158
|
+
};
|
|
52159
|
+
}
|
|
52160
|
+
var gpRegression = gaussianProcessRegression;
|
|
52161
|
+
|
|
52162
|
+
// src/stats/multivariate-sampling.ts
|
|
52163
|
+
function validateAlpha(alpha, fn) {
|
|
52164
|
+
if (!Array.isArray(alpha) || alpha.length < 2) {
|
|
52165
|
+
throw new Error(`${fn}: alpha must be an array of at least 2 concentration parameters`);
|
|
52166
|
+
}
|
|
52167
|
+
for (const a of alpha) {
|
|
52168
|
+
if (!(a > 0) || !Number.isFinite(a)) {
|
|
52169
|
+
throw new Error(`${fn}: all concentration parameters must be positive and finite`);
|
|
52170
|
+
}
|
|
52171
|
+
}
|
|
52172
|
+
}
|
|
52173
|
+
function dirichletSample(alpha, n = 1, opts) {
|
|
52174
|
+
validateAlpha(alpha, "dirichletSample");
|
|
52175
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
52176
|
+
throw new Error("dirichletSample: n must be a positive integer");
|
|
52177
|
+
}
|
|
52178
|
+
const k = alpha.length;
|
|
52179
|
+
const rng = createRng(opts?.seed ?? null);
|
|
52180
|
+
const samples = new Array(n);
|
|
52181
|
+
for (let s = 0; s < n; s++) {
|
|
52182
|
+
const g = new Array(k);
|
|
52183
|
+
let total = 0;
|
|
52184
|
+
for (let i = 0; i < k; i++) {
|
|
52185
|
+
const gi = gammaSampleRng(alpha[i], rng);
|
|
52186
|
+
g[i] = gi;
|
|
52187
|
+
total += gi;
|
|
52188
|
+
}
|
|
52189
|
+
const row2 = new Array(k);
|
|
52190
|
+
for (let i = 0; i < k; i++) row2[i] = g[i] / total;
|
|
52191
|
+
samples[s] = row2;
|
|
52192
|
+
}
|
|
52193
|
+
return samples;
|
|
52194
|
+
}
|
|
52195
|
+
function dirichletPdf(x, alpha) {
|
|
52196
|
+
validateAlpha(alpha, "dirichletPdf");
|
|
52197
|
+
if (x.length !== alpha.length) {
|
|
52198
|
+
throw new Error(`dirichletPdf: x length ${x.length} must match alpha length ${alpha.length}`);
|
|
52199
|
+
}
|
|
52200
|
+
let sum3 = 0;
|
|
52201
|
+
for (const xi of x) {
|
|
52202
|
+
if (!(xi >= 0) || !(xi <= 1)) {
|
|
52203
|
+
throw new Error("dirichletPdf: x must lie on the simplex (each component in [0, 1])");
|
|
52204
|
+
}
|
|
52205
|
+
sum3 += xi;
|
|
52206
|
+
}
|
|
52207
|
+
if (Math.abs(sum3 - 1) > 1e-8) {
|
|
52208
|
+
throw new Error("dirichletPdf: x components must sum to 1");
|
|
52209
|
+
}
|
|
52210
|
+
let a0 = 0;
|
|
52211
|
+
let logB = 0;
|
|
52212
|
+
for (const a of alpha) {
|
|
52213
|
+
logB += lgammaNumber(a);
|
|
52214
|
+
a0 += a;
|
|
52215
|
+
}
|
|
52216
|
+
logB -= lgammaNumber(a0);
|
|
52217
|
+
let logpdf = -logB;
|
|
52218
|
+
for (let i = 0; i < x.length; i++) {
|
|
52219
|
+
const xi = x[i];
|
|
52220
|
+
const p = alpha[i] - 1;
|
|
52221
|
+
if (p !== 0) {
|
|
52222
|
+
logpdf += p * Math.log(xi);
|
|
52223
|
+
}
|
|
52224
|
+
}
|
|
52225
|
+
return Math.exp(logpdf);
|
|
52226
|
+
}
|
|
52227
|
+
function validateScale(scale4, fn) {
|
|
52228
|
+
if (!Array.isArray(scale4) || scale4.length === 0) {
|
|
52229
|
+
throw new Error(`${fn}: scale must be a non-empty square matrix`);
|
|
52230
|
+
}
|
|
52231
|
+
const p = scale4.length;
|
|
52232
|
+
for (const row2 of scale4) {
|
|
52233
|
+
if (row2.length !== p) throw new Error(`${fn}: scale must be a ${p}x${p} square matrix`);
|
|
52234
|
+
}
|
|
52235
|
+
for (let i = 0; i < p; i++) {
|
|
52236
|
+
for (let j = i + 1; j < p; j++) {
|
|
52237
|
+
const tol = 1e-9 * (1 + Math.abs(scale4[i][j]));
|
|
52238
|
+
if (Math.abs(scale4[i][j] - scale4[j][i]) > tol) {
|
|
52239
|
+
throw new Error(`${fn}: scale must be symmetric`);
|
|
52240
|
+
}
|
|
52241
|
+
}
|
|
52242
|
+
}
|
|
52243
|
+
return p;
|
|
52244
|
+
}
|
|
52245
|
+
function wishartSample(df, scale4, n = 1, opts) {
|
|
52246
|
+
const p = validateScale(scale4, "wishartSample");
|
|
52247
|
+
if (!(df > p - 1)) {
|
|
52248
|
+
throw new Error(`wishartSample: df must be greater than p\u22121 = ${p - 1}`);
|
|
52249
|
+
}
|
|
52250
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
52251
|
+
throw new Error("wishartSample: n must be a positive integer");
|
|
52252
|
+
}
|
|
52253
|
+
const { L } = cholesky(scale4.map((row2) => [...row2]));
|
|
52254
|
+
const rng = createRng(opts?.seed ?? null);
|
|
52255
|
+
const samples = new Array(n);
|
|
52256
|
+
for (let s = 0; s < n; s++) {
|
|
52257
|
+
const A = Array.from({ length: p }, () => new Array(p).fill(0));
|
|
52258
|
+
for (let i = 0; i < p; i++) {
|
|
52259
|
+
A[i][i] = Math.sqrt(2 * gammaSampleRng((df - i) / 2, rng));
|
|
52260
|
+
for (let j = 0; j < i; j++) A[i][j] = normalSampleRng(rng);
|
|
52261
|
+
}
|
|
52262
|
+
const M = Array.from({ length: p }, () => new Array(p).fill(0));
|
|
52263
|
+
for (let i = 0; i < p; i++) {
|
|
52264
|
+
for (let j = 0; j <= i; j++) {
|
|
52265
|
+
let sum3 = 0;
|
|
52266
|
+
for (let m = j; m <= i; m++) sum3 += L[i][m] * A[m][j];
|
|
52267
|
+
M[i][j] = sum3;
|
|
52268
|
+
}
|
|
52269
|
+
}
|
|
52270
|
+
const W = Array.from({ length: p }, () => new Array(p).fill(0));
|
|
52271
|
+
for (let i = 0; i < p; i++) {
|
|
52272
|
+
for (let j = i; j < p; j++) {
|
|
52273
|
+
let sum3 = 0;
|
|
52274
|
+
const lim = Math.min(i, j);
|
|
52275
|
+
for (let m = 0; m <= lim; m++) sum3 += M[i][m] * M[j][m];
|
|
52276
|
+
W[i][j] = sum3;
|
|
52277
|
+
W[j][i] = sum3;
|
|
52278
|
+
}
|
|
52279
|
+
}
|
|
52280
|
+
samples[s] = W;
|
|
52281
|
+
}
|
|
52282
|
+
return samples;
|
|
52283
|
+
}
|
|
51962
52284
|
export {
|
|
51963
52285
|
ARRAY_WORKER_THRESHOLD,
|
|
51964
52286
|
CAS_BATCH_THRESHOLD,
|
|
@@ -52193,6 +52515,8 @@ export {
|
|
|
52193
52515
|
differences,
|
|
52194
52516
|
digamma,
|
|
52195
52517
|
directionalDerivative,
|
|
52518
|
+
dirichletPdf,
|
|
52519
|
+
dirichletSample,
|
|
52196
52520
|
disableGpu,
|
|
52197
52521
|
discreteLog,
|
|
52198
52522
|
discreteUniformDist,
|
|
@@ -52382,6 +52706,7 @@ export {
|
|
|
52382
52706
|
gasConstant,
|
|
52383
52707
|
gaussQuad,
|
|
52384
52708
|
gaussianKDE,
|
|
52709
|
+
gaussianProcessRegression,
|
|
52385
52710
|
gcd,
|
|
52386
52711
|
gegenbauerC,
|
|
52387
52712
|
generalizedEig,
|
|
@@ -52394,6 +52719,7 @@ export {
|
|
|
52394
52719
|
gmean,
|
|
52395
52720
|
gmres,
|
|
52396
52721
|
goertzel,
|
|
52722
|
+
gpRegression,
|
|
52397
52723
|
gpuAdd,
|
|
52398
52724
|
gpuMatmul,
|
|
52399
52725
|
gpuScale,
|
|
@@ -52441,6 +52767,8 @@ export {
|
|
|
52441
52767
|
ifftshift2 as ifftshift,
|
|
52442
52768
|
im,
|
|
52443
52769
|
implicitDiff,
|
|
52770
|
+
incompleteCholesky,
|
|
52771
|
+
incompleteLU,
|
|
52444
52772
|
indexFn as index,
|
|
52445
52773
|
indexFn,
|
|
52446
52774
|
initializePool,
|
|
@@ -52906,6 +53234,7 @@ export {
|
|
|
52906
53234
|
sum,
|
|
52907
53235
|
summation,
|
|
52908
53236
|
svd4 as svd,
|
|
53237
|
+
svds,
|
|
52909
53238
|
sylvester,
|
|
52910
53239
|
symbolicEqual,
|
|
52911
53240
|
symbolicIntegral,
|
|
@@ -52988,6 +53317,7 @@ export {
|
|
|
52988
53317
|
wiener,
|
|
52989
53318
|
wilcoxon,
|
|
52990
53319
|
windowFunction,
|
|
53320
|
+
wishartSample,
|
|
52991
53321
|
xgcd,
|
|
52992
53322
|
xor,
|
|
52993
53323
|
zTransform,
|
package/dist/linalg-extra.d.ts
CHANGED
|
@@ -2,8 +2,12 @@ type Vec = readonly number[] | Float64Array;
|
|
|
2
2
|
/**
|
|
3
3
|
* Generalized eigenvalues of the pencil `A x = λ B x` (B nonsingular), via the
|
|
4
4
|
* eigendecomposition of `B⁻¹A` — reusing `inv`, `multiply`, and the corrected
|
|
5
|
-
* `eigs
|
|
6
|
-
*
|
|
5
|
+
* `eigs` (Hessenberg + Francis double-shift). Eigenvalues match
|
|
6
|
+
* `scipy.linalg.eig(A, B)` across real, complex-pair and clustered spectra. For
|
|
7
|
+
* a *singular* or numerically near-singular `B` this squaring-free QZ formulation
|
|
8
|
+
* breaks down; extracting the pencil eigenvalues directly from the {@link qz}
|
|
9
|
+
* factors (`diag AA / diag BB`, with 2×2-block handling for complex pairs) is the
|
|
10
|
+
* future enhancement for that regime.
|
|
7
11
|
*/
|
|
8
12
|
export declare function generalizedEig(A: readonly number[][], B: readonly number[][]): {
|
|
9
13
|
values: Array<number | {
|
|
@@ -58,8 +62,10 @@ export declare function logdet(A: readonly number[][]): {
|
|
|
58
62
|
* Generalized (QZ) Schur decomposition of the pencil `(A, B)` with `B` nonsingular:
|
|
59
63
|
* returns orthogonal `Q`, `Z` and upper-(quasi-)triangular `AA`, `BB` with
|
|
60
64
|
* `A = Q·AA·Zᵀ` and `B = Q·BB·Zᵀ`. Built from the real Schur of `B⁻¹A` (= Z S Zᵀ) and
|
|
61
|
-
* the QR of `B·Z` (= Q·BB): then `AA = Qᵀ·A·Z`.
|
|
62
|
-
*
|
|
65
|
+
* the QR of `B·Z` (= Q·BB): then `AA = Qᵀ·A·Z`. The Schur step is the hardened
|
|
66
|
+
* Hessenberg + Francis double-shift `matrixSchur` (see {@link realSchur}), so `qz`
|
|
67
|
+
* no longer stalls on non-symmetric `B⁻¹A` pencils; matches the decomposition
|
|
68
|
+
* contract of `scipy.linalg.qz` (the factors are not unique).
|
|
63
69
|
*/
|
|
64
70
|
export declare function qz(A: readonly number[][], B: readonly number[][]): {
|
|
65
71
|
AA: number[][];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linalg-extra.d.ts","sourceRoot":"","sources":["../src/linalg-extra.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"linalg-extra.d.ts","sourceRoot":"","sources":["../src/linalg-extra.ts"],"names":[],"mappings":"AAuCA,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAG5C;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EACtB,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,GACrB;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,CAIhF;AAED,+EAA+E;AAC/E,wBAAgB,IAAI,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,SAAI,GAAG,MAAM,EAAE,EAAE,CAE9D;AAED,+EAA+E;AAC/E,wBAAgB,IAAI,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EAA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x -> A x`. */
|
|
17
17
|
export type LinearOperatorInput = number[][] | ((x: number[]) => number[]);
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Preconditioner. The three built-ins require a dense matrix (they read `A`'s
|
|
20
|
+
* entries): `'jacobi'` (diagonal `M⁻¹ = diag(1/Aᵢᵢ)`), `'ilu'` (ILU(0) —
|
|
21
|
+
* incomplete LU with zero fill on `A`'s sparsity pattern, for general `A`),
|
|
22
|
+
* `'ic'` (IC(0) — incomplete Cholesky, for symmetric positive-definite `A`).
|
|
23
|
+
* Or pass a custom `M⁻¹` callback (the only option that works with a
|
|
24
|
+
* matvec-only operator).
|
|
25
|
+
*/
|
|
26
|
+
export type Preconditioner = 'jacobi' | 'ilu' | 'ic' | ((r: number[]) => number[]);
|
|
20
27
|
/** Common options accepted by every solver in this module. */
|
|
21
28
|
export interface KrylovOptions {
|
|
22
29
|
/** Initial guess (default: the zero vector). */
|
|
@@ -44,6 +51,31 @@ export interface KrylovResult {
|
|
|
44
51
|
/** Final relative residual `‖b − A x‖₂ / ‖b‖₂`. */
|
|
45
52
|
residual: number;
|
|
46
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* ILU(0) — incomplete LU factorization with zero fill. Returns unit-lower `L`
|
|
56
|
+
* and upper `U` (dense, with zeros outside `A`'s sparsity pattern) such that
|
|
57
|
+
* `(L·U)ᵢⱼ = Aᵢⱼ` on that pattern, dropping any fill that would arise outside
|
|
58
|
+
* it. The classic preconditioner for iterative solvers on general sparse `A`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* incompleteLU([[4,1,0],[1,4,1],[0,1,4]]) // tridiagonal → exact LU (no fill)
|
|
62
|
+
*/
|
|
63
|
+
export declare function incompleteLU(a: readonly number[][]): {
|
|
64
|
+
L: number[][];
|
|
65
|
+
U: number[][];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* IC(0) — incomplete Cholesky factorization with zero fill, for symmetric
|
|
69
|
+
* positive-definite `A`. Returns lower-triangular `L` on `A`'s sparsity pattern
|
|
70
|
+
* with `(L·Lᵀ)ᵢⱼ = Aᵢⱼ` there. Throws on a non-positive pivot (the `A`-is-SPD
|
|
71
|
+
* precondition failed).
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* incompleteCholesky([[4,1,0],[1,4,1],[0,1,4]]) // tridiagonal → exact Cholesky
|
|
75
|
+
*/
|
|
76
|
+
export declare function incompleteCholesky(a: readonly number[][]): {
|
|
77
|
+
L: number[][];
|
|
78
|
+
};
|
|
47
79
|
/**
|
|
48
80
|
* Conjugate Gradient (CG) — for symmetric positive-definite `A`.
|
|
49
81
|
*
|
|
@@ -54,13 +86,19 @@ export declare function cg(a: LinearOperatorInput, b: number[], opts?: KrylovOpt
|
|
|
54
86
|
/**
|
|
55
87
|
* MINRES — for symmetric (possibly indefinite) `A`.
|
|
56
88
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
89
|
+
* The Paige–Saunders short-recurrence MINRES (Paige & Saunders 1975): a
|
|
90
|
+
* preconditioned Lanczos tridiagonalization coupled with an incrementally
|
|
91
|
+
* updated Givens-rotation QR of the tridiagonal. Each iteration does a fixed
|
|
92
|
+
* number of length-`n` vector operations (one matvec + a handful of `axpy`s)
|
|
93
|
+
* and **O(1)** scalar work — no growing least-squares is ever formed or
|
|
94
|
+
* solved. The solution is advanced through a running 3-term `w`-recurrence, so
|
|
95
|
+
* the whole solve is **O(k·n)** for `k` iterations rather than the O(k³) of the
|
|
96
|
+
* former "re-solve the growing `(k+1)×k` tridiagonal each step" formulation.
|
|
97
|
+
*
|
|
98
|
+
* With a preconditioner `M`, the loop converges the `M⁻¹`-norm relative
|
|
99
|
+
* residual `‖r_k‖_{M⁻¹} / ‖r_0‖_{M⁻¹}` (the estimate MINRES minimizes); for
|
|
100
|
+
* `M = I` this equals `‖b − A x‖₂ / ‖b‖₂`. The reported `residual`/`converged`
|
|
101
|
+
* are always computed from the true Euclidean residual (one final matvec).
|
|
64
102
|
*
|
|
65
103
|
* @example
|
|
66
104
|
* minres([[0, 1], [1, 0]], [1, 2]) // => { x: [2, 1], converged: true, ... }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"krylov.d.ts","sourceRoot":"","sources":["../../src/numeric/krylov.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,GAAG,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AAE3E
|
|
1
|
+
{"version":3,"file":"krylov.d.ts","sourceRoot":"","sources":["../../src/numeric/krylov.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,GAAG,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AAE3E;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AAEnF,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACd,+DAA+D;IAC/D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,4DAA4D;AAC5D,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sDAAsD;AAC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
|
+
/** Convergence tolerance forwarded to the Lanczos eigensolver (default 1e-10). */
|
|
4
|
+
tol?: number;
|
|
5
|
+
/** Maximum Lanczos steps (default `min(max(2k + 20, 20), dim)`). */
|
|
6
|
+
maxIter?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Result of {@link svds}. Singular values are returned **descending**
|
|
10
|
+
* (`s[0]` largest — matching this library's full {@link svd}); note this is the
|
|
11
|
+
* opposite of `scipy.sparse.linalg.svds`, which returns them ascending.
|
|
12
|
+
* Singular vectors are stored as **columns**: `U[i][j]` is the `i`-th component
|
|
13
|
+
* of the `j`-th left singular vector (for `s[j]`), and likewise `V` for the
|
|
14
|
+
* right singular vectors.
|
|
15
|
+
*/
|
|
16
|
+
export interface SvdsResult {
|
|
17
|
+
/** Left singular vectors, `m × k`, as columns. */
|
|
18
|
+
U: number[][];
|
|
19
|
+
/** The `k` largest singular values, descending. */
|
|
20
|
+
s: number[];
|
|
21
|
+
/** Right singular vectors, `n × k`, as columns. */
|
|
22
|
+
V: number[][];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The `k` largest singular triplets of `A` (dense `m × n`) via Lanczos on the
|
|
26
|
+
* smaller normal operator.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* svds([[1,2,0],[0,3,1],[4,0,2]], 2) // => { U, s: [σ₁, σ₂] (descending), V }
|
|
30
|
+
*/
|
|
31
|
+
export declare function svds(A: number[][], k?: number, opts?: SvdsOptions): SvdsResult;
|
|
32
|
+
//# sourceMappingURL=svds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svds.d.ts","sourceRoot":"","sources":["../../src/numeric/svds.ts"],"names":[],"mappings":"AAqBA,wCAAwC;AACxC,MAAM,WAAW,WAAW;IAC1B,kFAAkF;IAClF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,kDAAkD;IAClD,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACd,mDAAmD;IACnD,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,mDAAmD;IACnD,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;CACf;AA0BD;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,SAAI,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAkDzE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared RNG-driven Gamma / standard-normal variate generators.
|
|
3
|
+
*
|
|
4
|
+
* Extracted so the distribution objects (`typed/dist-objects.ts`) and the
|
|
5
|
+
* multivariate samplers (`stats/multivariate-sampling.ts`) share ONE
|
|
6
|
+
* Marsaglia & Tsang gamma implementation rather than each carrying a copy.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Standard normal N(0,1) variate via Box-Muller, driven by a caller-supplied
|
|
10
|
+
* uniform PRNG (so seeded draws are reproducible). Guards `log(0)`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalSampleRng(rng: () => number): number;
|
|
13
|
+
/**
|
|
14
|
+
* Gamma(alpha, 1) variate (shape `alpha`, unit scale) via Marsaglia & Tsang's
|
|
15
|
+
* method, driven by a caller-supplied uniform PRNG. For `alpha < 1` it uses the
|
|
16
|
+
* boosting identity `Gamma(a) = Gamma(a+1)·U^(1/a)`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function gammaSampleRng(alpha: number, rng: () => number): number;
|
|
19
|
+
//# sourceMappingURL=gammaSample.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gammaSample.d.ts","sourceRoot":"","sources":["../../../src/probability/util/gammaSample.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,MAAM,GAAG,MAAM,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,MAAM,GAAG,MAAM,CAkBvE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Supported covariance kernels. */
|
|
2
|
+
export type GPKernel = 'rbf' | 'matern32' | 'matern52';
|
|
3
|
+
/** Options for {@link gaussianProcessRegression}. */
|
|
4
|
+
export interface GPOptions {
|
|
5
|
+
/** Covariance kernel. Default `'rbf'` (squared-exponential). */
|
|
6
|
+
kernel?: GPKernel;
|
|
7
|
+
/** Kernel length-scale ℓ (> 0). Default `1`. */
|
|
8
|
+
lengthScale?: number;
|
|
9
|
+
/** Signal variance σ_f² (kernel amplitude, > 0). Default `1`. */
|
|
10
|
+
signalVariance?: number;
|
|
11
|
+
/** I.i.d. Gaussian noise variance α added to the diagonal (≥ 0). Default `1e-10`. */
|
|
12
|
+
noise?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Posterior prediction at a set of test points. */
|
|
15
|
+
export interface GPPrediction {
|
|
16
|
+
/** Posterior mean at each test point. */
|
|
17
|
+
mean: number[];
|
|
18
|
+
/** Posterior variance at each test point (≥ 0). */
|
|
19
|
+
variance: number[];
|
|
20
|
+
/** Posterior standard deviation at each test point (= √variance). */
|
|
21
|
+
std: number[];
|
|
22
|
+
}
|
|
23
|
+
/** A fitted Gaussian-process regressor. */
|
|
24
|
+
export interface GPModel {
|
|
25
|
+
/** Predict the posterior mean/variance/std at the given test points. */
|
|
26
|
+
predict(Xstar: readonly (readonly number[])[]): GPPrediction;
|
|
27
|
+
/** Log marginal likelihood log p(y | X) of the training data under the prior. */
|
|
28
|
+
logMarginalLikelihood: number;
|
|
29
|
+
/** The resolved kernel name. */
|
|
30
|
+
kernel: GPKernel;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Fit a Gaussian-process regressor to training points `X` (array of
|
|
34
|
+
* length-d feature vectors) and targets `y`, then return a model exposing
|
|
35
|
+
* `.predict(Xstar)` (posterior mean/variance/std) and the log marginal
|
|
36
|
+
* likelihood.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const gp = gaussianProcessRegression(
|
|
40
|
+
* [[-4], [-3], [-1], [0], [2]],
|
|
41
|
+
* [-2, 0, 1, 2, -1],
|
|
42
|
+
* { kernel: 'rbf', lengthScale: 1.2, signalVariance: 1.5, noise: 1e-2 }
|
|
43
|
+
* );
|
|
44
|
+
* gp.predict([[-0.5], [10]]); // mean ≈ [1.5872, ~0], std ≈ [0.1453, 1.2247]
|
|
45
|
+
*/
|
|
46
|
+
export declare function gaussianProcessRegression(X: readonly (readonly number[])[], y: readonly number[], options?: GPOptions): GPModel;
|
|
47
|
+
/** Alias of {@link gaussianProcessRegression}. */
|
|
48
|
+
export declare const gpRegression: typeof gaussianProcessRegression;
|
|
49
|
+
//# sourceMappingURL=gaussian-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gaussian-process.d.ts","sourceRoot":"","sources":["../../src/stats/gaussian-process.ts"],"names":[],"mappings":"AAuBA,oCAAoC;AACpC,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;AAEvD,qDAAqD;AACrD,MAAM,WAAW,SAAS;IACxB,gEAAgE;IAChE,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,mDAAmD;IACnD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,qEAAqE;IACrE,GAAG,EAAE,MAAM,EAAE,CAAC;CACf;AAED,2CAA2C;AAC3C,MAAM,WAAW,OAAO;IACtB,wEAAwE;IACxE,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC;IAC7D,iFAAiF;IACjF,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gCAAgC;IAChC,MAAM,EAAE,QAAQ,CAAC;CAClB;AA0FD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CACvC,CAAC,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACjC,CAAC,EAAE,SAAS,MAAM,EAAE,EACpB,OAAO,GAAE,SAAc,GACtB,OAAO,CAoET;AAED,kDAAkD;AAClD,eAAO,MAAM,YAAY,kCAA4B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Options for the multivariate samplers (shared shape with mvnSample). */
|
|
2
|
+
export interface SampleSeedOptions {
|
|
3
|
+
/** Seed for the deterministic RNG (reproducible draws). Omit for a
|
|
4
|
+
* time-seeded, non-reproducible generator. */
|
|
5
|
+
seed?: string | number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Draw `n` samples from a Dirichlet(`alpha`) distribution via the
|
|
9
|
+
* Gamma-normalization method. Each sample is a length-k vector on the simplex
|
|
10
|
+
* (non-negative, summing to 1). Returns an `n`-length array of length-k vectors.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* dirichletSample([2, 3, 5], 10000, { seed: 42 });
|
|
14
|
+
* // empirical mean ≈ [0.2, 0.3, 0.5] = αᵢ / Σα
|
|
15
|
+
*/
|
|
16
|
+
export declare function dirichletSample(alpha: readonly number[], n?: number, opts?: SampleSeedOptions): number[][];
|
|
17
|
+
/**
|
|
18
|
+
* Dirichlet(`alpha`) probability density at a point `x` on the simplex.
|
|
19
|
+
* `pdf(x) = (1 / B(α)) · Πᵢ xᵢ^(αᵢ−1)` with
|
|
20
|
+
* `B(α) = Πᵢ Γ(αᵢ) / Γ(Σαᵢ)`. Matches `scipy.stats.dirichlet.pdf`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* dirichletPdf([0.2, 0.3, 0.5], [2, 3, 4]); // 7.56
|
|
24
|
+
*/
|
|
25
|
+
export declare function dirichletPdf(x: readonly number[], alpha: readonly number[]): number;
|
|
26
|
+
/**
|
|
27
|
+
* Draw `n` samples from a Wishart(`df`, `scale`) distribution via the Bartlett
|
|
28
|
+
* decomposition: with `L = chol(scale)` and a lower-triangular `A` whose
|
|
29
|
+
* diagonal entries are `√χ²(df−i)` (0-indexed) and whose strictly-lower entries
|
|
30
|
+
* are N(0,1), each sample is `W = (L·A)(L·A)ᵀ` — a `p×p` symmetric
|
|
31
|
+
* positive-definite matrix. Returns an `n`-length array of `p×p` matrices.
|
|
32
|
+
*
|
|
33
|
+
* `df` must exceed `p − 1` (so every χ² degree-of-freedom is positive). The
|
|
34
|
+
* mean of the distribution is `df · scale`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* wishartSample(6, [[2, 0.5], [0.5, 1]], 10000, { seed: 7 });
|
|
38
|
+
* // empirical mean ≈ [[12, 3], [3, 6]] = df · scale
|
|
39
|
+
*/
|
|
40
|
+
export declare function wishartSample(df: number, scale: readonly (readonly number[])[], n?: number, opts?: SampleSeedOptions): number[][][];
|
|
41
|
+
//# sourceMappingURL=multivariate-sampling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multivariate-sampling.d.ts","sourceRoot":"","sources":["../../src/stats/multivariate-sampling.ts"],"names":[],"mappings":"AAuBA,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IAChC;kDAC8C;IAC9C,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAaD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,CAAC,SAAI,EACL,IAAI,CAAC,EAAE,iBAAiB,GACvB,MAAM,EAAE,EAAE,CAqBZ;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAkCnF;AAqBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACrC,CAAC,SAAI,EACL,IAAI,CAAC,EAAE,iBAAiB,GACvB,MAAM,EAAE,EAAE,EAAE,CA0Cd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dist-objects.d.ts","sourceRoot":"","sources":["../../src/typed/dist-objects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;
|
|
1
|
+
{"version":3,"file":"dist-objects.d.ts","sourceRoot":"","sources":["../../src/typed/dist-objects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAUH,0CAA0C;AAC1C,KAAK,GAAG,GAAG,MAAM,CAAC;AAElB;;;GAGG;AACH,eAAO,MAAM,qBAAqB,SAAU,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;IACrB,uCAAuC;IACvC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;IACrB,sCAAsC;IACtC,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;IAC1B,wBAAwB;IACx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