@numero-uno-jpn/rstats 0.11.0 → 0.11.1
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/CHANGELOG.md +13 -0
- package/README.ja.md +5 -4
- package/README.md +6 -4
- package/dist/chunks/{chunk-YSWGDOWK.js → chunk-2X7JYQBI.js} +2 -2
- package/dist/chunks/{chunk-F5EDJFEO.js → chunk-36GVER3O.js} +2 -2
- package/dist/chunks/{chunk-7GQMKH3Z.js → chunk-3WUXRSM6.js} +1 -1
- package/dist/chunks/{chunk-JWBO5WVN.js → chunk-6I6QKTFK.js} +2 -2
- package/dist/chunks/{chunk-EZWBRCJL.js → chunk-ETOEZTGL.js} +1 -1
- package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-FVPDVRJQ.js} +2 -2
- package/dist/chunks/{chunk-EZAFN5CD.js → chunk-GG4BJMJW.js} +1 -1
- package/dist/chunks/{chunk-5WDJPHYY.js → chunk-HITD7CX6.js} +1 -1
- package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-KK4GE65D.js} +2 -2
- package/dist/chunks/{chunk-AHHS6AC4.js → chunk-LAUYSGV4.js} +2 -2
- package/dist/chunks/{chunk-ALM3VHFP.js → chunk-M6GDXKKS.js} +1 -1
- package/dist/chunks/{chunk-C5XTWMGB.js → chunk-PHHUHR7T.js} +1 -1
- package/dist/chunks/{chunk-TOGXTCZO.js → chunk-WQPFDDIY.js} +2 -2
- package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-X2AWQSVS.js} +2 -2
- package/dist/chunks/{chunk-Y5CNQ266.js → chunk-ZRJQD7VS.js} +2 -2
- package/dist/data/grouping.d.ts +33 -12
- package/dist/data/grouping.js +2 -0
- package/dist/descriptive/basic.d.ts +130 -17
- package/dist/descriptive/basic.js +115 -14
- package/dist/descriptive/cov.d.ts +22 -12
- package/dist/descriptive/dataFrames.d.ts +39 -11
- package/dist/descriptive/dataFrames.js +14 -6
- package/dist/descriptive/factanal.d.ts +26 -6
- package/dist/descriptive/factanal.js +7 -3
- package/dist/descriptive/hist.d.ts +27 -6
- package/dist/descriptive/hist.js +9 -3
- package/dist/descriptive/missing.d.ts +13 -6
- package/dist/descriptive/missing.js +4 -2
- package/dist/descriptive/moments.d.ts +91 -13
- package/dist/descriptive/moments.js +66 -9
- package/dist/descriptive/omega.d.ts +28 -6
- package/dist/descriptive/omega.js +16 -4
- package/dist/descriptive/pivot.d.ts +22 -6
- package/dist/descriptive/pivot.js +7 -3
- package/dist/descriptive/quantile.d.ts +33 -5
- package/dist/descriptive/quantile.js +20 -2
- package/dist/descriptive/rank.d.ts +12 -2
- package/dist/descriptive/rank.js +2 -0
- package/dist/descriptive/table.d.ts +55 -7
- package/dist/descriptive/table.js +38 -4
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.d.ts +40 -5
- package/dist/distributions/arcsine.js +35 -4
- package/dist/distributions/beta.d.ts +12 -0
- package/dist/distributions/beta.js +12 -0
- package/dist/distributions/binomial.d.ts +18 -0
- package/dist/distributions/binomial.js +18 -0
- package/dist/distributions/bvnorm.d.ts +4 -1
- package/dist/distributions/bvnorm.js +4 -1
- package/dist/distributions/cauchy.d.ts +24 -0
- package/dist/distributions/cauchy.js +24 -0
- package/dist/distributions/chisq.d.ts +18 -0
- package/dist/distributions/chisq.js +18 -0
- package/dist/distributions/exponential.d.ts +29 -1
- package/dist/distributions/exponential.js +24 -0
- package/dist/distributions/f.d.ts +18 -0
- package/dist/distributions/f.js +18 -0
- package/dist/distributions/gamma.d.ts +20 -0
- package/dist/distributions/gamma.js +18 -0
- package/dist/distributions/geometric.d.ts +24 -0
- package/dist/distributions/geometric.js +24 -0
- package/dist/distributions/hypergeometric.d.ts +24 -0
- package/dist/distributions/hypergeometric.js +24 -0
- package/dist/distributions/invgamma.d.ts +32 -4
- package/dist/distributions/invgamma.js +27 -3
- package/dist/distributions/kumaraswamy.d.ts +31 -3
- package/dist/distributions/kumaraswamy.js +31 -3
- package/dist/distributions/laplace.d.ts +36 -4
- package/dist/distributions/laplace.js +31 -3
- package/dist/distributions/logistic.d.ts +29 -1
- package/dist/distributions/logistic.js +24 -0
- package/dist/distributions/lognormal.d.ts +29 -1
- package/dist/distributions/lognormal.js +24 -0
- package/dist/distributions/multinomial.d.ts +7 -1
- package/dist/distributions/multinomial.js +2 -0
- package/dist/distributions/negbinomial.d.ts +29 -1
- package/dist/distributions/negbinomial.js +24 -0
- package/dist/distributions/normal.d.ts +11 -1
- package/dist/distributions/normal.js +6 -0
- package/dist/distributions/pareto.d.ts +36 -4
- package/dist/distributions/pareto.js +31 -3
- package/dist/distributions/poisson.d.ts +18 -0
- package/dist/distributions/poisson.js +18 -0
- package/dist/distributions/signrank.d.ts +24 -0
- package/dist/distributions/signrank.js +24 -0
- package/dist/distributions/summary.d.ts +20 -2
- package/dist/distributions/summary.js +4 -0
- package/dist/distributions/t.d.ts +18 -0
- package/dist/distributions/t.js +18 -0
- package/dist/distributions/triangular.d.ts +36 -4
- package/dist/distributions/triangular.js +31 -3
- package/dist/distributions/tukey.d.ts +15 -1
- package/dist/distributions/tukey.js +10 -0
- package/dist/distributions/uniform.d.ts +29 -1
- package/dist/distributions/uniform.js +24 -0
- package/dist/distributions/weibull.d.ts +29 -1
- package/dist/distributions/weibull.js +24 -0
- package/dist/distributions/wilcox.d.ts +24 -0
- package/dist/distributions/wilcox.js +24 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +1 -1
- package/dist/entries/numerics.d.ts +1 -1
- package/dist/entries/tests.js +1 -1
- package/dist/htest/agreement.d.ts +61 -23
- package/dist/htest/agreement.js +19 -9
- package/dist/htest/ansariTest.d.ts +8 -2
- package/dist/htest/aov.d.ts +43 -10
- package/dist/htest/aov.js +17 -3
- package/dist/htest/binomTest.d.ts +12 -2
- package/dist/htest/binomTest.js +2 -0
- package/dist/htest/brunnerMunzelTest.d.ts +9 -3
- package/dist/htest/brunnerMunzelTest.js +4 -2
- package/dist/htest/chisqTest.d.ts +19 -3
- package/dist/htest/cor.d.ts +20 -4
- package/dist/htest/effectSize.d.ts +70 -12
- package/dist/htest/effectSize.js +40 -7
- package/dist/htest/fisherTest.d.ts +9 -1
- package/dist/htest/fisherTest.js +2 -0
- package/dist/htest/groups.d.ts +5 -1
- package/dist/htest/ksTest.d.ts +20 -3
- package/dist/htest/leveneTest.d.ts +15 -4
- package/dist/htest/leveneTest.js +5 -2
- package/dist/htest/mantelhaenTest.d.ts +25 -3
- package/dist/htest/mantelhaenTest.js +15 -1
- package/dist/htest/mcnemarTest.d.ts +14 -4
- package/dist/htest/mcnemarTest.js +4 -2
- package/dist/htest/multipleComparisons.d.ts +173 -29
- package/dist/htest/multipleComparisons.js +123 -19
- package/dist/htest/normalityTests.d.ts +56 -9
- package/dist/htest/normalityTests.js +40 -6
- package/dist/htest/onewayTest.d.ts +32 -3
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.d.ts +9 -1
- package/dist/htest/pAdjust.js +2 -0
- package/dist/htest/pairwise.d.ts +50 -5
- package/dist/htest/pairwise.js +25 -0
- package/dist/htest/poissonTest.d.ts +12 -2
- package/dist/htest/poissonTest.js +2 -0
- package/dist/htest/polycor.d.ts +29 -10
- package/dist/htest/power.d.ts +60 -6
- package/dist/htest/power.js +6 -0
- package/dist/htest/propTest.d.ts +13 -2
- package/dist/htest/propTest.js +2 -0
- package/dist/htest/pwr.d.ts +286 -36
- package/dist/htest/pwr.js +116 -15
- package/dist/htest/rankTests.d.ts +80 -12
- package/dist/htest/rankTests.js +11 -2
- package/dist/htest/tTest.d.ts +13 -3
- package/dist/htest/trendTests.d.ts +29 -8
- package/dist/htest/trendTests.js +8 -4
- package/dist/htest/types.d.ts +14 -2
- package/dist/htest/varTest.d.ts +25 -8
- package/dist/htest/wilcoxTest.d.ts +10 -2
- package/dist/internal/dpq.d.ts +4 -0
- package/dist/internal/noncentral.d.ts +2 -0
- package/dist/internal/vectorize.d.ts +4 -0
- package/dist/linalg/basic.d.ts +39 -5
- package/dist/linalg/basic.js +15 -0
- package/dist/linalg/chol.d.ts +26 -5
- package/dist/linalg/chol.js +7 -0
- package/dist/linalg/eigen.d.ts +16 -7
- package/dist/linalg/eigen.js +6 -5
- package/dist/linalg/expm.d.ts +15 -5
- package/dist/linalg/expm.js +5 -3
- package/dist/linalg/kappa.d.ts +21 -1
- package/dist/linalg/kappa.js +16 -0
- package/dist/linalg/lu.d.ts +30 -6
- package/dist/linalg/lu.js +15 -3
- package/dist/linalg/matrix.d.ts +4 -0
- package/dist/linalg/norm.d.ts +16 -1
- package/dist/linalg/norm.js +9 -0
- package/dist/linalg/ops.d.ts +156 -35
- package/dist/linalg/ops.js +96 -15
- package/dist/linalg/qr.d.ts +87 -12
- package/dist/linalg/qr.js +31 -0
- package/dist/linalg/schur.d.ts +8 -2
- package/dist/linalg/schur.js +3 -1
- package/dist/linalg/solve.d.ts +42 -6
- package/dist/linalg/solve.js +22 -0
- package/dist/linalg/svd.d.ts +12 -2
- package/dist/linalg/svd.js +2 -0
- package/dist/linalg.js +2 -2
- package/dist/models/anovaSequential.d.ts +26 -4
- package/dist/models/anovaSequential.js +3 -1
- package/dist/models/aovEz.d.ts +29 -6
- package/dist/models/aovEz.js +5 -2
- package/dist/models/aovStrata.d.ts +12 -2
- package/dist/models/carAnova.d.ts +9 -3
- package/dist/models/carAnova.js +4 -2
- package/dist/models/coxph.d.ts +33 -7
- package/dist/models/coxph.js +8 -3
- package/dist/models/glm.d.ts +128 -21
- package/dist/models/glm.js +71 -14
- package/dist/models/glmAnova.d.ts +30 -5
- package/dist/models/glmAnova.js +15 -2
- package/dist/models/glmConfint.d.ts +16 -2
- package/dist/models/glmConfint.js +9 -1
- package/dist/models/glmFamily.d.ts +27 -5
- package/dist/models/lm.d.ts +75 -17
- package/dist/models/lm.js +22 -4
- package/dist/models/mauchly.d.ts +20 -5
- package/dist/models/mauchly.js +7 -3
- package/dist/models/modelFrame.d.ts +5 -1
- package/dist/models/modelMatrix.d.ts +18 -4
- package/dist/models/modelMatrix.js +3 -1
- package/dist/models/survival.d.ts +41 -9
- package/dist/models/survival.js +10 -4
- package/dist/numerics/deriv.d.ts +21 -6
- package/dist/numerics/deriv.js +16 -5
- package/dist/numerics/integrate.d.ts +37 -7
- package/dist/numerics/integrate.js +8 -2
- package/dist/numerics/interp.d.ts +63 -12
- package/dist/numerics/interp.js +30 -6
- package/dist/numerics/ode.d.ts +15 -5
- package/dist/numerics/ode.js +5 -3
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.d.ts +32 -8
- package/dist/optim/optim.js +8 -4
- package/dist/random/beta.d.ts +8 -0
- package/dist/random/beta.js +8 -0
- package/dist/random/binomial.d.ts +16 -0
- package/dist/random/binomial.js +16 -0
- package/dist/random/continuous.d.ts +51 -0
- package/dist/random/continuous.js +51 -0
- package/dist/random/extra.d.ts +66 -6
- package/dist/random/extra.js +66 -6
- package/dist/random/gamma.d.ts +33 -0
- package/dist/random/gamma.js +33 -0
- package/dist/random/hyper.d.ts +8 -0
- package/dist/random/hyper.js +8 -0
- package/dist/random/poisson.d.ts +25 -0
- package/dist/random/poisson.js +25 -0
- package/dist/random/r2dtable.d.ts +2 -0
- package/dist/random/r2dtable.js +2 -0
- package/dist/random/rank.d.ts +16 -0
- package/dist/random/rank.js +16 -0
- package/dist/random/rng.d.ts +49 -6
- package/dist/random/rng.js +29 -2
- package/dist/random/sample.d.ts +10 -2
- package/dist/random/sample.js +5 -1
- package/dist/random/streams.d.ts +13 -0
- package/dist/random/streams.js +13 -0
- package/dist/rstats.js +1 -1
- package/dist/special/besselIK.d.ts +11 -3
- package/dist/special/besselIK.js +6 -2
- package/dist/special/besselJY.d.ts +6 -2
- package/dist/special/besselJY.js +6 -2
- package/dist/special/beta.d.ts +16 -2
- package/dist/special/beta.js +16 -2
- package/dist/special/choose.d.ts +13 -5
- package/dist/special/choose.js +13 -5
- package/dist/special/erf.d.ts +8 -3
- package/dist/special/erf.js +8 -3
- package/dist/special/extra.d.ts +30 -10
- package/dist/special/extra.js +25 -9
- package/dist/special/gamma.d.ts +18 -2
- package/dist/special/gamma.js +18 -2
- package/dist/special/log1p.d.ts +16 -7
- package/dist/special/log1p.js +16 -7
- package/dist/special/psigamma.d.ts +9 -3
- package/dist/special/psigamma.js +9 -3
- package/dist/special/rCompatible.d.ts +5 -1
- package/dist/special.js +2 -2
- package/dist/tests.js +2 -2
- package/llms.txt +2 -0
- package/package.json +1 -1
package/dist/htest/varTest.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { DataFrame } from "../models/modelFrame.js";
|
|
2
2
|
import { type Alternative, type HTest, type Sample } from "./types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link varTest}.
|
|
5
|
+
*
|
|
6
|
+
* @category Hypothesis tests
|
|
7
|
+
*/
|
|
4
8
|
export interface VarTestOptions {
|
|
5
9
|
/** Hypothesized ratio of the variances of `x` and `y`. Default `1`. */
|
|
6
10
|
ratio?: number;
|
|
@@ -9,10 +13,15 @@ export interface VarTestOptions {
|
|
|
9
13
|
/** Confidence level of the interval. Default `0.95`. */
|
|
10
14
|
confLevel?: number;
|
|
11
15
|
}
|
|
12
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Result of {@link varTest}. The F distribution has two degrees of freedom, so `parameter` is a pair.
|
|
18
|
+
*
|
|
19
|
+
* @category Hypothesis tests
|
|
20
|
+
*/
|
|
13
21
|
export interface VarTestResult extends Omit<HTest, "parameter" | "parameterName"> {
|
|
14
22
|
/** `[num df, denom df]`. */
|
|
15
23
|
parameter: [number, number];
|
|
24
|
+
/** Names of `parameter`: `["num df", "denom df"]`. */
|
|
16
25
|
parameterName: [string, string];
|
|
17
26
|
confInt: [number, number];
|
|
18
27
|
confLevel: number;
|
|
@@ -26,14 +35,16 @@ export interface VarTestResult extends Omit<HTest, "parameter" | "parameterName"
|
|
|
26
35
|
*
|
|
27
36
|
* @example
|
|
28
37
|
* ```ts
|
|
29
|
-
* varTest([1, 3, 2, 5, 4], [2, 9, 4, 12, 7, 1]).statistic; // 0.
|
|
38
|
+
* varTest([1, 3, 2, 5, 4], [2, 9, 4, 12, 7, 1]).statistic; // 0.13761467889908255
|
|
30
39
|
* ```
|
|
31
40
|
*
|
|
32
41
|
* There is also a formula form, `varTest("y ~ g", data, options)` (next overload).
|
|
42
|
+
*
|
|
43
|
+
* @category Hypothesis tests
|
|
33
44
|
*/
|
|
34
45
|
export declare function varTest(x: Sample, y: Sample, options?: VarTestOptions): VarTestResult;
|
|
35
46
|
/**
|
|
36
|
-
* F test of two variances from a formula and a data frame.
|
|
47
|
+
* F test of two variances from a formula and a data frame. As R's `var.test(formula, data)`: `"y ~ g"`
|
|
37
48
|
* compares the two levels of `g` (the first level is `x`). Only the variables of the formula count: the rows where
|
|
38
49
|
* one of them is missing are dropped.
|
|
39
50
|
*
|
|
@@ -41,14 +52,18 @@ export declare function varTest(x: Sample, y: Sample, options?: VarTestOptions):
|
|
|
41
52
|
* @param data The data frame: an object of columns (`null` or `NaN` for a missing value).
|
|
42
53
|
*/
|
|
43
54
|
export declare function varTest(formula: string, data: DataFrame, options?: VarTestOptions): VarTestResult;
|
|
44
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Result of {@link bartlettTest}. Has no `alternative`, as R's `bartlett.test()` returns none.
|
|
57
|
+
*
|
|
58
|
+
* @category Hypothesis tests
|
|
59
|
+
*/
|
|
45
60
|
export interface BartlettTestResult extends Omit<HTest, "alternative"> {
|
|
46
61
|
/** Degrees of freedom (`parameterName` is `"df"`). */
|
|
47
62
|
parameter: number;
|
|
48
63
|
}
|
|
49
64
|
/**
|
|
50
|
-
* Bartlett's test that the variances of several normal samples are equal. Equivalent to R's `bartlett.test()
|
|
51
|
-
* a list of samples. `NaN` and infinite values are dropped, as in R.
|
|
65
|
+
* Bartlett's test that the variances of several normal samples are equal. Equivalent to R's `bartlett.test()`.
|
|
66
|
+
* Takes a list of samples. `NaN` and infinite values are dropped, as in R.
|
|
52
67
|
*
|
|
53
68
|
* @param groups The samples (at least two), each with at least two finite values.
|
|
54
69
|
*
|
|
@@ -58,10 +73,12 @@ export interface BartlettTestResult extends Omit<HTest, "alternative"> {
|
|
|
58
73
|
* ```
|
|
59
74
|
*
|
|
60
75
|
* There is also a formula form, `bartlettTest("y ~ g", data)` (next overload).
|
|
76
|
+
*
|
|
77
|
+
* @category Hypothesis tests
|
|
61
78
|
*/
|
|
62
79
|
export declare function bartlettTest(groups: readonly Sample[]): BartlettTestResult;
|
|
63
80
|
/**
|
|
64
|
-
* Bartlett's test from a formula and a data frame.
|
|
81
|
+
* Bartlett's test from a formula and a data frame. As R's `bartlett.test(formula, data)`: `"y ~ g"`, one
|
|
65
82
|
* group per level of `g`, in the order of the levels. Only the variables of the formula count: the rows where one of
|
|
66
83
|
* them is missing are dropped.
|
|
67
84
|
*
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { DataFrame } from "../models/modelFrame.js";
|
|
2
2
|
import { type Alternative, type HTest, type Sample } from "./types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link wilcoxTest}.
|
|
5
|
+
*
|
|
6
|
+
* @category Hypothesis tests
|
|
7
|
+
*/
|
|
4
8
|
export interface WilcoxTestOptions {
|
|
5
9
|
/**
|
|
6
10
|
* Alternative hypothesis: `"two.sided"`, `"less"` or `"greater"`. Default `"two.sided"`.
|
|
@@ -30,6 +34,8 @@ export interface WilcoxTestOptions {
|
|
|
30
34
|
* Result of {@link wilcoxTest}. `statisticName` is `"V"` for the signed rank test and `"W"`
|
|
31
35
|
* for the rank sum test; `parameter` is not set. `estimate` and `confInt` are set only
|
|
32
36
|
* with `confInt: true`.
|
|
37
|
+
*
|
|
38
|
+
* @category Hypothesis tests
|
|
33
39
|
*/
|
|
34
40
|
export interface WilcoxTestResult extends HTest {
|
|
35
41
|
/** `mu`. */
|
|
@@ -60,10 +66,12 @@ export interface WilcoxTestResult extends HTest {
|
|
|
60
66
|
* ```
|
|
61
67
|
*
|
|
62
68
|
* There is also a formula form, `wilcoxTest("y ~ g", data, options)` (next overload).
|
|
69
|
+
*
|
|
70
|
+
* @category Hypothesis tests
|
|
63
71
|
*/
|
|
64
72
|
export declare function wilcoxTest(x: Sample, y?: Sample | WilcoxTestOptions, options?: WilcoxTestOptions): WilcoxTestResult;
|
|
65
73
|
/**
|
|
66
|
-
* Wilcoxon tests from a formula and a data frame.
|
|
74
|
+
* Wilcoxon tests from a formula and a data frame. As R's `wilcox.test(formula, data)`: `"y ~ g"` is the
|
|
67
75
|
* rank sum test of the two levels of `g` (the first level is `x`), `"y ~ 1"` the signed rank test and
|
|
68
76
|
* `"Pair(a, b) ~ 1"` the paired test of `a` and `b` (the option `paired` is not allowed). Only the variables of the
|
|
69
77
|
* formula count: the rows where one of them is missing are dropped.
|
package/dist/internal/dpq.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Options shared by the distribution (`p*`) and quantile (`q*`) functions.
|
|
3
3
|
* Correspond to R's `lower.tail` and `log.p` arguments.
|
|
4
|
+
*
|
|
5
|
+
* @category Distributions
|
|
4
6
|
*/
|
|
5
7
|
export interface TailOptions {
|
|
6
8
|
/** If `true`, probabilities are P[X <= x]; if `false`, P[X > x]. Default `true`. */
|
|
@@ -11,6 +13,8 @@ export interface TailOptions {
|
|
|
11
13
|
/**
|
|
12
14
|
* Options shared by the density / probability mass (`d*`) functions.
|
|
13
15
|
* Corresponds to R's `log` argument.
|
|
16
|
+
*
|
|
17
|
+
* @category Distributions
|
|
14
18
|
*/
|
|
15
19
|
export interface DensityOptions {
|
|
16
20
|
/** If `true`, return the log of the density (or probability). Default `false`. */
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
* Input accepted as the vectorized first argument of the distribution functions
|
|
3
3
|
* (the counterpart of R's automatic vectorization).
|
|
4
4
|
* A number gives a number, a `number[]` gives a `number[]`, and a `Float64Array` gives a `Float64Array`.
|
|
5
|
+
*
|
|
6
|
+
* @category Distributions
|
|
5
7
|
*/
|
|
6
8
|
export type Vectorizable = number | readonly number[] | Float64Array;
|
|
7
9
|
/**
|
|
8
10
|
* Result type matching the shape of a {@link Vectorizable} input:
|
|
9
11
|
* `number` for a number, `Float64Array` for a `Float64Array`, and `number[]` for an array.
|
|
12
|
+
*
|
|
13
|
+
* @category Distributions
|
|
10
14
|
*/
|
|
11
15
|
export type VectorResult<T extends Vectorizable> = T extends number ? number : T extends Float64Array ? Float64Array : number[];
|
|
12
16
|
export declare function vectorize<T extends Vectorizable>(x: T, f: (v: number) => number): VectorResult<T>;
|
package/dist/linalg/basic.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ import { type Mat, type MatrixInput, type VectorOrMatrix } from "./matrix.js";
|
|
|
7
7
|
* @param x A matrix (array of rows) or a vector.
|
|
8
8
|
* @param y A matrix or a vector with the same number of rows as `x`. Defaults to `x`.
|
|
9
9
|
* @returns The product as an array of rows (`ncol(x)` x `ncol(y)`).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* crossprod([[1, 2], [3, 4]]); // [[10, 14], [14, 20]]
|
|
14
|
+
* crossprod([[1, 2], [3, 4]], [1, 1]); // [[4], [6]]
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @category Linear algebra
|
|
10
18
|
*/
|
|
11
19
|
export declare function crossprod(x: VectorOrMatrix, y?: VectorOrMatrix): number[][];
|
|
12
20
|
/**
|
|
@@ -17,9 +25,20 @@ export declare function crossprod(x: VectorOrMatrix, y?: VectorOrMatrix): number
|
|
|
17
25
|
* @param x A matrix (array of rows) or a vector.
|
|
18
26
|
* @param y A matrix or a vector with the same number of columns as `x`. Defaults to `x`.
|
|
19
27
|
* @returns The product as an array of rows (`nrow(x)` x `nrow(y)`).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* tcrossprod([[1, 2], [3, 4]]); // [[5, 11], [11, 25]]
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @category Linear algebra
|
|
20
35
|
*/
|
|
21
36
|
export declare function tcrossprod(x: VectorOrMatrix, y?: VectorOrMatrix): number[][];
|
|
22
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Options for {@link backsolve} and {@link forwardsolve}.
|
|
39
|
+
*
|
|
40
|
+
* @category Linear algebra
|
|
41
|
+
*/
|
|
23
42
|
export interface BacksolveOptions {
|
|
24
43
|
/** Number of rows and columns of the triangular matrix to use (its top-left `k` x `k` block). Default: the number of columns of the matrix. */
|
|
25
44
|
k?: number;
|
|
@@ -38,10 +57,18 @@ export interface BacksolveOptions {
|
|
|
38
57
|
* @param x The right-hand side vector.
|
|
39
58
|
* @param options See {@link BacksolveOptions}.
|
|
40
59
|
* @returns The solution `y`, a vector of length `k`.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* backsolve([[2, 1], [0, 4]], [4, 8]); // [1, 2]
|
|
64
|
+
* backsolve([[2, 1], [0, 4]], [[4, 2], [8, 4]]); // [[1, 0.5], [2, 1]]
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @category Linear algebra
|
|
41
68
|
*/
|
|
42
69
|
export declare function backsolve(r: MatrixInput, x: readonly number[] | Float64Array, options?: BacksolveOptions): number[];
|
|
43
70
|
/**
|
|
44
|
-
* Solves the triangular system `r y = x` with a matrix right-hand side.
|
|
71
|
+
* Solves the triangular system `r y = x` with a matrix right-hand side.
|
|
45
72
|
*
|
|
46
73
|
* @param r A triangular matrix (array of rows).
|
|
47
74
|
* @param x The right-hand side matrix (array of rows); only its first `k` rows are used.
|
|
@@ -50,7 +77,7 @@ export declare function backsolve(r: MatrixInput, x: readonly number[] | Float64
|
|
|
50
77
|
*/
|
|
51
78
|
export declare function backsolve(r: MatrixInput, x: MatrixInput, options?: BacksolveOptions): number[][];
|
|
52
79
|
/**
|
|
53
|
-
* Solves the triangular system `r y = x`.
|
|
80
|
+
* Solves the triangular system `r y = x`.
|
|
54
81
|
*
|
|
55
82
|
* @param r A triangular matrix (array of rows).
|
|
56
83
|
* @param x The right-hand side, a vector or a matrix.
|
|
@@ -68,10 +95,17 @@ export declare function backsolve(r: MatrixInput, x: VectorOrMatrix, options?: B
|
|
|
68
95
|
* @param x The right-hand side vector.
|
|
69
96
|
* @param options See {@link BacksolveOptions}.
|
|
70
97
|
* @returns The solution `y`, a vector of length `k`.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* forwardsolve([[2, 0], [1, 4]], [4, 10]); // [2, 2]
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @category Linear algebra
|
|
71
105
|
*/
|
|
72
106
|
export declare function forwardsolve(l: MatrixInput, x: readonly number[] | Float64Array, options?: BacksolveOptions): number[];
|
|
73
107
|
/**
|
|
74
|
-
* Solves the triangular system `l y = x` with a matrix right-hand side.
|
|
108
|
+
* Solves the triangular system `l y = x` with a matrix right-hand side.
|
|
75
109
|
*
|
|
76
110
|
* @param l A triangular matrix (array of rows).
|
|
77
111
|
* @param x The right-hand side matrix (array of rows); only its first `k` rows are used.
|
|
@@ -80,7 +114,7 @@ export declare function forwardsolve(l: MatrixInput, x: readonly number[] | Floa
|
|
|
80
114
|
*/
|
|
81
115
|
export declare function forwardsolve(l: MatrixInput, x: MatrixInput, options?: BacksolveOptions): number[][];
|
|
82
116
|
/**
|
|
83
|
-
* Solves the triangular system `l y = x`.
|
|
117
|
+
* Solves the triangular system `l y = x`.
|
|
84
118
|
*
|
|
85
119
|
* @param l A triangular matrix (array of rows).
|
|
86
120
|
* @param x The right-hand side, a vector or a matrix.
|
package/dist/linalg/basic.js
CHANGED
|
@@ -15,6 +15,14 @@ import { fromMat, isMatrixInput, newMat, toMat, toMatOrColumn } from "./matrix.j
|
|
|
15
15
|
* @param x A matrix (array of rows) or a vector.
|
|
16
16
|
* @param y A matrix or a vector with the same number of rows as `x`. Defaults to `x`.
|
|
17
17
|
* @returns The product as an array of rows (`ncol(x)` x `ncol(y)`).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* crossprod([[1, 2], [3, 4]]); // [[10, 14], [14, 20]]
|
|
22
|
+
* crossprod([[1, 2], [3, 4]], [1, 1]); // [[4], [6]]
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @category Linear algebra
|
|
18
26
|
*/
|
|
19
27
|
export function crossprod(x, y) {
|
|
20
28
|
const a = toMatOrColumn(x);
|
|
@@ -46,6 +54,13 @@ export function crossprod(x, y) {
|
|
|
46
54
|
* @param x A matrix (array of rows) or a vector.
|
|
47
55
|
* @param y A matrix or a vector with the same number of columns as `x`. Defaults to `x`.
|
|
48
56
|
* @returns The product as an array of rows (`nrow(x)` x `nrow(y)`).
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* tcrossprod([[1, 2], [3, 4]]); // [[5, 11], [11, 25]]
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @category Linear algebra
|
|
49
64
|
*/
|
|
50
65
|
export function tcrossprod(x, y) {
|
|
51
66
|
const a = toMatOrColumn(x);
|
package/dist/linalg/chol.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { type Mat, type MatrixInput } from "./matrix.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link chol}.
|
|
4
|
+
*
|
|
5
|
+
* @category Linear algebra
|
|
6
|
+
*/
|
|
3
7
|
export interface CholOptions {
|
|
4
8
|
/** Use diagonal pivoting (largest remaining diagonal first), which also works for positive semi-definite matrices. Default: `false`. */
|
|
5
9
|
pivot?: boolean;
|
|
6
10
|
/** Stopping tolerance for the pivoted decomposition. A negative value means `n * eps * max(diag(x))`. Default: `-1`. Used only with `pivot: true`. */
|
|
7
11
|
tol?: number;
|
|
8
12
|
}
|
|
9
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Result of {@link chol} with `pivot: true`.
|
|
15
|
+
*
|
|
16
|
+
* @category Linear algebra
|
|
17
|
+
*/
|
|
10
18
|
export interface CholPivotResult {
|
|
11
19
|
/** The upper triangular factor `R`, such that `x[pivot, pivot] = t(R) R` (within the first `rank` rows). */
|
|
12
20
|
r: number[][];
|
|
@@ -30,12 +38,14 @@ export interface CholPivotResult {
|
|
|
30
38
|
* chol([[4, 2], [2, 3]]);
|
|
31
39
|
* // [[2, 1], [0, 1.4142135623730951]]
|
|
32
40
|
* ```
|
|
41
|
+
*
|
|
42
|
+
* @category Linear algebra
|
|
33
43
|
*/
|
|
34
44
|
export declare function chol(x: MatrixInput, options?: CholOptions & {
|
|
35
45
|
pivot?: false;
|
|
36
46
|
}): number[][];
|
|
37
47
|
/**
|
|
38
|
-
* Pivoted Cholesky decomposition
|
|
48
|
+
* Pivoted Cholesky decomposition, as R's `chol(x, pivot = TRUE)`.
|
|
39
49
|
*
|
|
40
50
|
* Does not throw for rank-deficient (positive semi-definite) matrices; check `rank` instead (R gives a
|
|
41
51
|
* warning). Rows of `r` after `rank` are not meaningful: the diagonal element at the stopping position holds
|
|
@@ -55,7 +65,7 @@ export declare function chol(x: MatrixInput, options: CholOptions & {
|
|
|
55
65
|
pivot: true;
|
|
56
66
|
}): CholPivotResult;
|
|
57
67
|
/**
|
|
58
|
-
* Cholesky decomposition, with or without pivoting.
|
|
68
|
+
* Cholesky decomposition, with or without pivoting.
|
|
59
69
|
*
|
|
60
70
|
* @param x A square symmetric matrix (array of rows).
|
|
61
71
|
* @param options See {@link CholOptions}.
|
|
@@ -64,7 +74,11 @@ export declare function chol(x: MatrixInput, options: CholOptions & {
|
|
|
64
74
|
export declare function chol(x: MatrixInput, options?: CholOptions): number[][] | CholPivotResult;
|
|
65
75
|
/** Overwrite a with its upper-triangular Cholesky factor (dpotf2). Returns the failing column (1-based), or 0 on success */
|
|
66
76
|
export declare function potf2(A: Mat): number;
|
|
67
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Options for {@link chol2inv}.
|
|
79
|
+
*
|
|
80
|
+
* @category Linear algebra
|
|
81
|
+
*/
|
|
68
82
|
export interface Chol2InvOptions {
|
|
69
83
|
/** Number of rows and columns of `x` to use (its top-left `size` x `size` upper triangle). Default: the number of columns of `x`. */
|
|
70
84
|
size?: number;
|
|
@@ -77,6 +91,13 @@ export interface Chol2InvOptions {
|
|
|
77
91
|
* @param x The upper triangular Cholesky factor `R` (array of rows), e.g. from {@link chol}. A vector is treated as a one-column matrix.
|
|
78
92
|
* @param options See {@link Chol2InvOptions}.
|
|
79
93
|
* @returns The symmetric inverse matrix (`size` x `size`) as an array of rows.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* chol2inv([[2, 1], [0, 1]]); // [[0.5, -0.5], [-0.5, 1]]
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @category Linear algebra
|
|
80
101
|
*/
|
|
81
102
|
export declare function chol2inv(x: MatrixInput | readonly number[] | Float64Array, options?: Chol2InvOptions): number[][];
|
|
82
103
|
/** From upper-triangular R, compute the upper triangle of (t(R) R)^-1 in place (dpotri = dtrti2 + dlauu2) */
|
package/dist/linalg/chol.js
CHANGED
|
@@ -128,6 +128,13 @@ function pstf2(A, tol) {
|
|
|
128
128
|
* @param x The upper triangular Cholesky factor `R` (array of rows), e.g. from {@link chol}. A vector is treated as a one-column matrix.
|
|
129
129
|
* @param options See {@link Chol2InvOptions}.
|
|
130
130
|
* @returns The symmetric inverse matrix (`size` x `size`) as an array of rows.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* chol2inv([[2, 1], [0, 1]]); // [[0.5, -0.5], [-0.5, 1]]
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @category Linear algebra
|
|
131
138
|
*/
|
|
132
139
|
export function chol2inv(x, options = {}) {
|
|
133
140
|
const m = toMatOrColumn(x);
|
package/dist/linalg/eigen.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type Mat, type MatrixInput } from "./matrix.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link eigen}.
|
|
4
|
+
*
|
|
5
|
+
* @category Linear algebra
|
|
6
|
+
*/
|
|
3
7
|
export interface EigenOptions {
|
|
4
8
|
/**
|
|
5
9
|
* Treat the matrix as symmetric (only its lower triangle is then used). Default: detected automatically,
|
|
@@ -9,7 +13,11 @@ export interface EigenOptions {
|
|
|
9
13
|
/** Compute only the eigenvalues. Default: `false`. R's `only.values`. */
|
|
10
14
|
onlyValues?: boolean;
|
|
11
15
|
}
|
|
12
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Result of {@link eigen}.
|
|
18
|
+
*
|
|
19
|
+
* @category Linear algebra
|
|
20
|
+
*/
|
|
13
21
|
export interface EigenResult {
|
|
14
22
|
/**
|
|
15
23
|
* The eigenvalues (their real parts if complex). Sorted in decreasing order for a symmetric matrix, and by
|
|
@@ -39,13 +47,14 @@ export interface EigenResult {
|
|
|
39
47
|
*
|
|
40
48
|
* @example
|
|
41
49
|
* ```ts
|
|
42
|
-
* eigen([[2, 1], [1, 2]]);
|
|
43
|
-
* //
|
|
44
|
-
* //
|
|
50
|
+
* const e = eigen([[2, 1], [1, 2]]);
|
|
51
|
+
* e.values; // [3, 1]
|
|
52
|
+
* e.vectors; // [[0.7071, 0.7071], [0.7071, -0.7071]] (signs may differ from R)
|
|
45
53
|
*
|
|
46
|
-
* eigen([[0, -1], [1, 0]]);
|
|
47
|
-
* // values: [0, 0], valuesIm: [1, -1]
|
|
54
|
+
* eigen([[0, -1], [1, 0]]); // { values: [0, 0], valuesIm: [1, -1] }
|
|
48
55
|
* ```
|
|
56
|
+
*
|
|
57
|
+
* @category Linear algebra
|
|
49
58
|
*/
|
|
50
59
|
export declare function eigen(x: MatrixInput, options?: EigenOptions): EigenResult;
|
|
51
60
|
/** Same test as R's isSymmetric (all.equal(A, t(A), tolerance = 100 ε)) */
|
package/dist/linalg/eigen.js
CHANGED
|
@@ -31,13 +31,14 @@ import { fromMat, newMat, requireSquare, toMat } from "./matrix.js";
|
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* ```ts
|
|
34
|
-
* eigen([[2, 1], [1, 2]]);
|
|
35
|
-
* //
|
|
36
|
-
* //
|
|
34
|
+
* const e = eigen([[2, 1], [1, 2]]);
|
|
35
|
+
* e.values; // [3, 1]
|
|
36
|
+
* e.vectors; // [[0.7071, 0.7071], [0.7071, -0.7071]] (signs may differ from R)
|
|
37
37
|
*
|
|
38
|
-
* eigen([[0, -1], [1, 0]]);
|
|
39
|
-
* // values: [0, 0], valuesIm: [1, -1]
|
|
38
|
+
* eigen([[0, -1], [1, 0]]); // { values: [0, 0], valuesIm: [1, -1] }
|
|
40
39
|
* ```
|
|
40
|
+
*
|
|
41
|
+
* @category Linear algebra
|
|
41
42
|
*/
|
|
42
43
|
export function eigen(x, options = {}) {
|
|
43
44
|
const a = toMat(x);
|
package/dist/linalg/expm.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type Mat, type MatrixInput } from "./matrix.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Methods of {@link expm}.
|
|
4
|
+
*
|
|
5
|
+
* @category Linear algebra
|
|
6
|
+
*/
|
|
3
7
|
export type ExpmMethod = "Higham08.b" | "Higham08" | "Pade" | "Taylor" | "PadeO" | "TaylorO";
|
|
4
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link expm}.
|
|
10
|
+
*
|
|
11
|
+
* @category Linear algebra
|
|
12
|
+
*/
|
|
5
13
|
export interface ExpmOptions {
|
|
6
14
|
/**
|
|
7
15
|
* `"Higham08.b"` (default): Higham's scaling and squaring with Padé approximants after balancing (LAPACK's
|
|
@@ -17,8 +25,8 @@ export interface ExpmOptions {
|
|
|
17
25
|
order?: number;
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
20
|
-
* Matrix exponential. Equivalent to
|
|
21
|
-
* `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
|
|
28
|
+
* Matrix exponential. Equivalent to `expm::expm(x, method, order)` in R. The methods are `"Higham08.b"` (the
|
|
29
|
+
* default), `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
|
|
22
30
|
*
|
|
23
31
|
* `"Higham08.b"` and `"Higham08"` use the scaling and squaring method with Padé approximants of degree 3, 5, 7, 9 or
|
|
24
32
|
* 13 (Higham 2005), with or without balancing first, and throw if a linear system of the method is computationally
|
|
@@ -32,8 +40,10 @@ export interface ExpmOptions {
|
|
|
32
40
|
* @example
|
|
33
41
|
* ```ts
|
|
34
42
|
* expm([[0, 1], [0, 0]]); // [[1, 1], [0, 1]]
|
|
35
|
-
* expm([[0, -1], [1, 0]]); // [[
|
|
43
|
+
* expm([[0, -1], [1, 0]]); // [[0.5403023059, -0.8414709848], [0.8414709848, 0.5403023059]] (cos 1 and sin 1)
|
|
36
44
|
* ```
|
|
45
|
+
*
|
|
46
|
+
* @category Linear algebra
|
|
37
47
|
*/
|
|
38
48
|
export declare function expm(x: MatrixInput, options?: ExpmOptions): number[][];
|
|
39
49
|
/**
|
package/dist/linalg/expm.js
CHANGED
|
@@ -23,8 +23,8 @@ import { infNorm, oneNorm } from "./norm.js";
|
|
|
23
23
|
import { solve } from "./solve.js";
|
|
24
24
|
const METHODS = ["Higham08.b", "Higham08", "Pade", "Taylor", "PadeO", "TaylorO"];
|
|
25
25
|
/**
|
|
26
|
-
* Matrix exponential. Equivalent to
|
|
27
|
-
* `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
|
|
26
|
+
* Matrix exponential. Equivalent to `expm::expm(x, method, order)` in R. The methods are `"Higham08.b"` (the
|
|
27
|
+
* default), `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
|
|
28
28
|
*
|
|
29
29
|
* `"Higham08.b"` and `"Higham08"` use the scaling and squaring method with Padé approximants of degree 3, 5, 7, 9 or
|
|
30
30
|
* 13 (Higham 2005), with or without balancing first, and throw if a linear system of the method is computationally
|
|
@@ -38,8 +38,10 @@ const METHODS = ["Higham08.b", "Higham08", "Pade", "Taylor", "PadeO", "TaylorO"]
|
|
|
38
38
|
* @example
|
|
39
39
|
* ```ts
|
|
40
40
|
* expm([[0, 1], [0, 0]]); // [[1, 1], [0, 1]]
|
|
41
|
-
* expm([[0, -1], [1, 0]]); // [[
|
|
41
|
+
* expm([[0, -1], [1, 0]]); // [[0.5403023059, -0.8414709848], [0.8414709848, 0.5403023059]] (cos 1 and sin 1)
|
|
42
42
|
* ```
|
|
43
|
+
*
|
|
44
|
+
* @category Linear algebra
|
|
43
45
|
*/
|
|
44
46
|
export function expm(x, options = {}) {
|
|
45
47
|
const method = options.method ?? "Higham08.b";
|
package/dist/linalg/kappa.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type Mat, type MatrixInput } from "./matrix.js";
|
|
2
2
|
import { type NormType } from "./norm.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link kappa}.
|
|
5
|
+
*
|
|
6
|
+
* @category Linear algebra
|
|
7
|
+
*/
|
|
4
8
|
export interface KappaOptions {
|
|
5
9
|
/** Compute the condition number exactly instead of estimating it. Default: `false`. */
|
|
6
10
|
exact?: boolean;
|
|
@@ -29,6 +33,14 @@ export interface KappaOptions {
|
|
|
29
33
|
* @param z A matrix (array of rows).
|
|
30
34
|
* @param options See {@link KappaOptions}.
|
|
31
35
|
* @returns The (estimated) condition number.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* kappa([[1, 2], [3, 4]]); // 17.85 (LINPACK estimate)
|
|
40
|
+
* kappa([[1, 2], [3, 4]], { exact: true }); // 14.933034373659272
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @category Linear algebra
|
|
32
44
|
*/
|
|
33
45
|
export declare function kappa(z: MatrixInput, options?: KappaOptions): number;
|
|
34
46
|
/**
|
|
@@ -45,6 +57,14 @@ export declare function trco(T: Mat, upper: boolean): number;
|
|
|
45
57
|
* @param x A matrix (array of rows).
|
|
46
58
|
* @param options `tol`: relative tolerance for treating singular values as zero. Default: `sqrt(Number.EPSILON)`.
|
|
47
59
|
* @returns The generalized inverse (`ncol` x `nrow`) as an array of rows.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* ginv([[1, 2], [3, 4]]); // [[-2, 1], [1.5, -0.5]]
|
|
64
|
+
* ginv([[1, 1], [1, 1]]); // [[0.25, 0.25], [0.25, 0.25]]
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @category Linear algebra
|
|
48
68
|
*/
|
|
49
69
|
export declare function ginv(x: MatrixInput, options?: {
|
|
50
70
|
tol?: number;
|
package/dist/linalg/kappa.js
CHANGED
|
@@ -27,6 +27,14 @@ import { svd } from "./svd.js";
|
|
|
27
27
|
* @param z A matrix (array of rows).
|
|
28
28
|
* @param options See {@link KappaOptions}.
|
|
29
29
|
* @returns The (estimated) condition number.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* kappa([[1, 2], [3, 4]]); // 17.85 (LINPACK estimate)
|
|
34
|
+
* kappa([[1, 2], [3, 4]], { exact: true }); // 14.933034373659272
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @category Linear algebra
|
|
30
38
|
*/
|
|
31
39
|
export function kappa(z, options = {}) {
|
|
32
40
|
// The default norm is "2" if exact, "1" if estimated
|
|
@@ -176,6 +184,14 @@ function asum(z) {
|
|
|
176
184
|
* @param x A matrix (array of rows).
|
|
177
185
|
* @param options `tol`: relative tolerance for treating singular values as zero. Default: `sqrt(Number.EPSILON)`.
|
|
178
186
|
* @returns The generalized inverse (`ncol` x `nrow`) as an array of rows.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* ginv([[1, 2], [3, 4]]); // [[-2, 1], [1.5, -0.5]]
|
|
191
|
+
* ginv([[1, 1], [1, 1]]); // [[0.25, 0.25], [0.25, 0.25]]
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* @category Linear algebra
|
|
179
195
|
*/
|
|
180
196
|
export function ginv(x, options = {}) {
|
|
181
197
|
const tol = options.tol ?? Math.sqrt(Number.EPSILON);
|
package/dist/linalg/lu.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { MatrixInput } from "./matrix.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Result of {@link lu}: `x = P L U`.
|
|
4
|
+
*
|
|
5
|
+
* @category Linear algebra
|
|
6
|
+
*/
|
|
3
7
|
export interface LuResult {
|
|
4
8
|
/** Permutation matrix (m x m). */
|
|
5
9
|
P: number[][];
|
|
@@ -9,23 +13,34 @@ export interface LuResult {
|
|
|
9
13
|
U: number[][];
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
|
-
* LU decomposition with partial (row) pivoting, `x = P L U`. Equivalent to `Matrix::
|
|
13
|
-
* (LAPACK's dgetrf).
|
|
16
|
+
* LU decomposition with partial (row) pivoting, `x = P L U`. Equivalent to R's `Matrix::lu()`. The factors are those
|
|
17
|
+
* of `Matrix::expand(Matrix::lu(x))` (LAPACK's dgetrf).
|
|
14
18
|
*
|
|
15
19
|
* @example
|
|
16
20
|
* ```ts
|
|
17
|
-
*
|
|
21
|
+
* lu([[1, 2], [3, 4]]);
|
|
22
|
+
* // { P: [[0, 1], [1, 0]], L: [[1, 0], [0.3333333333333333, 1]], U: [[3, 4], [0, 0.6666666666666667]] }
|
|
18
23
|
* ```
|
|
24
|
+
*
|
|
25
|
+
* @category Linear algebra
|
|
19
26
|
*/
|
|
20
27
|
export declare function lu(x: MatrixInput): LuResult;
|
|
21
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Options for {@link prcomp}.
|
|
30
|
+
*
|
|
31
|
+
* @category Linear algebra
|
|
32
|
+
*/
|
|
22
33
|
export interface PrcompOptions {
|
|
23
34
|
/** Centre the columns (default `true`), or subtract the given values. */
|
|
24
35
|
center?: boolean | readonly number[];
|
|
25
36
|
/** Scale the columns to unit variance (default `false`), or divide by the given values. */
|
|
26
37
|
scale?: boolean | readonly number[];
|
|
27
38
|
}
|
|
28
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Result of {@link prcomp}.
|
|
41
|
+
*
|
|
42
|
+
* @category Linear algebra
|
|
43
|
+
*/
|
|
29
44
|
export interface PrcompResult {
|
|
30
45
|
/** Standard deviations of the principal components. */
|
|
31
46
|
sdev: number[];
|
|
@@ -41,5 +56,14 @@ export interface PrcompResult {
|
|
|
41
56
|
/**
|
|
42
57
|
* Principal components of the columns of `x` (observations as rows). Equivalent to R's `prcomp()`. The sign of each
|
|
43
58
|
* component is arbitrary, as in R.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const pc = prcomp([[1, 2], [2, 1], [3, 4], [4, 3]]);
|
|
63
|
+
* pc.sdev; // [1.632993161855452, 0.816496580927726]
|
|
64
|
+
* pc.x; // [[-1.4142, 0.7071], [-1.4142, -0.7071], [1.4142, 0.7071], [1.4142, -0.7071]] (signs may differ from R)
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @category Linear algebra
|
|
44
68
|
*/
|
|
45
69
|
export declare function prcomp(x: MatrixInput, options?: PrcompOptions): PrcompResult;
|