deepbox 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +39 -37
- package/dist/{CSRMatrix-KzNt6QpS.d.ts → CSRMatrix-B7XtUAZO.d.cts} +3 -3
- package/dist/{CSRMatrix-CwGwQRea.d.cts → CSRMatrix-CtD23fRM.d.ts} +3 -3
- package/dist/{Tensor-BQLk1ltW.d.cts → Tensor-BORFp_zt.d.ts} +27 -7
- package/dist/{Tensor-g8mUClel.d.ts → Tensor-fxBg-TFZ.d.cts} +27 -7
- package/dist/{chunk-FJYLIGJX.js → chunk-3AX37GPK.js} +33 -7
- package/dist/chunk-3AX37GPK.js.map +1 -0
- package/dist/{chunk-PR647I7R.js → chunk-3YFEYDHN.js} +21 -4
- package/dist/chunk-3YFEYDHN.js.map +1 -0
- package/dist/{chunk-XMWVME2W.js → chunk-6SX26MAJ.js} +4 -4
- package/dist/{chunk-XMWVME2W.js.map → chunk-6SX26MAJ.js.map} +1 -1
- package/dist/{chunk-C4PKXY74.cjs → chunk-6X7XFNDO.cjs} +94 -77
- package/dist/chunk-6X7XFNDO.cjs.map +1 -0
- package/dist/{chunk-6AE5FKKQ.cjs → chunk-724CXHFH.cjs} +1211 -919
- package/dist/chunk-724CXHFH.cjs.map +1 -0
- package/dist/{chunk-AU7XHGKJ.js → chunk-AJTKVBY5.js} +4 -4
- package/dist/{chunk-AU7XHGKJ.js.map → chunk-AJTKVBY5.js.map} +1 -1
- package/dist/{chunk-ZB75FESB.cjs → chunk-AV6WGSYX.cjs} +130 -104
- package/dist/chunk-AV6WGSYX.cjs.map +1 -0
- package/dist/{chunk-ZLW62TJG.cjs → chunk-BWOSU234.cjs} +142 -141
- package/dist/chunk-BWOSU234.cjs.map +1 -0
- package/dist/{chunk-4S73VUBD.js → chunk-CZOMBUI7.js} +3 -3
- package/dist/chunk-CZOMBUI7.js.map +1 -0
- package/dist/{chunk-QERHVCHC.cjs → chunk-EUZHJDZ6.cjs} +419 -364
- package/dist/chunk-EUZHJDZ6.cjs.map +1 -0
- package/dist/{chunk-AD436M45.js → chunk-G2G55ATL.js} +120 -58
- package/dist/chunk-G2G55ATL.js.map +1 -0
- package/dist/{chunk-5R4S63PF.js → chunk-G3WNLNYS.js} +119 -64
- package/dist/chunk-G3WNLNYS.js.map +1 -0
- package/dist/{chunk-XEG44RF6.cjs → chunk-G7KXZHG6.cjs} +105 -95
- package/dist/chunk-G7KXZHG6.cjs.map +1 -0
- package/dist/{chunk-MLBMYKCG.js → chunk-H3JR7SV2.js} +255 -113
- package/dist/chunk-H3JR7SV2.js.map +1 -0
- package/dist/{chunk-PHV2DKRS.cjs → chunk-HDKMIG6E.cjs} +107 -107
- package/dist/{chunk-PHV2DKRS.cjs.map → chunk-HDKMIG6E.cjs.map} +1 -1
- package/dist/{chunk-ALS7ETWZ.cjs → chunk-HI2EZHCJ.cjs} +111 -102
- package/dist/chunk-HI2EZHCJ.cjs.map +1 -0
- package/dist/{chunk-OX6QXFMV.cjs → chunk-IT4BZUYE.cjs} +490 -428
- package/dist/chunk-IT4BZUYE.cjs.map +1 -0
- package/dist/{chunk-E3EU5FZO.cjs → chunk-JTZPRV6E.cjs} +123 -123
- package/dist/{chunk-E3EU5FZO.cjs.map → chunk-JTZPRV6E.cjs.map} +1 -1
- package/dist/{chunk-PL7TAYKI.js → chunk-K2L5C5YH.js} +8 -7
- package/dist/chunk-K2L5C5YH.js.map +1 -0
- package/dist/{chunk-BCR7G3A6.js → chunk-KCF6P34A.js} +356 -64
- package/dist/chunk-KCF6P34A.js.map +1 -0
- package/dist/{chunk-ZXKBDFP3.js → chunk-LZHVHD62.js} +15 -6
- package/dist/chunk-LZHVHD62.js.map +1 -0
- package/dist/{chunk-LWECRCW2.cjs → chunk-MTJF52AJ.cjs} +141 -141
- package/dist/{chunk-LWECRCW2.cjs.map → chunk-MTJF52AJ.cjs.map} +1 -1
- package/dist/{chunk-B5TNKUEY.js → chunk-NDDTUFKK.js} +16 -6
- package/dist/chunk-NDDTUFKK.js.map +1 -0
- package/dist/{chunk-DWZY6PIP.cjs → chunk-NOQI6OFL.cjs} +615 -473
- package/dist/chunk-NOQI6OFL.cjs.map +1 -0
- package/dist/{chunk-F3JWBINJ.js → chunk-OEXDJFHA.js} +4 -4
- package/dist/{chunk-F3JWBINJ.js.map → chunk-OEXDJFHA.js.map} +1 -1
- package/dist/{chunk-JSCDE774.cjs → chunk-Z6BGACIH.cjs} +3 -3
- package/dist/chunk-Z6BGACIH.cjs.map +1 -0
- package/dist/core/index.cjs +50 -50
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +1 -1
- package/dist/dataframe/index.cjs +6 -6
- package/dist/dataframe/index.d.cts +3 -3
- package/dist/dataframe/index.d.ts +3 -3
- package/dist/dataframe/index.js +3 -3
- package/dist/datasets/index.cjs +34 -34
- package/dist/datasets/index.d.cts +3 -3
- package/dist/datasets/index.d.ts +3 -3
- package/dist/datasets/index.js +3 -3
- package/dist/{index-C1mfVYoo.d.ts → index-B18dHc8q.d.ts} +81 -46
- package/dist/{index-GFAVyOWO.d.ts → index-BHHX0qTY.d.cts} +14 -12
- package/dist/{index-tk4lSYod.d.ts → index-BI6QOUvV.d.ts} +106 -80
- package/dist/{index-DIp_RrRt.d.ts → index-BKvK21lf.d.ts} +13 -35
- package/dist/{index-BJY2SI4i.d.ts → index-BL8jLf3K.d.cts} +12 -11
- package/dist/{index-Cn3SdB0O.d.ts → index-BNbX167d.d.cts} +16 -10
- package/dist/{index-BWGhrDlr.d.ts → index-BT2ofL7Z.d.cts} +35 -35
- package/dist/{index-BbA2Gxfl.d.ts → index-BqcfIcL4.d.ts} +15 -15
- package/dist/{index-ZtI1Iy4L.d.ts → index-BrgrECM2.d.ts} +41 -38
- package/dist/{index-CDw5CnOU.d.ts → index-BtYKI9yJ.d.ts} +10 -8
- package/dist/{index-DIT_OO9C.d.cts → index-C7nLsAOC.d.cts} +10 -8
- package/dist/{index-D9Loo1_A.d.cts → index-CNj2Mxwf.d.cts} +81 -46
- package/dist/{index-DmEg_LCm.d.cts → index-CYlxeNW1.d.cts} +5 -3
- package/dist/{index-D61yaSMY.d.cts → index-CiTd61a5.d.ts} +12 -11
- package/dist/{index-BndMbqsM.d.ts → index-Cjnn0KeN.d.cts} +35 -21
- package/dist/{index-9oQx1HgV.d.cts → index-CkGGAn69.d.cts} +41 -38
- package/dist/{index-74AB8Cyh.d.cts → index-D4URSgqA.d.ts} +16 -10
- package/dist/{index-DoPWVxPo.d.cts → index-D4pn5zLT.d.ts} +35 -21
- package/dist/{index-DuCxd-8d.d.ts → index-D9ztTlDr.d.ts} +60 -42
- package/dist/{index-BgHYAoSS.d.cts → index-DF28ZPB5.d.cts} +60 -42
- package/dist/{index-eJgeni9c.d.cts → index-DLdiQzf0.d.cts} +106 -80
- package/dist/{index-WHQLn0e8.d.cts → index-DN4omPQw.d.ts} +35 -35
- package/dist/{index-CrqLlS-a.d.ts → index-DUnFq1WV.d.ts} +5 -3
- package/dist/{index-DbultU6X.d.cts → index-DgaYshkF.d.ts} +14 -12
- package/dist/{index-B_DK4FKY.d.cts → index-GUHYEhxs.d.cts} +13 -35
- package/dist/{index-CCvlwAmL.d.cts → index-TP--4irE.d.cts} +16 -14
- package/dist/{index-Dx42TZaY.d.ts → index-x0z_sanT.d.ts} +16 -14
- package/dist/{index-DyZ4QQf5.d.cts → index-xWH7ujWa.d.cts} +15 -15
- package/dist/index.cjs +26 -26
- package/dist/index.d.cts +17 -17
- package/dist/index.d.ts +17 -17
- package/dist/index.js +13 -13
- package/dist/linalg/index.cjs +22 -22
- package/dist/linalg/index.d.cts +3 -3
- package/dist/linalg/index.d.ts +3 -3
- package/dist/linalg/index.js +3 -3
- package/dist/metrics/index.cjs +40 -40
- package/dist/metrics/index.d.cts +3 -3
- package/dist/metrics/index.d.ts +3 -3
- package/dist/metrics/index.js +3 -3
- package/dist/ml/index.cjs +23 -23
- package/dist/ml/index.d.cts +3 -3
- package/dist/ml/index.d.ts +3 -3
- package/dist/ml/index.js +4 -4
- package/dist/ndarray/index.cjs +125 -125
- package/dist/ndarray/index.d.cts +5 -5
- package/dist/ndarray/index.d.ts +5 -5
- package/dist/ndarray/index.js +2 -2
- package/dist/nn/index.cjs +36 -36
- package/dist/nn/index.d.cts +6 -6
- package/dist/nn/index.d.ts +6 -6
- package/dist/nn/index.js +3 -3
- package/dist/optim/index.cjs +19 -19
- package/dist/optim/index.d.cts +4 -4
- package/dist/optim/index.d.ts +4 -4
- package/dist/optim/index.js +2 -2
- package/dist/plot/index.cjs +29 -29
- package/dist/plot/index.d.cts +6 -6
- package/dist/plot/index.d.ts +6 -6
- package/dist/plot/index.js +3 -3
- package/dist/preprocess/index.cjs +21 -21
- package/dist/preprocess/index.d.cts +4 -4
- package/dist/preprocess/index.d.ts +4 -4
- package/dist/preprocess/index.js +3 -3
- package/dist/random/index.cjs +19 -19
- package/dist/random/index.d.cts +3 -3
- package/dist/random/index.d.ts +3 -3
- package/dist/random/index.js +3 -3
- package/dist/stats/index.cjs +36 -36
- package/dist/stats/index.d.cts +3 -3
- package/dist/stats/index.d.ts +3 -3
- package/dist/stats/index.js +3 -3
- package/dist/{tensor-B96jjJLQ.d.cts → tensor-IlVTF0bz.d.cts} +16 -3
- package/dist/{tensor-B96jjJLQ.d.ts → tensor-IlVTF0bz.d.ts} +16 -3
- package/package.json +3 -2
- package/dist/chunk-4S73VUBD.js.map +0 -1
- package/dist/chunk-5R4S63PF.js.map +0 -1
- package/dist/chunk-6AE5FKKQ.cjs.map +0 -1
- package/dist/chunk-AD436M45.js.map +0 -1
- package/dist/chunk-ALS7ETWZ.cjs.map +0 -1
- package/dist/chunk-B5TNKUEY.js.map +0 -1
- package/dist/chunk-BCR7G3A6.js.map +0 -1
- package/dist/chunk-C4PKXY74.cjs.map +0 -1
- package/dist/chunk-DWZY6PIP.cjs.map +0 -1
- package/dist/chunk-FJYLIGJX.js.map +0 -1
- package/dist/chunk-JSCDE774.cjs.map +0 -1
- package/dist/chunk-MLBMYKCG.js.map +0 -1
- package/dist/chunk-OX6QXFMV.cjs.map +0 -1
- package/dist/chunk-PL7TAYKI.js.map +0 -1
- package/dist/chunk-PR647I7R.js.map +0 -1
- package/dist/chunk-QERHVCHC.cjs.map +0 -1
- package/dist/chunk-XEG44RF6.cjs.map +0 -1
- package/dist/chunk-ZB75FESB.cjs.map +0 -1
- package/dist/chunk-ZLW62TJG.cjs.map +0 -1
- package/dist/chunk-ZXKBDFP3.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk724CXHFH_cjs = require('./chunk-724CXHFH.cjs');
|
|
4
|
+
var chunkZ6BGACIH_cjs = require('./chunk-Z6BGACIH.cjs');
|
|
5
5
|
|
|
6
6
|
// src/preprocess/index.ts
|
|
7
7
|
var preprocess_exports = {};
|
|
8
|
-
|
|
8
|
+
chunkZ6BGACIH_cjs.__export(preprocess_exports, {
|
|
9
9
|
GroupKFold: () => GroupKFold,
|
|
10
10
|
KFold: () => KFold,
|
|
11
11
|
LabelBinarizer: () => LabelBinarizer,
|
|
@@ -29,24 +29,24 @@ chunkJSCDE774_cjs.__export(preprocess_exports, {
|
|
|
29
29
|
// src/preprocess/_internal.ts
|
|
30
30
|
function assertNumericTensor(X, name) {
|
|
31
31
|
if (X.dtype === "string") {
|
|
32
|
-
throw new
|
|
32
|
+
throw new chunkZ6BGACIH_cjs.DTypeError(`${name} must be numeric`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
function assert2D(X, name) {
|
|
36
36
|
if (X.ndim !== 2) {
|
|
37
|
-
throw new
|
|
37
|
+
throw new chunkZ6BGACIH_cjs.ShapeError(`${name} must be a 2D tensor, got ${X.ndim}D`);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
function getShape2D(X) {
|
|
41
41
|
if (X.ndim !== 2 || X.shape[0] === void 0 || X.shape[1] === void 0) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new chunkZ6BGACIH_cjs.ShapeError(`Expected 2D tensor with valid shape, got shape [${X.shape.join(", ")}]`);
|
|
43
43
|
}
|
|
44
44
|
return [X.shape[0], X.shape[1]];
|
|
45
45
|
}
|
|
46
46
|
function getStride1D(X) {
|
|
47
47
|
const stride = X.strides[0];
|
|
48
48
|
if (stride === void 0) {
|
|
49
|
-
throw new
|
|
49
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing stride for 1D tensor");
|
|
50
50
|
}
|
|
51
51
|
return stride;
|
|
52
52
|
}
|
|
@@ -54,7 +54,7 @@ function getStrides2D(X) {
|
|
|
54
54
|
const stride0 = X.strides[0];
|
|
55
55
|
const stride1 = X.strides[1];
|
|
56
56
|
if (stride0 === void 0 || stride1 === void 0) {
|
|
57
|
-
throw new
|
|
57
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing strides for 2D tensor");
|
|
58
58
|
}
|
|
59
59
|
return [stride0, stride1];
|
|
60
60
|
}
|
|
@@ -63,7 +63,7 @@ function createSeededRandom(seed) {
|
|
|
63
63
|
const c = 12345;
|
|
64
64
|
const m = 2 ** 31;
|
|
65
65
|
if (!Number.isFinite(seed) || !Number.isInteger(seed) || !Number.isSafeInteger(seed) || seed < 0) {
|
|
66
|
-
throw new
|
|
66
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
67
67
|
"randomState must be a non-negative safe integer",
|
|
68
68
|
"randomState",
|
|
69
69
|
seed
|
|
@@ -80,11 +80,11 @@ function shuffleIndicesInPlace(indices, random) {
|
|
|
80
80
|
const j = Math.floor(random() * (i + 1));
|
|
81
81
|
const temp = indices[i];
|
|
82
82
|
if (temp === void 0) {
|
|
83
|
-
throw new
|
|
83
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: shuffle source index missing");
|
|
84
84
|
}
|
|
85
85
|
const swap = indices[j];
|
|
86
86
|
if (swap === void 0) {
|
|
87
|
-
throw new
|
|
87
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: shuffle target index missing");
|
|
88
88
|
}
|
|
89
89
|
indices[i] = swap;
|
|
90
90
|
indices[j] = temp;
|
|
@@ -92,21 +92,73 @@ function shuffleIndicesInPlace(indices, random) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// src/preprocess/encoders.ts
|
|
95
|
+
function coerceToTensor1D(input) {
|
|
96
|
+
if (typeof input === "object" && "shape" in input && "dtype" in input) {
|
|
97
|
+
return input;
|
|
98
|
+
}
|
|
99
|
+
const arr = input;
|
|
100
|
+
if (arr.length === 0) {
|
|
101
|
+
return chunk724CXHFH_cjs.tensor([]);
|
|
102
|
+
}
|
|
103
|
+
const first = arr[0];
|
|
104
|
+
if (typeof first === "string") {
|
|
105
|
+
const strArr = [];
|
|
106
|
+
for (const v of arr) {
|
|
107
|
+
strArr.push(String(v));
|
|
108
|
+
}
|
|
109
|
+
return chunk724CXHFH_cjs.tensor(strArr);
|
|
110
|
+
}
|
|
111
|
+
const numArr = [];
|
|
112
|
+
for (const v of arr) {
|
|
113
|
+
numArr.push(Number(v));
|
|
114
|
+
}
|
|
115
|
+
return chunk724CXHFH_cjs.tensor(numArr, { dtype: "float64" });
|
|
116
|
+
}
|
|
117
|
+
function coerceToTensor2D(input) {
|
|
118
|
+
if (typeof input === "object" && "shape" in input && "dtype" in input) {
|
|
119
|
+
return input;
|
|
120
|
+
}
|
|
121
|
+
const arr = input;
|
|
122
|
+
if (arr.length === 0 || arr[0] && arr[0].length === 0) {
|
|
123
|
+
return chunk724CXHFH_cjs.tensor([[]]);
|
|
124
|
+
}
|
|
125
|
+
const first = arr[0]?.[0];
|
|
126
|
+
if (typeof first === "string") {
|
|
127
|
+
const strArr = [];
|
|
128
|
+
for (const row of arr) {
|
|
129
|
+
const strRow = [];
|
|
130
|
+
for (const v of row) {
|
|
131
|
+
strRow.push(String(v));
|
|
132
|
+
}
|
|
133
|
+
strArr.push(strRow);
|
|
134
|
+
}
|
|
135
|
+
return chunk724CXHFH_cjs.tensor(strArr);
|
|
136
|
+
}
|
|
137
|
+
const numArr = [];
|
|
138
|
+
for (const row of arr) {
|
|
139
|
+
const numRow = [];
|
|
140
|
+
for (const v of row) {
|
|
141
|
+
numRow.push(Number(v));
|
|
142
|
+
}
|
|
143
|
+
numArr.push(numRow);
|
|
144
|
+
}
|
|
145
|
+
return chunk724CXHFH_cjs.tensor(numArr, { dtype: "float64" });
|
|
146
|
+
}
|
|
95
147
|
function getStringData(t) {
|
|
96
148
|
if (t.dtype !== "string") {
|
|
97
|
-
throw new
|
|
149
|
+
throw new chunkZ6BGACIH_cjs.DTypeError("Expected string tensor");
|
|
98
150
|
}
|
|
99
151
|
if (!Array.isArray(t.data)) {
|
|
100
|
-
throw new
|
|
152
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: invalid string tensor storage");
|
|
101
153
|
}
|
|
102
154
|
return t.data;
|
|
103
155
|
}
|
|
104
156
|
function getNumericData(t) {
|
|
105
157
|
if (t.dtype === "string") {
|
|
106
|
-
throw new
|
|
158
|
+
throw new chunkZ6BGACIH_cjs.DTypeError("Expected numeric tensor");
|
|
107
159
|
}
|
|
108
160
|
if (Array.isArray(t.data)) {
|
|
109
|
-
throw new
|
|
161
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: invalid numeric tensor storage");
|
|
110
162
|
}
|
|
111
163
|
return t.data;
|
|
112
164
|
}
|
|
@@ -119,7 +171,7 @@ function inferCategoryType(values, paramName) {
|
|
|
119
171
|
hasString = true;
|
|
120
172
|
} else if (typeof value === "number") {
|
|
121
173
|
if (!Number.isFinite(value)) {
|
|
122
|
-
throw new
|
|
174
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Category values must be finite numbers", paramName, value);
|
|
123
175
|
}
|
|
124
176
|
hasNumber = true;
|
|
125
177
|
} else if (typeof value === "bigint") {
|
|
@@ -131,7 +183,7 @@ function inferCategoryType(values, paramName) {
|
|
|
131
183
|
return "number";
|
|
132
184
|
}
|
|
133
185
|
if (typeCount > 1) {
|
|
134
|
-
throw new
|
|
186
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Mixed category types are not supported", paramName);
|
|
135
187
|
}
|
|
136
188
|
if (hasString) return "string";
|
|
137
189
|
if (hasBigInt) return "bigint";
|
|
@@ -144,7 +196,7 @@ function sortCategories(values, paramName) {
|
|
|
144
196
|
if (categoryType === "string") {
|
|
145
197
|
arr.sort((a, b) => {
|
|
146
198
|
if (typeof a !== "string" || typeof b !== "string") {
|
|
147
|
-
throw new
|
|
199
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: inconsistent category types");
|
|
148
200
|
}
|
|
149
201
|
return a.localeCompare(b);
|
|
150
202
|
});
|
|
@@ -153,7 +205,7 @@ function sortCategories(values, paramName) {
|
|
|
153
205
|
if (categoryType === "bigint") {
|
|
154
206
|
arr.sort((a, b) => {
|
|
155
207
|
if (typeof a !== "bigint" || typeof b !== "bigint") {
|
|
156
|
-
throw new
|
|
208
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: inconsistent category types");
|
|
157
209
|
}
|
|
158
210
|
if (a < b) return -1;
|
|
159
211
|
if (a > b) return 1;
|
|
@@ -163,7 +215,7 @@ function sortCategories(values, paramName) {
|
|
|
163
215
|
}
|
|
164
216
|
arr.sort((a, b) => {
|
|
165
217
|
if (typeof a !== "number" || typeof b !== "number") {
|
|
166
|
-
throw new
|
|
218
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: inconsistent category types");
|
|
167
219
|
}
|
|
168
220
|
return a - b;
|
|
169
221
|
});
|
|
@@ -171,14 +223,14 @@ function sortCategories(values, paramName) {
|
|
|
171
223
|
}
|
|
172
224
|
function validateCategoryValues(values, paramName) {
|
|
173
225
|
if (values.length === 0) {
|
|
174
|
-
throw new
|
|
226
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("categories must contain at least one value", paramName);
|
|
175
227
|
}
|
|
176
228
|
const arr = Array.from(values);
|
|
177
229
|
inferCategoryType(arr, paramName);
|
|
178
230
|
const seen = /* @__PURE__ */ new Set();
|
|
179
231
|
for (const value of arr) {
|
|
180
232
|
if (seen.has(value)) {
|
|
181
|
-
throw new
|
|
233
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
182
234
|
`categories must be unique; duplicate value ${String(value)}`,
|
|
183
235
|
paramName,
|
|
184
236
|
value
|
|
@@ -193,14 +245,14 @@ function resolveCategoriesOption(categoriesOption, nFeatures, paramName) {
|
|
|
193
245
|
return null;
|
|
194
246
|
}
|
|
195
247
|
if (!Array.isArray(categoriesOption)) {
|
|
196
|
-
throw new
|
|
248
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
197
249
|
"categories must be 'auto' or an array of category arrays",
|
|
198
250
|
paramName,
|
|
199
251
|
categoriesOption
|
|
200
252
|
);
|
|
201
253
|
}
|
|
202
254
|
if (categoriesOption.length !== nFeatures) {
|
|
203
|
-
throw new
|
|
255
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
204
256
|
"categories length must match number of features",
|
|
205
257
|
paramName,
|
|
206
258
|
categoriesOption.length
|
|
@@ -214,13 +266,13 @@ function read1DValue(t, i) {
|
|
|
214
266
|
if (t.dtype === "string") {
|
|
215
267
|
const value2 = getStringData(t)[idx];
|
|
216
268
|
if (value2 === void 0) {
|
|
217
|
-
throw new
|
|
269
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: string tensor access out of bounds");
|
|
218
270
|
}
|
|
219
271
|
return value2;
|
|
220
272
|
}
|
|
221
273
|
const value = getNumericData(t)[idx];
|
|
222
274
|
if (value === void 0) {
|
|
223
|
-
throw new
|
|
275
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
224
276
|
}
|
|
225
277
|
return typeof value === "bigint" ? value : Number(value);
|
|
226
278
|
}
|
|
@@ -230,25 +282,25 @@ function read2DValue(t, row, col) {
|
|
|
230
282
|
if (t.dtype === "string") {
|
|
231
283
|
const value2 = getStringData(t)[idx];
|
|
232
284
|
if (value2 === void 0) {
|
|
233
|
-
throw new
|
|
285
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: string tensor access out of bounds");
|
|
234
286
|
}
|
|
235
287
|
return value2;
|
|
236
288
|
}
|
|
237
289
|
const value = getNumericData(t)[idx];
|
|
238
290
|
if (value === void 0) {
|
|
239
|
-
throw new
|
|
291
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
240
292
|
}
|
|
241
293
|
return typeof value === "bigint" ? value : Number(value);
|
|
242
294
|
}
|
|
243
295
|
function assert1D(t, name) {
|
|
244
296
|
if (t.ndim !== 1) {
|
|
245
|
-
throw new
|
|
297
|
+
throw new chunkZ6BGACIH_cjs.ShapeError(`${name} must be a 1D tensor`);
|
|
246
298
|
}
|
|
247
299
|
}
|
|
248
300
|
function categoryValueAt(values, index, context) {
|
|
249
301
|
const value = values[index];
|
|
250
302
|
if (value === void 0) {
|
|
251
|
-
throw new
|
|
303
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError(`Internal error: missing category at index ${index} (${context})`);
|
|
252
304
|
}
|
|
253
305
|
return value;
|
|
254
306
|
}
|
|
@@ -264,22 +316,22 @@ function inferCategoryTypeFromRows(rows, paramName) {
|
|
|
264
316
|
function emptyCategoryVectorFromClasses(classes, paramName) {
|
|
265
317
|
const categoryType = inferCategoryType(classes, paramName);
|
|
266
318
|
if (categoryType === "string") {
|
|
267
|
-
return
|
|
319
|
+
return chunk724CXHFH_cjs.empty([0], { dtype: "string" });
|
|
268
320
|
}
|
|
269
321
|
if (categoryType === "bigint") {
|
|
270
|
-
return
|
|
322
|
+
return chunk724CXHFH_cjs.empty([0], { dtype: "int64" });
|
|
271
323
|
}
|
|
272
|
-
return
|
|
324
|
+
return chunk724CXHFH_cjs.zeros([0], { dtype: "float64" });
|
|
273
325
|
}
|
|
274
326
|
function emptyCategoryMatrixFromCategories(categories, nFeatures, paramName) {
|
|
275
327
|
const categoryType = inferCategoryTypeFromRows(categories, paramName);
|
|
276
328
|
if (categoryType === "string") {
|
|
277
|
-
return
|
|
329
|
+
return chunk724CXHFH_cjs.empty([0, nFeatures], { dtype: "string" });
|
|
278
330
|
}
|
|
279
331
|
if (categoryType === "bigint") {
|
|
280
|
-
return
|
|
332
|
+
return chunk724CXHFH_cjs.empty([0, nFeatures], { dtype: "int64" });
|
|
281
333
|
}
|
|
282
|
-
return
|
|
334
|
+
return chunk724CXHFH_cjs.zeros([0, nFeatures], { dtype: "float64" });
|
|
283
335
|
}
|
|
284
336
|
function toCategoryVectorTensor(values, paramName = "y") {
|
|
285
337
|
const categoryType = inferCategoryType(values, paramName);
|
|
@@ -288,32 +340,32 @@ function toCategoryVectorTensor(values, paramName = "y") {
|
|
|
288
340
|
for (let i = 0; i < values.length; i++) {
|
|
289
341
|
const value = values[i];
|
|
290
342
|
if (typeof value !== "string") {
|
|
291
|
-
throw new
|
|
343
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: expected string category value");
|
|
292
344
|
}
|
|
293
345
|
out2[i] = value;
|
|
294
346
|
}
|
|
295
|
-
return
|
|
347
|
+
return chunk724CXHFH_cjs.tensor(out2);
|
|
296
348
|
}
|
|
297
349
|
if (categoryType === "bigint") {
|
|
298
350
|
const out2 = new BigInt64Array(values.length);
|
|
299
351
|
for (let i = 0; i < values.length; i++) {
|
|
300
352
|
const value = values[i];
|
|
301
353
|
if (typeof value !== "bigint") {
|
|
302
|
-
throw new
|
|
354
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: expected bigint category value");
|
|
303
355
|
}
|
|
304
356
|
out2[i] = value;
|
|
305
357
|
}
|
|
306
|
-
return
|
|
358
|
+
return chunk724CXHFH_cjs.tensor(out2);
|
|
307
359
|
}
|
|
308
360
|
const out = new Float64Array(values.length);
|
|
309
361
|
for (let i = 0; i < values.length; i++) {
|
|
310
362
|
const value = values[i];
|
|
311
363
|
if (value === void 0 || typeof value !== "number") {
|
|
312
|
-
throw new
|
|
364
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: expected numeric category value");
|
|
313
365
|
}
|
|
314
366
|
out[i] = value;
|
|
315
367
|
}
|
|
316
|
-
return
|
|
368
|
+
return chunk724CXHFH_cjs.tensor(out);
|
|
317
369
|
}
|
|
318
370
|
function toCategoryMatrixTensor(values, paramName = "X") {
|
|
319
371
|
const rows = values.length;
|
|
@@ -321,10 +373,10 @@ function toCategoryMatrixTensor(values, paramName = "X") {
|
|
|
321
373
|
for (let i = 0; i < rows; i++) {
|
|
322
374
|
const row = values[i];
|
|
323
375
|
if (!row) {
|
|
324
|
-
throw new
|
|
376
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing row in category matrix");
|
|
325
377
|
}
|
|
326
378
|
if (row.length !== cols) {
|
|
327
|
-
throw new
|
|
379
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("Ragged category matrix cannot be converted to tensor");
|
|
328
380
|
}
|
|
329
381
|
}
|
|
330
382
|
const flat = [];
|
|
@@ -339,49 +391,49 @@ function toCategoryMatrixTensor(values, paramName = "X") {
|
|
|
339
391
|
for (let i = 0; i < rows; i++) {
|
|
340
392
|
const row = values[i];
|
|
341
393
|
if (!row) {
|
|
342
|
-
throw new
|
|
394
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing row in category matrix");
|
|
343
395
|
}
|
|
344
396
|
const outRow = new Array(cols);
|
|
345
397
|
for (let j = 0; j < cols; j++) {
|
|
346
398
|
const value = row[j];
|
|
347
399
|
if (typeof value !== "string") {
|
|
348
|
-
throw new
|
|
400
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: expected string category value");
|
|
349
401
|
}
|
|
350
402
|
outRow[j] = value;
|
|
351
403
|
}
|
|
352
404
|
out[i] = outRow;
|
|
353
405
|
}
|
|
354
|
-
return
|
|
406
|
+
return chunk724CXHFH_cjs.tensor(out);
|
|
355
407
|
}
|
|
356
408
|
if (categoryType === "number") {
|
|
357
409
|
const out = new Array(rows);
|
|
358
410
|
for (let i = 0; i < rows; i++) {
|
|
359
411
|
const row = values[i];
|
|
360
412
|
if (!row) {
|
|
361
|
-
throw new
|
|
413
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing row in category matrix");
|
|
362
414
|
}
|
|
363
415
|
const outRow = new Array(cols);
|
|
364
416
|
for (let j = 0; j < cols; j++) {
|
|
365
417
|
const value = row[j];
|
|
366
418
|
if (typeof value !== "number") {
|
|
367
|
-
throw new
|
|
419
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: expected numeric category value");
|
|
368
420
|
}
|
|
369
421
|
outRow[j] = value;
|
|
370
422
|
}
|
|
371
423
|
out[i] = outRow;
|
|
372
424
|
}
|
|
373
|
-
return
|
|
425
|
+
return chunk724CXHFH_cjs.tensor(out, { dtype: "float64" });
|
|
374
426
|
}
|
|
375
427
|
const data = new BigInt64Array(rows * cols);
|
|
376
428
|
for (let i = 0; i < flat.length; i++) {
|
|
377
429
|
const value = flat[i];
|
|
378
430
|
if (typeof value !== "bigint") {
|
|
379
|
-
throw new
|
|
431
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: expected bigint category value");
|
|
380
432
|
}
|
|
381
433
|
data[i] = value;
|
|
382
434
|
}
|
|
383
|
-
const { defaultDevice } =
|
|
384
|
-
return
|
|
435
|
+
const { defaultDevice } = chunkZ6BGACIH_cjs.getConfig();
|
|
436
|
+
return chunk724CXHFH_cjs.Tensor.fromTypedArray({
|
|
385
437
|
data,
|
|
386
438
|
shape: [rows, cols],
|
|
387
439
|
dtype: "int64",
|
|
@@ -404,13 +456,14 @@ var LabelEncoder = class {
|
|
|
404
456
|
* @throws {InvalidParameterError} If y is empty
|
|
405
457
|
*/
|
|
406
458
|
fit(y) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
459
|
+
const t = coerceToTensor1D(y);
|
|
460
|
+
assert1D(t, "y");
|
|
461
|
+
if (t.size === 0) {
|
|
462
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Cannot fit LabelEncoder on empty array", "y");
|
|
410
463
|
}
|
|
411
464
|
const uniqueSet = /* @__PURE__ */ new Set();
|
|
412
|
-
for (let i = 0; i <
|
|
413
|
-
uniqueSet.add(read1DValue(
|
|
465
|
+
for (let i = 0; i < t.size; i++) {
|
|
466
|
+
uniqueSet.add(read1DValue(t, i));
|
|
414
467
|
}
|
|
415
468
|
this.classes_ = sortCategories(uniqueSet, "y");
|
|
416
469
|
this.classToIndex_ = /* @__PURE__ */ new Map();
|
|
@@ -431,22 +484,23 @@ var LabelEncoder = class {
|
|
|
431
484
|
*/
|
|
432
485
|
transform(y) {
|
|
433
486
|
if (!this.fitted) {
|
|
434
|
-
throw new
|
|
487
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("LabelEncoder must be fitted before transform");
|
|
435
488
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
489
|
+
const t = coerceToTensor1D(y);
|
|
490
|
+
assert1D(t, "y");
|
|
491
|
+
if (t.size === 0) {
|
|
492
|
+
return chunk724CXHFH_cjs.tensor([]);
|
|
439
493
|
}
|
|
440
494
|
const lookup = this.classToIndex_;
|
|
441
495
|
if (!this.classes_ || !lookup) {
|
|
442
|
-
throw new
|
|
496
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("LabelEncoder internal error: missing fitted state");
|
|
443
497
|
}
|
|
444
|
-
const result = new Array(
|
|
445
|
-
for (let i = 0; i <
|
|
446
|
-
const val = read1DValue(
|
|
498
|
+
const result = new Array(t.size);
|
|
499
|
+
for (let i = 0; i < t.size; i++) {
|
|
500
|
+
const val = read1DValue(t, i);
|
|
447
501
|
const idx = lookup.get(val);
|
|
448
502
|
if (idx === void 0) {
|
|
449
|
-
throw new
|
|
503
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
450
504
|
`Unknown label: ${String(val)}. Label must be present during fit.`,
|
|
451
505
|
"y",
|
|
452
506
|
val
|
|
@@ -454,7 +508,7 @@ var LabelEncoder = class {
|
|
|
454
508
|
}
|
|
455
509
|
result[i] = idx;
|
|
456
510
|
}
|
|
457
|
-
return
|
|
511
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64" });
|
|
458
512
|
}
|
|
459
513
|
/**
|
|
460
514
|
* Fit label encoder and return encoded labels in one step.
|
|
@@ -470,36 +524,37 @@ var LabelEncoder = class {
|
|
|
470
524
|
* Transform integer labels back to original encoding.
|
|
471
525
|
* Reverses the encoding performed by transform().
|
|
472
526
|
*
|
|
473
|
-
* @param y - Encoded labels (1D integer tensor)
|
|
527
|
+
* @param y - Encoded labels (1D integer tensor or number array)
|
|
474
528
|
* @returns Original labels (strings or numbers)
|
|
475
529
|
* @throws {NotFittedError} If encoder is not fitted
|
|
476
530
|
* @throws {InvalidParameterError} If y contains invalid indices
|
|
477
531
|
*/
|
|
478
532
|
inverseTransform(y) {
|
|
479
533
|
if (!this.fitted) {
|
|
480
|
-
throw new
|
|
534
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("LabelEncoder must be fitted before inverse_transform");
|
|
481
535
|
}
|
|
482
|
-
|
|
483
|
-
|
|
536
|
+
const t = coerceToTensor1D(y);
|
|
537
|
+
assert1D(t, "y");
|
|
538
|
+
assertNumericTensor(t, "y");
|
|
484
539
|
const classes = this.classes_;
|
|
485
540
|
if (!classes) {
|
|
486
|
-
throw new
|
|
541
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("LabelEncoder internal error: missing fitted state");
|
|
487
542
|
}
|
|
488
|
-
if (
|
|
543
|
+
if (t.size === 0) {
|
|
489
544
|
return emptyCategoryVectorFromClasses(classes, "y");
|
|
490
545
|
}
|
|
491
546
|
const classesLen = classes.length;
|
|
492
|
-
const result = new Array(
|
|
493
|
-
const stride = getStride1D(
|
|
494
|
-
const data = getNumericData(
|
|
495
|
-
for (let i = 0; i <
|
|
496
|
-
const raw = data[
|
|
547
|
+
const result = new Array(t.size);
|
|
548
|
+
const stride = getStride1D(t);
|
|
549
|
+
const data = getNumericData(t);
|
|
550
|
+
for (let i = 0; i < t.size; i++) {
|
|
551
|
+
const raw = data[t.offset + i * stride];
|
|
497
552
|
if (raw === void 0) {
|
|
498
|
-
throw new
|
|
553
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
499
554
|
}
|
|
500
555
|
const idx = Number(raw);
|
|
501
556
|
if (idx < 0 || idx >= classesLen || !Number.isInteger(idx)) {
|
|
502
|
-
throw new
|
|
557
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
503
558
|
`Invalid label index: ${idx}. Must be integer in [0, ${classesLen - 1}]`,
|
|
504
559
|
"y",
|
|
505
560
|
idx
|
|
@@ -541,7 +596,7 @@ var OneHotEncoder = class {
|
|
|
541
596
|
const sparseOption = options.sparse ?? options.sparseOutput ?? false;
|
|
542
597
|
if (options.sparse !== void 0 && options.sparseOutput !== void 0) {
|
|
543
598
|
if (options.sparse !== options.sparseOutput) {
|
|
544
|
-
throw new
|
|
599
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
545
600
|
"sparse and sparseOutput must match when both are provided",
|
|
546
601
|
"sparse",
|
|
547
602
|
options.sparse
|
|
@@ -553,17 +608,17 @@ var OneHotEncoder = class {
|
|
|
553
608
|
this.drop = options.drop ?? null;
|
|
554
609
|
this.categoriesOption = options.categories ?? "auto";
|
|
555
610
|
if (typeof this.sparse !== "boolean") {
|
|
556
|
-
throw new
|
|
611
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("sparse must be a boolean", "sparse", this.sparse);
|
|
557
612
|
}
|
|
558
613
|
if (this.handleUnknown !== "error" && this.handleUnknown !== "ignore") {
|
|
559
|
-
throw new
|
|
614
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
560
615
|
"handleUnknown must be 'error' or 'ignore'",
|
|
561
616
|
"handleUnknown",
|
|
562
617
|
this.handleUnknown
|
|
563
618
|
);
|
|
564
619
|
}
|
|
565
620
|
if (this.drop !== null && this.drop !== "first" && this.drop !== "if_binary") {
|
|
566
|
-
throw new
|
|
621
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
567
622
|
"drop must be 'first', 'if_binary', or null",
|
|
568
623
|
"drop",
|
|
569
624
|
this.drop
|
|
@@ -580,10 +635,11 @@ var OneHotEncoder = class {
|
|
|
580
635
|
* @throws {InvalidParameterError} If X is empty
|
|
581
636
|
*/
|
|
582
637
|
fit(X) {
|
|
583
|
-
|
|
584
|
-
|
|
638
|
+
const _X = coerceToTensor2D(X);
|
|
639
|
+
assert2D(_X, "X");
|
|
640
|
+
const [nSamples, nFeatures] = getShape2D(_X);
|
|
585
641
|
if (nSamples === 0 || nFeatures === 0) {
|
|
586
|
-
throw new
|
|
642
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Cannot fit OneHotEncoder on empty array", "X");
|
|
587
643
|
}
|
|
588
644
|
this.categories_ = [];
|
|
589
645
|
this.categoryToIndex_ = [];
|
|
@@ -597,10 +653,10 @@ var OneHotEncoder = class {
|
|
|
597
653
|
if (explicitCategories) {
|
|
598
654
|
const featureCats = explicitCategories[j];
|
|
599
655
|
if (!featureCats) {
|
|
600
|
-
throw new
|
|
656
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Missing categories for feature", "categories", j);
|
|
601
657
|
}
|
|
602
658
|
if (!Array.isArray(featureCats)) {
|
|
603
|
-
throw new
|
|
659
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
604
660
|
"categories must be an array of category arrays",
|
|
605
661
|
"categories",
|
|
606
662
|
featureCats
|
|
@@ -610,12 +666,12 @@ var OneHotEncoder = class {
|
|
|
610
666
|
} else {
|
|
611
667
|
const uniqueSet = /* @__PURE__ */ new Set();
|
|
612
668
|
for (let i = 0; i < nSamples; i++) {
|
|
613
|
-
uniqueSet.add(read2DValue(
|
|
669
|
+
uniqueSet.add(read2DValue(_X, i, j));
|
|
614
670
|
}
|
|
615
671
|
cats = sortCategories(uniqueSet, "X");
|
|
616
672
|
}
|
|
617
673
|
if (cats.length === 0) {
|
|
618
|
-
throw new
|
|
674
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Each feature must have at least one category", "X", j);
|
|
619
675
|
}
|
|
620
676
|
this.categories_.push(cats);
|
|
621
677
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -625,9 +681,9 @@ var OneHotEncoder = class {
|
|
|
625
681
|
this.categoryToIndex_.push(map);
|
|
626
682
|
if (explicitCategories) {
|
|
627
683
|
for (let i = 0; i < nSamples; i++) {
|
|
628
|
-
const val = read2DValue(
|
|
684
|
+
const val = read2DValue(_X, i, j);
|
|
629
685
|
if (!map.has(val)) {
|
|
630
|
-
throw new
|
|
686
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
631
687
|
`Unknown category: ${String(val)} in feature ${j}`,
|
|
632
688
|
"X",
|
|
633
689
|
val
|
|
@@ -656,18 +712,19 @@ var OneHotEncoder = class {
|
|
|
656
712
|
*/
|
|
657
713
|
transform(X) {
|
|
658
714
|
if (!this.fitted) {
|
|
659
|
-
throw new
|
|
715
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("OneHotEncoder must be fitted before transform");
|
|
660
716
|
}
|
|
661
|
-
|
|
662
|
-
|
|
717
|
+
const _X = coerceToTensor2D(X);
|
|
718
|
+
assert2D(_X, "X");
|
|
719
|
+
const [nSamples, nFeatures] = getShape2D(_X);
|
|
663
720
|
const categories = this.categories_;
|
|
664
721
|
const categoryMaps = this.categoryToIndex_;
|
|
665
722
|
if (!categories || !categoryMaps) {
|
|
666
|
-
throw new
|
|
723
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("OneHotEncoder internal error: missing fitted state");
|
|
667
724
|
}
|
|
668
725
|
const fittedFeatures = categories.length;
|
|
669
726
|
if (nFeatures !== fittedFeatures) {
|
|
670
|
-
throw new
|
|
727
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
671
728
|
"X has a different feature count than during fit",
|
|
672
729
|
"X",
|
|
673
730
|
nFeatures
|
|
@@ -682,13 +739,13 @@ var OneHotEncoder = class {
|
|
|
682
739
|
totalCols += cats.length - (dropIndex === null ? 0 : 1);
|
|
683
740
|
}
|
|
684
741
|
if (nSamples === 0 || nFeatures === 0) {
|
|
685
|
-
return this.sparse ?
|
|
742
|
+
return this.sparse ? chunk724CXHFH_cjs.CSRMatrix.fromCOO({
|
|
686
743
|
rows: 0,
|
|
687
744
|
cols: totalCols,
|
|
688
745
|
rowIndices: new Int32Array(0),
|
|
689
746
|
colIndices: new Int32Array(0),
|
|
690
747
|
values: new Float64Array(0)
|
|
691
|
-
}) :
|
|
748
|
+
}) : chunk724CXHFH_cjs.zeros([0, totalCols], { dtype: "float64" });
|
|
692
749
|
}
|
|
693
750
|
if (this.sparse) {
|
|
694
751
|
const rowIdx = [];
|
|
@@ -701,17 +758,17 @@ var OneHotEncoder = class {
|
|
|
701
758
|
const map = categoryMaps[j];
|
|
702
759
|
const dropIndex = dropIndices[j] ?? null;
|
|
703
760
|
if (!cats || !map) {
|
|
704
|
-
throw new
|
|
761
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("OneHotEncoder internal error: missing fitted categories");
|
|
705
762
|
}
|
|
706
763
|
const outSize = cats.length - (dropIndex === null ? 0 : 1);
|
|
707
|
-
const val = read2DValue(
|
|
764
|
+
const val = read2DValue(_X, i, j);
|
|
708
765
|
const idx = map.get(val);
|
|
709
766
|
if (idx === void 0) {
|
|
710
767
|
if (this.handleUnknown === "ignore") {
|
|
711
768
|
colOffset += outSize;
|
|
712
769
|
continue;
|
|
713
770
|
}
|
|
714
|
-
throw new
|
|
771
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(`Unknown category: ${String(val)}`, "X", val);
|
|
715
772
|
}
|
|
716
773
|
if (dropIndex !== null && idx === dropIndex) {
|
|
717
774
|
colOffset += outSize;
|
|
@@ -724,7 +781,7 @@ var OneHotEncoder = class {
|
|
|
724
781
|
colOffset += outSize;
|
|
725
782
|
}
|
|
726
783
|
}
|
|
727
|
-
return
|
|
784
|
+
return chunk724CXHFH_cjs.CSRMatrix.fromCOO({
|
|
728
785
|
rows: nSamples,
|
|
729
786
|
cols: totalCols,
|
|
730
787
|
rowIndices: Int32Array.from(rowIdx),
|
|
@@ -740,17 +797,17 @@ var OneHotEncoder = class {
|
|
|
740
797
|
const map = categoryMaps[j];
|
|
741
798
|
const dropIndex = dropIndices[j] ?? null;
|
|
742
799
|
if (!cats || !map) {
|
|
743
|
-
throw new
|
|
800
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("OneHotEncoder internal error: missing fitted categories");
|
|
744
801
|
}
|
|
745
802
|
const outSize = cats.length - (dropIndex === null ? 0 : 1);
|
|
746
|
-
const val = read2DValue(
|
|
803
|
+
const val = read2DValue(_X, i, j);
|
|
747
804
|
const idx = map.get(val);
|
|
748
805
|
if (idx === void 0) {
|
|
749
806
|
if (this.handleUnknown === "ignore") {
|
|
750
807
|
colOffset += outSize;
|
|
751
808
|
continue;
|
|
752
809
|
}
|
|
753
|
-
throw new
|
|
810
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(`Unknown category: ${String(val)}`, "X", val);
|
|
754
811
|
}
|
|
755
812
|
if (dropIndex !== null && idx === dropIndex) {
|
|
756
813
|
colOffset += outSize;
|
|
@@ -758,29 +815,29 @@ var OneHotEncoder = class {
|
|
|
758
815
|
}
|
|
759
816
|
const row = result[i];
|
|
760
817
|
if (row === void 0) {
|
|
761
|
-
throw new
|
|
818
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
762
819
|
}
|
|
763
820
|
const adjusted = dropIndex !== null && idx > dropIndex ? idx - 1 : idx;
|
|
764
821
|
row[colOffset + adjusted] = 1;
|
|
765
822
|
colOffset += outSize;
|
|
766
823
|
}
|
|
767
824
|
}
|
|
768
|
-
return
|
|
825
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: _X.device });
|
|
769
826
|
}
|
|
770
827
|
fitTransform(X) {
|
|
771
828
|
return this.fit(X).transform(X);
|
|
772
829
|
}
|
|
773
830
|
inverseTransform(X) {
|
|
774
831
|
if (!this.fitted) {
|
|
775
|
-
throw new
|
|
832
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("OneHotEncoder must be fitted before inverse_transform");
|
|
776
833
|
}
|
|
777
|
-
const dense = X instanceof
|
|
834
|
+
const dense = X instanceof chunk724CXHFH_cjs.CSRMatrix ? X.toDense() : X;
|
|
778
835
|
assert2D(dense, "X");
|
|
779
836
|
assertNumericTensor(dense, "X");
|
|
780
837
|
const [nSamples, nCols] = getShape2D(dense);
|
|
781
838
|
const categories = this.categories_;
|
|
782
839
|
if (!categories) {
|
|
783
|
-
throw new
|
|
840
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("OneHotEncoder internal error: missing fitted categories");
|
|
784
841
|
}
|
|
785
842
|
const nFeatures = categories.length;
|
|
786
843
|
const dropIndices = this.dropIndices_ ?? categories.map(() => null);
|
|
@@ -789,7 +846,7 @@ var OneHotEncoder = class {
|
|
|
789
846
|
return sum + cats.length - (dropIndex === null ? 0 : 1);
|
|
790
847
|
}, 0);
|
|
791
848
|
if (nCols !== totalCols) {
|
|
792
|
-
throw new
|
|
849
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("column count does not match fitted categories", "X", nCols);
|
|
793
850
|
}
|
|
794
851
|
if (nSamples === 0) {
|
|
795
852
|
return emptyCategoryMatrixFromCategories(categories, nFeatures, "X");
|
|
@@ -806,13 +863,13 @@ var OneHotEncoder = class {
|
|
|
806
863
|
const cats = categories[j];
|
|
807
864
|
const dropIndex = dropIndices[j] ?? null;
|
|
808
865
|
if (!cats) {
|
|
809
|
-
throw new
|
|
866
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("OneHotEncoder internal error: missing fitted categories");
|
|
810
867
|
}
|
|
811
868
|
const outSize = cats.length - (dropIndex === null ? 0 : 1);
|
|
812
869
|
if (outSize === 0) {
|
|
813
870
|
const row2 = result[i];
|
|
814
871
|
if (!row2) {
|
|
815
|
-
throw new
|
|
872
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
816
873
|
}
|
|
817
874
|
row2[j] = categoryValueAt(cats, dropIndex ?? 0, "OneHotEncoder.inverseTransform");
|
|
818
875
|
continue;
|
|
@@ -821,14 +878,14 @@ var OneHotEncoder = class {
|
|
|
821
878
|
const rowBase = dense.offset + i * stride0 + colOffset * stride1;
|
|
822
879
|
const first = denseData[rowBase];
|
|
823
880
|
if (first === void 0) {
|
|
824
|
-
throw new
|
|
881
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
825
882
|
}
|
|
826
883
|
let maxVal = Number(first);
|
|
827
884
|
let hasPositive = maxVal > 0;
|
|
828
885
|
for (let k = 1; k < outSize; k++) {
|
|
829
886
|
const raw = denseData[rowBase + k * stride1];
|
|
830
887
|
if (raw === void 0) {
|
|
831
|
-
throw new
|
|
888
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
832
889
|
}
|
|
833
890
|
const val = Number(raw);
|
|
834
891
|
if (val > maxVal) {
|
|
@@ -841,18 +898,18 @@ var OneHotEncoder = class {
|
|
|
841
898
|
}
|
|
842
899
|
const row = result[i];
|
|
843
900
|
if (row === void 0) {
|
|
844
|
-
throw new
|
|
901
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
845
902
|
}
|
|
846
903
|
if (!hasPositive) {
|
|
847
904
|
if (dropIndex !== null) {
|
|
848
905
|
row[j] = categoryValueAt(cats, dropIndex, "OneHotEncoder.inverseTransform");
|
|
849
906
|
} else if (this.handleUnknown === "ignore") {
|
|
850
|
-
throw new
|
|
907
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
851
908
|
"Cannot inverse-transform: sample contains no active category (all zeros). This may happen if unknown categories were ignored during transform.",
|
|
852
909
|
"X"
|
|
853
910
|
);
|
|
854
911
|
} else {
|
|
855
|
-
throw new
|
|
912
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Invalid one-hot encoding: all zeros", "X");
|
|
856
913
|
}
|
|
857
914
|
} else {
|
|
858
915
|
const actualIdx = dropIndex !== null && maxIdx >= dropIndex ? maxIdx + 1 : maxIdx;
|
|
@@ -890,21 +947,21 @@ var OrdinalEncoder = class {
|
|
|
890
947
|
this.unknownValue = options.unknownValue ?? -1;
|
|
891
948
|
this.categoriesOption = options.categories ?? "auto";
|
|
892
949
|
if (this.handleUnknown !== "error" && this.handleUnknown !== "useEncodedValue") {
|
|
893
|
-
throw new
|
|
950
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
894
951
|
"handleUnknown must be 'error' or 'useEncodedValue'",
|
|
895
952
|
"handleUnknown",
|
|
896
953
|
this.handleUnknown
|
|
897
954
|
);
|
|
898
955
|
}
|
|
899
956
|
if (!Number.isFinite(this.unknownValue) && !Number.isNaN(this.unknownValue)) {
|
|
900
|
-
throw new
|
|
957
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
901
958
|
"unknownValue must be a finite number or NaN",
|
|
902
959
|
"unknownValue",
|
|
903
960
|
this.unknownValue
|
|
904
961
|
);
|
|
905
962
|
}
|
|
906
963
|
if (Number.isFinite(this.unknownValue) && !Number.isInteger(this.unknownValue)) {
|
|
907
|
-
throw new
|
|
964
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
908
965
|
"unknownValue must be an integer when finite",
|
|
909
966
|
"unknownValue",
|
|
910
967
|
this.unknownValue
|
|
@@ -920,10 +977,11 @@ var OrdinalEncoder = class {
|
|
|
920
977
|
* @throws {InvalidParameterError} If X is empty
|
|
921
978
|
*/
|
|
922
979
|
fit(X) {
|
|
923
|
-
|
|
924
|
-
|
|
980
|
+
const _X = coerceToTensor2D(X);
|
|
981
|
+
assert2D(_X, "X");
|
|
982
|
+
const [nSamples, nFeatures] = getShape2D(_X);
|
|
925
983
|
if (nSamples === 0) {
|
|
926
|
-
throw new
|
|
984
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Cannot fit OrdinalEncoder on empty array", "X");
|
|
927
985
|
}
|
|
928
986
|
this.categories_ = [];
|
|
929
987
|
this.categoryToIndex_ = [];
|
|
@@ -937,10 +995,10 @@ var OrdinalEncoder = class {
|
|
|
937
995
|
if (explicitCategories) {
|
|
938
996
|
const featureCats = explicitCategories[j];
|
|
939
997
|
if (!featureCats) {
|
|
940
|
-
throw new
|
|
998
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Missing categories for feature", "categories", j);
|
|
941
999
|
}
|
|
942
1000
|
if (!Array.isArray(featureCats)) {
|
|
943
|
-
throw new
|
|
1001
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
944
1002
|
"categories must be an array of category arrays",
|
|
945
1003
|
"categories",
|
|
946
1004
|
featureCats
|
|
@@ -950,12 +1008,12 @@ var OrdinalEncoder = class {
|
|
|
950
1008
|
} else {
|
|
951
1009
|
const uniqueSet = /* @__PURE__ */ new Set();
|
|
952
1010
|
for (let i = 0; i < nSamples; i++) {
|
|
953
|
-
uniqueSet.add(read2DValue(
|
|
1011
|
+
uniqueSet.add(read2DValue(_X, i, j));
|
|
954
1012
|
}
|
|
955
1013
|
sorted = sortCategories(uniqueSet, "X");
|
|
956
1014
|
}
|
|
957
1015
|
if (sorted.length === 0) {
|
|
958
|
-
throw new
|
|
1016
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Each feature must have at least one category", "X", j);
|
|
959
1017
|
}
|
|
960
1018
|
this.categories_.push(sorted);
|
|
961
1019
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -965,9 +1023,9 @@ var OrdinalEncoder = class {
|
|
|
965
1023
|
this.categoryToIndex_.push(map);
|
|
966
1024
|
if (explicitCategories) {
|
|
967
1025
|
for (let i = 0; i < nSamples; i++) {
|
|
968
|
-
const val = read2DValue(
|
|
1026
|
+
const val = read2DValue(_X, i, j);
|
|
969
1027
|
if (!map.has(val)) {
|
|
970
|
-
throw new
|
|
1028
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
971
1029
|
`Unknown category: ${String(val)} in feature ${j}`,
|
|
972
1030
|
"X",
|
|
973
1031
|
val
|
|
@@ -977,7 +1035,7 @@ var OrdinalEncoder = class {
|
|
|
977
1035
|
}
|
|
978
1036
|
if (this.handleUnknown === "useEncodedValue") {
|
|
979
1037
|
if (Number.isFinite(this.unknownValue) && this.unknownValue >= 0 && this.unknownValue < sorted.length) {
|
|
980
|
-
throw new
|
|
1038
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
981
1039
|
"unknownValue must be outside the range of encoded categories",
|
|
982
1040
|
"unknownValue",
|
|
983
1041
|
this.unknownValue
|
|
@@ -999,20 +1057,21 @@ var OrdinalEncoder = class {
|
|
|
999
1057
|
*/
|
|
1000
1058
|
transform(X) {
|
|
1001
1059
|
if (!this.fitted) {
|
|
1002
|
-
throw new
|
|
1060
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("OrdinalEncoder must be fitted before transform");
|
|
1003
1061
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1062
|
+
const _X = coerceToTensor2D(X);
|
|
1063
|
+
assert2D(_X, "X");
|
|
1064
|
+
const [nSamples, nFeatures] = getShape2D(_X);
|
|
1006
1065
|
const fittedFeatures = this.categories_?.length ?? 0;
|
|
1007
1066
|
if (nFeatures !== fittedFeatures) {
|
|
1008
|
-
throw new
|
|
1067
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1009
1068
|
"X has a different feature count than during fit",
|
|
1010
1069
|
"X",
|
|
1011
1070
|
nFeatures
|
|
1012
1071
|
);
|
|
1013
1072
|
}
|
|
1014
1073
|
if (nSamples === 0) {
|
|
1015
|
-
return
|
|
1074
|
+
return chunk724CXHFH_cjs.zeros([0, nFeatures], { dtype: "float64" });
|
|
1016
1075
|
}
|
|
1017
1076
|
const result = new Array(nSamples);
|
|
1018
1077
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -1020,22 +1079,22 @@ var OrdinalEncoder = class {
|
|
|
1020
1079
|
}
|
|
1021
1080
|
for (let i = 0; i < nSamples; i++) {
|
|
1022
1081
|
for (let j = 0; j < nFeatures; j++) {
|
|
1023
|
-
const val = read2DValue(
|
|
1082
|
+
const val = read2DValue(_X, i, j);
|
|
1024
1083
|
const map = this.categoryToIndex_?.[j];
|
|
1025
1084
|
if (!map) {
|
|
1026
|
-
throw new
|
|
1085
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("OrdinalEncoder internal error: missing fitted categories");
|
|
1027
1086
|
}
|
|
1028
1087
|
const idx = map.get(val);
|
|
1029
1088
|
const row = result[i];
|
|
1030
1089
|
if (!row) {
|
|
1031
|
-
throw new
|
|
1090
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
1032
1091
|
}
|
|
1033
1092
|
if (idx === void 0) {
|
|
1034
1093
|
if (this.handleUnknown === "useEncodedValue") {
|
|
1035
1094
|
row[j] = this.unknownValue;
|
|
1036
1095
|
continue;
|
|
1037
1096
|
}
|
|
1038
|
-
throw new
|
|
1097
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1039
1098
|
`Unknown category: ${String(val)} in feature ${j}`,
|
|
1040
1099
|
"X",
|
|
1041
1100
|
val
|
|
@@ -1044,7 +1103,7 @@ var OrdinalEncoder = class {
|
|
|
1044
1103
|
row[j] = idx;
|
|
1045
1104
|
}
|
|
1046
1105
|
}
|
|
1047
|
-
return
|
|
1106
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64" });
|
|
1048
1107
|
}
|
|
1049
1108
|
/**
|
|
1050
1109
|
* Fit encoder and transform X in one step.
|
|
@@ -1067,14 +1126,15 @@ var OrdinalEncoder = class {
|
|
|
1067
1126
|
*/
|
|
1068
1127
|
inverseTransform(X) {
|
|
1069
1128
|
if (!this.fitted) {
|
|
1070
|
-
throw new
|
|
1129
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("OrdinalEncoder must be fitted before inverse_transform");
|
|
1071
1130
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1131
|
+
const _X = coerceToTensor2D(X);
|
|
1132
|
+
assert2D(_X, "X");
|
|
1133
|
+
assertNumericTensor(_X, "X");
|
|
1134
|
+
const [nSamples, nFeatures] = getShape2D(_X);
|
|
1075
1135
|
const fittedFeatures = this.categories_?.length ?? 0;
|
|
1076
1136
|
if (nFeatures !== fittedFeatures) {
|
|
1077
|
-
throw new
|
|
1137
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1078
1138
|
"X has a different feature count than during fit",
|
|
1079
1139
|
"X",
|
|
1080
1140
|
nFeatures
|
|
@@ -1084,29 +1144,29 @@ var OrdinalEncoder = class {
|
|
|
1084
1144
|
const categoryRows = this.categories_ ?? [];
|
|
1085
1145
|
const categoryType = inferCategoryTypeFromRows(categoryRows, "X");
|
|
1086
1146
|
if (categoryType === "string") {
|
|
1087
|
-
return
|
|
1147
|
+
return chunk724CXHFH_cjs.empty([0, nFeatures], { dtype: "string" });
|
|
1088
1148
|
}
|
|
1089
1149
|
if (categoryType === "bigint") {
|
|
1090
|
-
return
|
|
1150
|
+
return chunk724CXHFH_cjs.empty([0, nFeatures], { dtype: "int64" });
|
|
1091
1151
|
}
|
|
1092
|
-
return
|
|
1152
|
+
return chunk724CXHFH_cjs.zeros([0, nFeatures], { dtype: "float64" });
|
|
1093
1153
|
}
|
|
1094
1154
|
const result = new Array(nSamples);
|
|
1095
1155
|
for (let i = 0; i < nSamples; i++) {
|
|
1096
1156
|
result[i] = new Array(nFeatures);
|
|
1097
1157
|
}
|
|
1098
|
-
const [stride0, stride1] = getStrides2D(
|
|
1099
|
-
const data = getNumericData(
|
|
1158
|
+
const [stride0, stride1] = getStrides2D(_X);
|
|
1159
|
+
const data = getNumericData(_X);
|
|
1100
1160
|
for (let i = 0; i < nSamples; i++) {
|
|
1101
1161
|
for (let j = 0; j < nFeatures; j++) {
|
|
1102
|
-
const raw = data[
|
|
1162
|
+
const raw = data[_X.offset + i * stride0 + j * stride1];
|
|
1103
1163
|
if (raw === void 0) {
|
|
1104
|
-
throw new
|
|
1164
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1105
1165
|
}
|
|
1106
1166
|
const idx = Number(raw);
|
|
1107
1167
|
const isUnknownValue = this.handleUnknown === "useEncodedValue" && (Number.isNaN(idx) ? Number.isNaN(this.unknownValue) : idx === this.unknownValue);
|
|
1108
1168
|
if (isUnknownValue) {
|
|
1109
|
-
throw new
|
|
1169
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1110
1170
|
"Cannot inverse-transform unknown encoded value",
|
|
1111
1171
|
"X",
|
|
1112
1172
|
idx
|
|
@@ -1114,7 +1174,7 @@ var OrdinalEncoder = class {
|
|
|
1114
1174
|
}
|
|
1115
1175
|
const cats = this.categories_?.[j];
|
|
1116
1176
|
if (!cats || idx < 0 || idx >= cats.length || !Number.isInteger(idx)) {
|
|
1117
|
-
throw new
|
|
1177
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1118
1178
|
`Invalid encoded value: ${idx} for feature ${j}. Must be integer in [0, ${(cats?.length ?? 0) - 1}]`,
|
|
1119
1179
|
"X",
|
|
1120
1180
|
idx
|
|
@@ -1122,11 +1182,11 @@ var OrdinalEncoder = class {
|
|
|
1122
1182
|
}
|
|
1123
1183
|
const row = result[i];
|
|
1124
1184
|
if (!row) {
|
|
1125
|
-
throw new
|
|
1185
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
1126
1186
|
}
|
|
1127
1187
|
const catVal = cats[idx];
|
|
1128
1188
|
if (catVal === void 0) {
|
|
1129
|
-
throw new
|
|
1189
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: category value missing");
|
|
1130
1190
|
}
|
|
1131
1191
|
row[j] = catVal;
|
|
1132
1192
|
}
|
|
@@ -1161,10 +1221,10 @@ var LabelBinarizer = class {
|
|
|
1161
1221
|
this.negLabel = options.negLabel ?? 0;
|
|
1162
1222
|
const sparseOption = options.sparse ?? options.sparseOutput ?? false;
|
|
1163
1223
|
if (!Number.isFinite(this.posLabel) || !Number.isFinite(this.negLabel)) {
|
|
1164
|
-
throw new
|
|
1224
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("posLabel and negLabel must be finite numbers", "posLabel");
|
|
1165
1225
|
}
|
|
1166
1226
|
if (this.posLabel <= this.negLabel) {
|
|
1167
|
-
throw new
|
|
1227
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1168
1228
|
"posLabel must be greater than negLabel",
|
|
1169
1229
|
"posLabel",
|
|
1170
1230
|
this.posLabel
|
|
@@ -1172,7 +1232,7 @@ var LabelBinarizer = class {
|
|
|
1172
1232
|
}
|
|
1173
1233
|
if (options.sparse !== void 0 && options.sparseOutput !== void 0) {
|
|
1174
1234
|
if (options.sparse !== options.sparseOutput) {
|
|
1175
|
-
throw new
|
|
1235
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1176
1236
|
"sparse and sparseOutput must match when both are provided",
|
|
1177
1237
|
"sparse",
|
|
1178
1238
|
options.sparse
|
|
@@ -1180,10 +1240,10 @@ var LabelBinarizer = class {
|
|
|
1180
1240
|
}
|
|
1181
1241
|
}
|
|
1182
1242
|
if (typeof sparseOption !== "boolean") {
|
|
1183
|
-
throw new
|
|
1243
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("sparse must be a boolean", "sparse", sparseOption);
|
|
1184
1244
|
}
|
|
1185
1245
|
if (sparseOption && this.negLabel !== 0) {
|
|
1186
|
-
throw new
|
|
1246
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1187
1247
|
"sparse output requires negLabel to be 0",
|
|
1188
1248
|
"negLabel",
|
|
1189
1249
|
this.negLabel
|
|
@@ -1200,13 +1260,14 @@ var LabelBinarizer = class {
|
|
|
1200
1260
|
* @throws {InvalidParameterError} If y is empty
|
|
1201
1261
|
*/
|
|
1202
1262
|
fit(y) {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1263
|
+
const _y = coerceToTensor1D(y);
|
|
1264
|
+
assert1D(_y, "y");
|
|
1265
|
+
if (_y.size === 0) {
|
|
1266
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Cannot fit LabelBinarizer on empty array", "y");
|
|
1206
1267
|
}
|
|
1207
1268
|
const uniqueSet = /* @__PURE__ */ new Set();
|
|
1208
|
-
for (let i = 0; i <
|
|
1209
|
-
uniqueSet.add(read1DValue(
|
|
1269
|
+
for (let i = 0; i < _y.size; i++) {
|
|
1270
|
+
uniqueSet.add(read1DValue(_y, i));
|
|
1210
1271
|
}
|
|
1211
1272
|
this.classes_ = sortCategories(uniqueSet, "y");
|
|
1212
1273
|
this.classToIndex_ = /* @__PURE__ */ new Map();
|
|
@@ -1227,34 +1288,35 @@ var LabelBinarizer = class {
|
|
|
1227
1288
|
*/
|
|
1228
1289
|
transform(y) {
|
|
1229
1290
|
if (!this.fitted) {
|
|
1230
|
-
throw new
|
|
1291
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("LabelBinarizer must be fitted before transform");
|
|
1231
1292
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1293
|
+
const _y = coerceToTensor1D(y);
|
|
1294
|
+
assert1D(_y, "y");
|
|
1295
|
+
if (_y.size === 0) {
|
|
1234
1296
|
const nClasses2 = this.classes_?.length ?? 0;
|
|
1235
|
-
return this.sparse ?
|
|
1297
|
+
return this.sparse ? chunk724CXHFH_cjs.CSRMatrix.fromCOO({
|
|
1236
1298
|
rows: 0,
|
|
1237
1299
|
cols: nClasses2,
|
|
1238
1300
|
rowIndices: new Int32Array(0),
|
|
1239
1301
|
colIndices: new Int32Array(0),
|
|
1240
1302
|
values: new Float64Array(0)
|
|
1241
|
-
}) :
|
|
1303
|
+
}) : chunk724CXHFH_cjs.zeros([0, nClasses2], { dtype: "float64" });
|
|
1242
1304
|
}
|
|
1243
|
-
const nSamples =
|
|
1305
|
+
const nSamples = _y.size;
|
|
1244
1306
|
const nClasses = this.classes_?.length ?? 0;
|
|
1245
1307
|
const lookup = this.classToIndex_;
|
|
1246
1308
|
if (!lookup) {
|
|
1247
|
-
throw new
|
|
1309
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("LabelBinarizer internal error: missing fitted lookup");
|
|
1248
1310
|
}
|
|
1249
1311
|
if (this.sparse) {
|
|
1250
1312
|
const rowIdx = [];
|
|
1251
1313
|
const colIdx = [];
|
|
1252
1314
|
const vals = [];
|
|
1253
1315
|
for (let i = 0; i < nSamples; i++) {
|
|
1254
|
-
const val = read1DValue(
|
|
1316
|
+
const val = read1DValue(_y, i);
|
|
1255
1317
|
const idx = lookup.get(val);
|
|
1256
1318
|
if (idx === void 0) {
|
|
1257
|
-
throw new
|
|
1319
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1258
1320
|
`Unknown label: ${String(val)}. Label must be present during fit.`,
|
|
1259
1321
|
"y",
|
|
1260
1322
|
val
|
|
@@ -1264,7 +1326,7 @@ var LabelBinarizer = class {
|
|
|
1264
1326
|
colIdx.push(idx);
|
|
1265
1327
|
vals.push(this.posLabel);
|
|
1266
1328
|
}
|
|
1267
|
-
return
|
|
1329
|
+
return chunk724CXHFH_cjs.CSRMatrix.fromCOO({
|
|
1268
1330
|
rows: nSamples,
|
|
1269
1331
|
cols: nClasses,
|
|
1270
1332
|
rowIndices: Int32Array.from(rowIdx),
|
|
@@ -1277,10 +1339,10 @@ var LabelBinarizer = class {
|
|
|
1277
1339
|
result[i] = new Array(nClasses).fill(this.negLabel);
|
|
1278
1340
|
}
|
|
1279
1341
|
for (let i = 0; i < nSamples; i++) {
|
|
1280
|
-
const val = read1DValue(
|
|
1342
|
+
const val = read1DValue(_y, i);
|
|
1281
1343
|
const idx = lookup.get(val);
|
|
1282
1344
|
if (idx === void 0) {
|
|
1283
|
-
throw new
|
|
1345
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1284
1346
|
`Unknown label: ${String(val)}. Label must be present during fit.`,
|
|
1285
1347
|
"y",
|
|
1286
1348
|
val
|
|
@@ -1288,11 +1350,11 @@ var LabelBinarizer = class {
|
|
|
1288
1350
|
}
|
|
1289
1351
|
const row = result[i];
|
|
1290
1352
|
if (!row) {
|
|
1291
|
-
throw new
|
|
1353
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
1292
1354
|
}
|
|
1293
1355
|
row[idx] = this.posLabel;
|
|
1294
1356
|
}
|
|
1295
|
-
return
|
|
1357
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64" });
|
|
1296
1358
|
}
|
|
1297
1359
|
/**
|
|
1298
1360
|
* Fit binarizer and transform labels in one step.
|
|
@@ -1315,11 +1377,11 @@ var LabelBinarizer = class {
|
|
|
1315
1377
|
*/
|
|
1316
1378
|
inverseTransform(Y) {
|
|
1317
1379
|
if (!this.fitted) {
|
|
1318
|
-
throw new
|
|
1380
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("LabelBinarizer must be fitted before inverse_transform");
|
|
1319
1381
|
}
|
|
1320
|
-
if (Y instanceof
|
|
1382
|
+
if (Y instanceof chunk724CXHFH_cjs.CSRMatrix) {
|
|
1321
1383
|
if (this.negLabel !== 0) {
|
|
1322
|
-
throw new
|
|
1384
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1323
1385
|
"Sparse inverse transform requires negLabel to be 0",
|
|
1324
1386
|
"negLabel",
|
|
1325
1387
|
this.negLabel
|
|
@@ -1327,15 +1389,15 @@ var LabelBinarizer = class {
|
|
|
1327
1389
|
}
|
|
1328
1390
|
const [rows, cols] = Y.shape;
|
|
1329
1391
|
if (rows === void 0 || cols === void 0) {
|
|
1330
|
-
throw new
|
|
1392
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("Y must have valid shape");
|
|
1331
1393
|
}
|
|
1332
1394
|
const nClasses2 = this.classes_?.length ?? 0;
|
|
1333
1395
|
if (cols !== nClasses2) {
|
|
1334
|
-
throw new
|
|
1396
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("column count does not match number of classes", "Y", cols);
|
|
1335
1397
|
}
|
|
1336
1398
|
const classes2 = this.classes_;
|
|
1337
1399
|
if (!classes2) {
|
|
1338
|
-
throw new
|
|
1400
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("LabelBinarizer internal error: missing fitted classes");
|
|
1339
1401
|
}
|
|
1340
1402
|
if (rows === 0) {
|
|
1341
1403
|
return emptyCategoryVectorFromClasses(classes2, "y");
|
|
@@ -1349,10 +1411,10 @@ var LabelBinarizer = class {
|
|
|
1349
1411
|
for (let p = start; p < end; p++) {
|
|
1350
1412
|
const col = Y.indices[p];
|
|
1351
1413
|
if (col === void 0) {
|
|
1352
|
-
throw new
|
|
1414
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: sparse column index missing");
|
|
1353
1415
|
}
|
|
1354
1416
|
if (col < 0 || col >= nClasses2) {
|
|
1355
|
-
throw new
|
|
1417
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1356
1418
|
"column index out of bounds for fitted classes",
|
|
1357
1419
|
"Y",
|
|
1358
1420
|
col
|
|
@@ -1360,7 +1422,7 @@ var LabelBinarizer = class {
|
|
|
1360
1422
|
}
|
|
1361
1423
|
const raw = Y.data[p];
|
|
1362
1424
|
if (raw === void 0) {
|
|
1363
|
-
throw new
|
|
1425
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: sparse value missing");
|
|
1364
1426
|
}
|
|
1365
1427
|
const val = Number(raw);
|
|
1366
1428
|
if (val > maxVal) {
|
|
@@ -1369,7 +1431,7 @@ var LabelBinarizer = class {
|
|
|
1369
1431
|
}
|
|
1370
1432
|
}
|
|
1371
1433
|
if (maxVal <= this.negLabel) {
|
|
1372
|
-
throw new
|
|
1434
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1373
1435
|
`No active label found for sample ${i}. LabelBinarizer expects exactly one active label.`,
|
|
1374
1436
|
"Y"
|
|
1375
1437
|
);
|
|
@@ -1383,11 +1445,11 @@ var LabelBinarizer = class {
|
|
|
1383
1445
|
const [nSamples, nCols] = getShape2D(Y);
|
|
1384
1446
|
const nClasses = this.classes_?.length ?? 0;
|
|
1385
1447
|
if (nCols !== nClasses) {
|
|
1386
|
-
throw new
|
|
1448
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("column count does not match number of classes", "Y", nCols);
|
|
1387
1449
|
}
|
|
1388
1450
|
const classes = this.classes_;
|
|
1389
1451
|
if (!classes) {
|
|
1390
|
-
throw new
|
|
1452
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("LabelBinarizer internal error: missing fitted classes");
|
|
1391
1453
|
}
|
|
1392
1454
|
if (nSamples === 0) {
|
|
1393
1455
|
return emptyCategoryVectorFromClasses(classes, "y");
|
|
@@ -1400,13 +1462,13 @@ var LabelBinarizer = class {
|
|
|
1400
1462
|
const rowBase = Y.offset + i * stride0;
|
|
1401
1463
|
const first = data[rowBase];
|
|
1402
1464
|
if (first === void 0) {
|
|
1403
|
-
throw new
|
|
1465
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1404
1466
|
}
|
|
1405
1467
|
let maxVal = Number(first);
|
|
1406
1468
|
for (let j = 1; j < nCols; j++) {
|
|
1407
1469
|
const raw = data[rowBase + j * stride1];
|
|
1408
1470
|
if (raw === void 0) {
|
|
1409
|
-
throw new
|
|
1471
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1410
1472
|
}
|
|
1411
1473
|
const val = Number(raw);
|
|
1412
1474
|
if (val > maxVal) {
|
|
@@ -1415,7 +1477,7 @@ var LabelBinarizer = class {
|
|
|
1415
1477
|
}
|
|
1416
1478
|
}
|
|
1417
1479
|
if (maxVal <= this.negLabel) {
|
|
1418
|
-
throw new
|
|
1480
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1419
1481
|
`No active label found for sample ${i}. LabelBinarizer expects exactly one active label.`,
|
|
1420
1482
|
"Y"
|
|
1421
1483
|
);
|
|
@@ -1448,7 +1510,7 @@ var MultiLabelBinarizer = class {
|
|
|
1448
1510
|
const sparseOption = options.sparse ?? options.sparseOutput ?? false;
|
|
1449
1511
|
if (options.sparse !== void 0 && options.sparseOutput !== void 0) {
|
|
1450
1512
|
if (options.sparse !== options.sparseOutput) {
|
|
1451
|
-
throw new
|
|
1513
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1452
1514
|
"sparse and sparseOutput must match when both are provided",
|
|
1453
1515
|
"sparse",
|
|
1454
1516
|
options.sparse
|
|
@@ -1457,7 +1519,7 @@ var MultiLabelBinarizer = class {
|
|
|
1457
1519
|
}
|
|
1458
1520
|
this.sparse = sparseOption;
|
|
1459
1521
|
if (typeof this.sparse !== "boolean") {
|
|
1460
|
-
throw new
|
|
1522
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("sparse must be a boolean", "sparse", this.sparse);
|
|
1461
1523
|
}
|
|
1462
1524
|
if (options.classes !== void 0) {
|
|
1463
1525
|
this.classesOption = validateCategoryValues(options.classes, "classes");
|
|
@@ -1473,15 +1535,15 @@ var MultiLabelBinarizer = class {
|
|
|
1473
1535
|
*/
|
|
1474
1536
|
fit(y) {
|
|
1475
1537
|
if (y.length === 0) {
|
|
1476
|
-
throw new
|
|
1538
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Cannot fit MultiLabelBinarizer on empty array", "y");
|
|
1477
1539
|
}
|
|
1478
1540
|
for (const labels of y) {
|
|
1479
1541
|
if (!Array.isArray(labels)) {
|
|
1480
|
-
throw new
|
|
1542
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("MultiLabelBinarizer expects label arrays", "y", labels);
|
|
1481
1543
|
}
|
|
1482
1544
|
for (const label of labels) {
|
|
1483
1545
|
if (typeof label !== "string" && typeof label !== "number" && typeof label !== "bigint") {
|
|
1484
|
-
throw new
|
|
1546
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1485
1547
|
"MultiLabelBinarizer labels must be strings, numbers, or bigints",
|
|
1486
1548
|
"y",
|
|
1487
1549
|
label
|
|
@@ -1490,7 +1552,7 @@ var MultiLabelBinarizer = class {
|
|
|
1490
1552
|
}
|
|
1491
1553
|
}
|
|
1492
1554
|
if (this.classesOption && this.classesOption.length === 0) {
|
|
1493
|
-
throw new
|
|
1555
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("classes must contain at least one value", "classes");
|
|
1494
1556
|
}
|
|
1495
1557
|
if (this.classesOption) {
|
|
1496
1558
|
this.classes_ = Array.from(this.classesOption);
|
|
@@ -1511,7 +1573,7 @@ var MultiLabelBinarizer = class {
|
|
|
1511
1573
|
for (const labels of y) {
|
|
1512
1574
|
for (const label of labels) {
|
|
1513
1575
|
if (!this.classToIndex_.has(label)) {
|
|
1514
|
-
throw new
|
|
1576
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1515
1577
|
`Unknown label: ${String(label)}. Label must be present in classes.`,
|
|
1516
1578
|
"y",
|
|
1517
1579
|
label
|
|
@@ -1534,15 +1596,15 @@ var MultiLabelBinarizer = class {
|
|
|
1534
1596
|
*/
|
|
1535
1597
|
transform(y) {
|
|
1536
1598
|
if (!this.fitted) {
|
|
1537
|
-
throw new
|
|
1599
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("MultiLabelBinarizer must be fitted before transform");
|
|
1538
1600
|
}
|
|
1539
1601
|
for (const labels of y) {
|
|
1540
1602
|
if (!Array.isArray(labels)) {
|
|
1541
|
-
throw new
|
|
1603
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("MultiLabelBinarizer expects label arrays", "y", labels);
|
|
1542
1604
|
}
|
|
1543
1605
|
for (const label of labels) {
|
|
1544
1606
|
if (typeof label !== "string" && typeof label !== "number" && typeof label !== "bigint") {
|
|
1545
|
-
throw new
|
|
1607
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1546
1608
|
"MultiLabelBinarizer labels must be strings, numbers, or bigints",
|
|
1547
1609
|
"y",
|
|
1548
1610
|
label
|
|
@@ -1552,19 +1614,19 @@ var MultiLabelBinarizer = class {
|
|
|
1552
1614
|
}
|
|
1553
1615
|
if (y.length === 0) {
|
|
1554
1616
|
const nClasses2 = this.classes_?.length ?? 0;
|
|
1555
|
-
return this.sparse ?
|
|
1617
|
+
return this.sparse ? chunk724CXHFH_cjs.CSRMatrix.fromCOO({
|
|
1556
1618
|
rows: 0,
|
|
1557
1619
|
cols: nClasses2,
|
|
1558
1620
|
rowIndices: new Int32Array(0),
|
|
1559
1621
|
colIndices: new Int32Array(0),
|
|
1560
1622
|
values: new Float64Array(0)
|
|
1561
|
-
}) :
|
|
1623
|
+
}) : chunk724CXHFH_cjs.zeros([0, nClasses2], { dtype: "float64" });
|
|
1562
1624
|
}
|
|
1563
1625
|
const nSamples = y.length;
|
|
1564
1626
|
const nClasses = this.classes_?.length ?? 0;
|
|
1565
1627
|
const lookup = this.classToIndex_;
|
|
1566
1628
|
if (!lookup) {
|
|
1567
|
-
throw new
|
|
1629
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("MultiLabelBinarizer internal error: missing fitted lookup");
|
|
1568
1630
|
}
|
|
1569
1631
|
if (this.sparse) {
|
|
1570
1632
|
const rowIdx = [];
|
|
@@ -1577,7 +1639,7 @@ var MultiLabelBinarizer = class {
|
|
|
1577
1639
|
for (const label of yRow) {
|
|
1578
1640
|
const idx = lookup.get(label);
|
|
1579
1641
|
if (idx === void 0) {
|
|
1580
|
-
throw new
|
|
1642
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1581
1643
|
`Unknown label: ${String(label)}. Label must be present during fit.`,
|
|
1582
1644
|
"y",
|
|
1583
1645
|
label
|
|
@@ -1590,7 +1652,7 @@ var MultiLabelBinarizer = class {
|
|
|
1590
1652
|
vals.push(1);
|
|
1591
1653
|
}
|
|
1592
1654
|
}
|
|
1593
|
-
return
|
|
1655
|
+
return chunk724CXHFH_cjs.CSRMatrix.fromCOO({
|
|
1594
1656
|
rows: nSamples,
|
|
1595
1657
|
cols: nClasses,
|
|
1596
1658
|
rowIndices: Int32Array.from(rowIdx),
|
|
@@ -1608,7 +1670,7 @@ var MultiLabelBinarizer = class {
|
|
|
1608
1670
|
for (const label of yRow) {
|
|
1609
1671
|
const idx = lookup.get(label);
|
|
1610
1672
|
if (idx === void 0) {
|
|
1611
|
-
throw new
|
|
1673
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1612
1674
|
`Unknown label: ${String(label)}. Label must be present during fit.`,
|
|
1613
1675
|
"y",
|
|
1614
1676
|
label
|
|
@@ -1616,12 +1678,12 @@ var MultiLabelBinarizer = class {
|
|
|
1616
1678
|
}
|
|
1617
1679
|
const row = result[i];
|
|
1618
1680
|
if (!row) {
|
|
1619
|
-
throw new
|
|
1681
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
1620
1682
|
}
|
|
1621
1683
|
row[idx] = 1;
|
|
1622
1684
|
}
|
|
1623
1685
|
}
|
|
1624
|
-
return
|
|
1686
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64" });
|
|
1625
1687
|
}
|
|
1626
1688
|
/**
|
|
1627
1689
|
* Fit binarizer and transform label sets in one step.
|
|
@@ -1644,23 +1706,23 @@ var MultiLabelBinarizer = class {
|
|
|
1644
1706
|
*/
|
|
1645
1707
|
inverseTransform(Y) {
|
|
1646
1708
|
if (!this.fitted) {
|
|
1647
|
-
throw new
|
|
1709
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("MultiLabelBinarizer must be fitted before inverse_transform");
|
|
1648
1710
|
}
|
|
1649
|
-
if (Y instanceof
|
|
1711
|
+
if (Y instanceof chunk724CXHFH_cjs.CSRMatrix) {
|
|
1650
1712
|
const [rows, cols] = Y.shape;
|
|
1651
1713
|
if (rows === void 0 || cols === void 0) {
|
|
1652
|
-
throw new
|
|
1714
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("Y must have valid shape");
|
|
1653
1715
|
}
|
|
1654
1716
|
const fittedClasses2 = this.classes_?.length ?? 0;
|
|
1655
1717
|
if (cols !== fittedClasses2) {
|
|
1656
|
-
throw new
|
|
1718
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("column count does not match number of classes", "Y", cols);
|
|
1657
1719
|
}
|
|
1658
1720
|
if (rows === 0) {
|
|
1659
1721
|
return [];
|
|
1660
1722
|
}
|
|
1661
1723
|
const classes2 = this.classes_;
|
|
1662
1724
|
if (!classes2) {
|
|
1663
|
-
throw new
|
|
1725
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("MultiLabelBinarizer internal error: missing fitted classes");
|
|
1664
1726
|
}
|
|
1665
1727
|
const result2 = [];
|
|
1666
1728
|
for (let i = 0; i < rows; i++) {
|
|
@@ -1670,10 +1732,10 @@ var MultiLabelBinarizer = class {
|
|
|
1670
1732
|
for (let p = start; p < end; p++) {
|
|
1671
1733
|
const col = Y.indices[p];
|
|
1672
1734
|
if (col === void 0) {
|
|
1673
|
-
throw new
|
|
1735
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: sparse column index missing");
|
|
1674
1736
|
}
|
|
1675
1737
|
if (col < 0 || col >= fittedClasses2) {
|
|
1676
|
-
throw new
|
|
1738
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1677
1739
|
"column index out of bounds for fitted classes",
|
|
1678
1740
|
"Y",
|
|
1679
1741
|
col
|
|
@@ -1681,7 +1743,7 @@ var MultiLabelBinarizer = class {
|
|
|
1681
1743
|
}
|
|
1682
1744
|
const raw = Y.data[p];
|
|
1683
1745
|
if (raw === void 0) {
|
|
1684
|
-
throw new
|
|
1746
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: sparse value missing");
|
|
1685
1747
|
}
|
|
1686
1748
|
const value = Number(raw);
|
|
1687
1749
|
if (value > 0) {
|
|
@@ -1698,7 +1760,7 @@ var MultiLabelBinarizer = class {
|
|
|
1698
1760
|
const nClasses = Y.shape[1] ?? 0;
|
|
1699
1761
|
const fittedClasses = this.classes_?.length ?? 0;
|
|
1700
1762
|
if (nClasses !== fittedClasses) {
|
|
1701
|
-
throw new
|
|
1763
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1702
1764
|
"column count does not match number of classes",
|
|
1703
1765
|
"Y",
|
|
1704
1766
|
nClasses
|
|
@@ -1709,7 +1771,7 @@ var MultiLabelBinarizer = class {
|
|
|
1709
1771
|
}
|
|
1710
1772
|
const classes = this.classes_;
|
|
1711
1773
|
if (!classes) {
|
|
1712
|
-
throw new
|
|
1774
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("MultiLabelBinarizer internal error: missing fitted classes");
|
|
1713
1775
|
}
|
|
1714
1776
|
const result = [];
|
|
1715
1777
|
const [stride0, stride1] = getStrides2D(Y);
|
|
@@ -1720,7 +1782,7 @@ var MultiLabelBinarizer = class {
|
|
|
1720
1782
|
for (let j = 0; j < nClasses; j++) {
|
|
1721
1783
|
const raw = data[rowBase + j * stride1];
|
|
1722
1784
|
if (raw === void 0) {
|
|
1723
|
-
throw new
|
|
1785
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1724
1786
|
}
|
|
1725
1787
|
const val = Number(raw);
|
|
1726
1788
|
if (val > 0) {
|
|
@@ -1736,10 +1798,10 @@ var MultiLabelBinarizer = class {
|
|
|
1736
1798
|
// src/preprocess/scalers.ts
|
|
1737
1799
|
function getNumericData2(X, name) {
|
|
1738
1800
|
if (X.dtype === "string") {
|
|
1739
|
-
throw new
|
|
1801
|
+
throw new chunkZ6BGACIH_cjs.DTypeError(`${name} must be numeric`);
|
|
1740
1802
|
}
|
|
1741
1803
|
if (Array.isArray(X.data)) {
|
|
1742
|
-
throw new
|
|
1804
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: invalid numeric tensor storage");
|
|
1743
1805
|
}
|
|
1744
1806
|
return X.data;
|
|
1745
1807
|
}
|
|
@@ -1748,7 +1810,7 @@ function parseBooleanOption(value, name, defaultValue) {
|
|
|
1748
1810
|
return defaultValue;
|
|
1749
1811
|
}
|
|
1750
1812
|
if (typeof value !== "boolean") {
|
|
1751
|
-
throw new
|
|
1813
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(`${name} must be a boolean`, name, value);
|
|
1752
1814
|
}
|
|
1753
1815
|
return value;
|
|
1754
1816
|
}
|
|
@@ -1762,11 +1824,11 @@ function validateFiniteData(X, name) {
|
|
|
1762
1824
|
for (let j = 0; j < nFeatures; j++) {
|
|
1763
1825
|
const raw = data[rowBase + j * stride1];
|
|
1764
1826
|
if (raw === void 0) {
|
|
1765
|
-
throw new
|
|
1827
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1766
1828
|
}
|
|
1767
1829
|
const val = Number(raw);
|
|
1768
1830
|
if (!Number.isFinite(val)) {
|
|
1769
|
-
throw new
|
|
1831
|
+
throw new chunkZ6BGACIH_cjs.DataValidationError(`${name} contains NaN or Infinity at index ${flatIndex}`);
|
|
1770
1832
|
}
|
|
1771
1833
|
flatIndex += 1;
|
|
1772
1834
|
}
|
|
@@ -1782,7 +1844,7 @@ function snapInverseValue(value) {
|
|
|
1782
1844
|
}
|
|
1783
1845
|
function normalQuantile(p) {
|
|
1784
1846
|
if (!Number.isFinite(p) || p <= 0 || p >= 1) {
|
|
1785
|
-
throw new
|
|
1847
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
1786
1848
|
"normalQuantile requires p in the open interval (0, 1)",
|
|
1787
1849
|
"p",
|
|
1788
1850
|
p
|
|
@@ -1844,7 +1906,7 @@ var StandardScaler = class {
|
|
|
1844
1906
|
}
|
|
1845
1907
|
fit(X) {
|
|
1846
1908
|
if (X.size === 0) {
|
|
1847
|
-
throw new
|
|
1909
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X must contain at least one sample", "X");
|
|
1848
1910
|
}
|
|
1849
1911
|
assert2D(X, "X");
|
|
1850
1912
|
assertNumericTensor(X, "X");
|
|
@@ -1860,7 +1922,7 @@ var StandardScaler = class {
|
|
|
1860
1922
|
for (let i = 0; i < nSamples; i++) {
|
|
1861
1923
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
1862
1924
|
if (raw === void 0) {
|
|
1863
|
-
throw new
|
|
1925
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1864
1926
|
}
|
|
1865
1927
|
sum += Number(raw);
|
|
1866
1928
|
}
|
|
@@ -1877,24 +1939,24 @@ var StandardScaler = class {
|
|
|
1877
1939
|
for (let i = 0; i < nSamples; i++) {
|
|
1878
1940
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
1879
1941
|
if (raw === void 0) {
|
|
1880
|
-
throw new
|
|
1942
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1881
1943
|
}
|
|
1882
1944
|
const val = Number(raw) - mean;
|
|
1883
1945
|
sumSq += val * val;
|
|
1884
1946
|
}
|
|
1885
1947
|
stds[j] = Math.sqrt(sumSq / nSamples);
|
|
1886
1948
|
}
|
|
1887
|
-
this.scale_ =
|
|
1949
|
+
this.scale_ = chunk724CXHFH_cjs.tensor(stds, { dtype: "float64" });
|
|
1888
1950
|
} else {
|
|
1889
1951
|
this.scale_ = void 0;
|
|
1890
1952
|
}
|
|
1891
|
-
this.mean_ = this.withMean && means ?
|
|
1953
|
+
this.mean_ = this.withMean && means ? chunk724CXHFH_cjs.tensor(means, { dtype: "float64" }) : void 0;
|
|
1892
1954
|
this.fitted = true;
|
|
1893
1955
|
return this;
|
|
1894
1956
|
}
|
|
1895
1957
|
transform(X) {
|
|
1896
1958
|
if (!this.fitted) {
|
|
1897
|
-
throw new
|
|
1959
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("StandardScaler must be fitted before transform");
|
|
1898
1960
|
}
|
|
1899
1961
|
assert2D(X, "X");
|
|
1900
1962
|
assertNumericTensor(X, "X");
|
|
@@ -1909,10 +1971,10 @@ var StandardScaler = class {
|
|
|
1909
1971
|
const meanStride = mean ? getStride1D(mean) : 0;
|
|
1910
1972
|
const scaleStride = scale ? getStride1D(scale) : 0;
|
|
1911
1973
|
if (this.withMean && !mean) {
|
|
1912
|
-
throw new
|
|
1974
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("StandardScaler internal error: missing mean_");
|
|
1913
1975
|
}
|
|
1914
1976
|
if (this.withStd && !scale) {
|
|
1915
|
-
throw new
|
|
1977
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("StandardScaler internal error: missing scale_");
|
|
1916
1978
|
}
|
|
1917
1979
|
const result = Array.from({ length: nSamples }, () => new Array(nFeatures).fill(0));
|
|
1918
1980
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -1920,20 +1982,20 @@ var StandardScaler = class {
|
|
|
1920
1982
|
for (let j = 0; j < nFeatures; j++) {
|
|
1921
1983
|
const raw = data[rowBase + j * stride1];
|
|
1922
1984
|
if (raw === void 0) {
|
|
1923
|
-
throw new
|
|
1985
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1924
1986
|
}
|
|
1925
1987
|
let val = Number(raw);
|
|
1926
1988
|
if (this.withMean && mean && meanData) {
|
|
1927
1989
|
const meanValue = meanData[mean.offset + j * meanStride];
|
|
1928
1990
|
if (meanValue === void 0) {
|
|
1929
|
-
throw new
|
|
1991
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: mean tensor access out of bounds");
|
|
1930
1992
|
}
|
|
1931
1993
|
val -= Number(meanValue);
|
|
1932
1994
|
}
|
|
1933
1995
|
if (this.withStd && scale && scaleData) {
|
|
1934
1996
|
const rawScale = scaleData[scale.offset + j * scaleStride];
|
|
1935
1997
|
if (rawScale === void 0) {
|
|
1936
|
-
throw new
|
|
1998
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: scale tensor access out of bounds");
|
|
1937
1999
|
}
|
|
1938
2000
|
const std = Number(rawScale);
|
|
1939
2001
|
const safeStd = std === 0 ? 1 : std;
|
|
@@ -1941,19 +2003,19 @@ var StandardScaler = class {
|
|
|
1941
2003
|
}
|
|
1942
2004
|
const row = result[i];
|
|
1943
2005
|
if (row === void 0) {
|
|
1944
|
-
throw new
|
|
2006
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
1945
2007
|
}
|
|
1946
2008
|
row[j] = val;
|
|
1947
2009
|
}
|
|
1948
2010
|
}
|
|
1949
|
-
return
|
|
2011
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
1950
2012
|
}
|
|
1951
2013
|
fitTransform(X) {
|
|
1952
2014
|
return this.fit(X).transform(X);
|
|
1953
2015
|
}
|
|
1954
2016
|
inverseTransform(X) {
|
|
1955
2017
|
if (!this.fitted) {
|
|
1956
|
-
throw new
|
|
2018
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("StandardScaler must be fitted before inverse_transform");
|
|
1957
2019
|
}
|
|
1958
2020
|
assert2D(X, "X");
|
|
1959
2021
|
assertNumericTensor(X, "X");
|
|
@@ -1967,10 +2029,10 @@ var StandardScaler = class {
|
|
|
1967
2029
|
const meanStride = mean ? getStride1D(mean) : 0;
|
|
1968
2030
|
const scaleStride = scale ? getStride1D(scale) : 0;
|
|
1969
2031
|
if (this.withMean && !mean) {
|
|
1970
|
-
throw new
|
|
2032
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("StandardScaler internal error: missing mean_");
|
|
1971
2033
|
}
|
|
1972
2034
|
if (this.withStd && !scale) {
|
|
1973
|
-
throw new
|
|
2035
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("StandardScaler internal error: missing scale_");
|
|
1974
2036
|
}
|
|
1975
2037
|
const result = Array.from({ length: nSamples }, () => new Array(nFeatures).fill(0));
|
|
1976
2038
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -1978,13 +2040,13 @@ var StandardScaler = class {
|
|
|
1978
2040
|
for (let j = 0; j < nFeatures; j++) {
|
|
1979
2041
|
const raw = data[rowBase + j * stride1];
|
|
1980
2042
|
if (raw === void 0) {
|
|
1981
|
-
throw new
|
|
2043
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
1982
2044
|
}
|
|
1983
2045
|
let val = Number(raw);
|
|
1984
2046
|
if (this.withStd && scale && scaleData) {
|
|
1985
2047
|
const rawScale = scaleData[scale.offset + j * scaleStride];
|
|
1986
2048
|
if (rawScale === void 0) {
|
|
1987
|
-
throw new
|
|
2049
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: scale tensor access out of bounds");
|
|
1988
2050
|
}
|
|
1989
2051
|
const std = Number(rawScale);
|
|
1990
2052
|
const safeStd = std === 0 ? 1 : std;
|
|
@@ -1993,18 +2055,18 @@ var StandardScaler = class {
|
|
|
1993
2055
|
if (this.withMean && mean && meanData) {
|
|
1994
2056
|
const meanValue = meanData[mean.offset + j * meanStride];
|
|
1995
2057
|
if (meanValue === void 0) {
|
|
1996
|
-
throw new
|
|
2058
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: mean tensor access out of bounds");
|
|
1997
2059
|
}
|
|
1998
2060
|
val += Number(meanValue);
|
|
1999
2061
|
}
|
|
2000
2062
|
const resultRow = result[i];
|
|
2001
2063
|
if (resultRow === void 0) {
|
|
2002
|
-
throw new
|
|
2064
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2003
2065
|
}
|
|
2004
2066
|
resultRow[j] = snapInverseValue(val);
|
|
2005
2067
|
}
|
|
2006
2068
|
}
|
|
2007
|
-
return
|
|
2069
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2008
2070
|
}
|
|
2009
2071
|
};
|
|
2010
2072
|
var MinMaxScaler = class {
|
|
@@ -2027,7 +2089,7 @@ var MinMaxScaler = class {
|
|
|
2027
2089
|
parseBooleanOption(options.copy, "copy", true);
|
|
2028
2090
|
const [minRange, maxRange] = this.featureRange;
|
|
2029
2091
|
if (!Number.isFinite(minRange) || !Number.isFinite(maxRange) || minRange >= maxRange) {
|
|
2030
|
-
throw new
|
|
2092
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
2031
2093
|
"featureRange must be [min, max] with min < max",
|
|
2032
2094
|
"featureRange",
|
|
2033
2095
|
this.featureRange
|
|
@@ -2036,7 +2098,7 @@ var MinMaxScaler = class {
|
|
|
2036
2098
|
}
|
|
2037
2099
|
fit(X) {
|
|
2038
2100
|
if (X.size === 0) {
|
|
2039
|
-
throw new
|
|
2101
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X must contain at least one sample", "X");
|
|
2040
2102
|
}
|
|
2041
2103
|
assert2D(X, "X");
|
|
2042
2104
|
assertNumericTensor(X, "X");
|
|
@@ -2050,26 +2112,26 @@ var MinMaxScaler = class {
|
|
|
2050
2112
|
for (let i = 0; i < nSamples; i++) {
|
|
2051
2113
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
2052
2114
|
if (raw === void 0) {
|
|
2053
|
-
throw new
|
|
2115
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2054
2116
|
}
|
|
2055
2117
|
const val = Number(raw);
|
|
2056
2118
|
const currentMin = mins[j];
|
|
2057
2119
|
const currentMax = maxs[j];
|
|
2058
2120
|
if (currentMin === void 0 || currentMax === void 0) {
|
|
2059
|
-
throw new
|
|
2121
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: min/max array access failed");
|
|
2060
2122
|
}
|
|
2061
2123
|
mins[j] = Math.min(currentMin, val);
|
|
2062
2124
|
maxs[j] = Math.max(currentMax, val);
|
|
2063
2125
|
}
|
|
2064
2126
|
}
|
|
2065
|
-
this.dataMin_ =
|
|
2066
|
-
this.dataMax_ =
|
|
2127
|
+
this.dataMin_ = chunk724CXHFH_cjs.tensor(mins, { dtype: "float64" });
|
|
2128
|
+
this.dataMax_ = chunk724CXHFH_cjs.tensor(maxs, { dtype: "float64" });
|
|
2067
2129
|
this.fitted = true;
|
|
2068
2130
|
return this;
|
|
2069
2131
|
}
|
|
2070
2132
|
transform(X) {
|
|
2071
2133
|
if (!this.fitted) {
|
|
2072
|
-
throw new
|
|
2134
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("MinMaxScaler must be fitted before transform");
|
|
2073
2135
|
}
|
|
2074
2136
|
assert2D(X, "X");
|
|
2075
2137
|
assertNumericTensor(X, "X");
|
|
@@ -2081,7 +2143,7 @@ var MinMaxScaler = class {
|
|
|
2081
2143
|
const dataMin = this.dataMin_;
|
|
2082
2144
|
const dataMax = this.dataMax_;
|
|
2083
2145
|
if (!dataMin || !dataMax) {
|
|
2084
|
-
throw new
|
|
2146
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("MinMaxScaler internal error: missing fitted min/max");
|
|
2085
2147
|
}
|
|
2086
2148
|
const minData = getNumericData2(dataMin, "dataMin_");
|
|
2087
2149
|
const maxData = getNumericData2(dataMax, "dataMax_");
|
|
@@ -2093,20 +2155,20 @@ var MinMaxScaler = class {
|
|
|
2093
2155
|
for (let j = 0; j < nFeatures; j++) {
|
|
2094
2156
|
const raw = data[rowBase + j * stride1];
|
|
2095
2157
|
if (raw === void 0) {
|
|
2096
|
-
throw new
|
|
2158
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2097
2159
|
}
|
|
2098
2160
|
const val = Number(raw);
|
|
2099
2161
|
const rawMin = minData[dataMin.offset + j * minStride];
|
|
2100
2162
|
const rawMax = maxData[dataMax.offset + j * maxStride];
|
|
2101
2163
|
if (rawMin === void 0 || rawMax === void 0) {
|
|
2102
|
-
throw new
|
|
2164
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: min/max tensor access out of bounds");
|
|
2103
2165
|
}
|
|
2104
2166
|
const min = Number(rawMin);
|
|
2105
2167
|
const max = Number(rawMax);
|
|
2106
2168
|
const range = max - min;
|
|
2107
2169
|
const row = result[i];
|
|
2108
2170
|
if (row === void 0) {
|
|
2109
|
-
throw new
|
|
2171
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2110
2172
|
}
|
|
2111
2173
|
let scaled = range !== 0 ? (val - min) / range * (maxRange - minRange) + minRange : minRange;
|
|
2112
2174
|
if (this.clip) {
|
|
@@ -2115,14 +2177,14 @@ var MinMaxScaler = class {
|
|
|
2115
2177
|
row[j] = scaled;
|
|
2116
2178
|
}
|
|
2117
2179
|
}
|
|
2118
|
-
return
|
|
2180
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2119
2181
|
}
|
|
2120
2182
|
fitTransform(X) {
|
|
2121
2183
|
return this.fit(X).transform(X);
|
|
2122
2184
|
}
|
|
2123
2185
|
inverseTransform(X) {
|
|
2124
2186
|
if (!this.fitted) {
|
|
2125
|
-
throw new
|
|
2187
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("MinMaxScaler must be fitted before inverse_transform");
|
|
2126
2188
|
}
|
|
2127
2189
|
assert2D(X, "X");
|
|
2128
2190
|
assertNumericTensor(X, "X");
|
|
@@ -2133,7 +2195,7 @@ var MinMaxScaler = class {
|
|
|
2133
2195
|
const dataMin = this.dataMin_;
|
|
2134
2196
|
const dataMax = this.dataMax_;
|
|
2135
2197
|
if (!dataMin || !dataMax) {
|
|
2136
|
-
throw new
|
|
2198
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("MinMaxScaler internal error: missing fitted min/max");
|
|
2137
2199
|
}
|
|
2138
2200
|
const minData = getNumericData2(dataMin, "dataMin_");
|
|
2139
2201
|
const maxData = getNumericData2(dataMax, "dataMax_");
|
|
@@ -2145,25 +2207,25 @@ var MinMaxScaler = class {
|
|
|
2145
2207
|
for (let j = 0; j < nFeatures; j++) {
|
|
2146
2208
|
const raw = data[rowBase + j * stride1];
|
|
2147
2209
|
if (raw === void 0) {
|
|
2148
|
-
throw new
|
|
2210
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2149
2211
|
}
|
|
2150
2212
|
const val = Number(raw);
|
|
2151
2213
|
const rawMin = minData[dataMin.offset + j * minStride];
|
|
2152
2214
|
const rawMax = maxData[dataMax.offset + j * maxStride];
|
|
2153
2215
|
if (rawMin === void 0 || rawMax === void 0) {
|
|
2154
|
-
throw new
|
|
2216
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: min/max tensor access out of bounds");
|
|
2155
2217
|
}
|
|
2156
2218
|
const min = Number(rawMin);
|
|
2157
2219
|
const max = Number(rawMax);
|
|
2158
2220
|
const range = max - min;
|
|
2159
2221
|
const row = result[i];
|
|
2160
2222
|
if (row === void 0) {
|
|
2161
|
-
throw new
|
|
2223
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2162
2224
|
}
|
|
2163
2225
|
row[j] = (val - minRange) / (maxRange - minRange) * range + min;
|
|
2164
2226
|
}
|
|
2165
2227
|
}
|
|
2166
|
-
return
|
|
2228
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2167
2229
|
}
|
|
2168
2230
|
};
|
|
2169
2231
|
var MaxAbsScaler = class {
|
|
@@ -2180,7 +2242,7 @@ var MaxAbsScaler = class {
|
|
|
2180
2242
|
}
|
|
2181
2243
|
fit(X) {
|
|
2182
2244
|
if (X.size === 0) {
|
|
2183
|
-
throw new
|
|
2245
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X must contain at least one sample", "X");
|
|
2184
2246
|
}
|
|
2185
2247
|
assert2D(X, "X");
|
|
2186
2248
|
assertNumericTensor(X, "X");
|
|
@@ -2193,22 +2255,22 @@ var MaxAbsScaler = class {
|
|
|
2193
2255
|
for (let i = 0; i < nSamples; i++) {
|
|
2194
2256
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
2195
2257
|
if (raw === void 0) {
|
|
2196
|
-
throw new
|
|
2258
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2197
2259
|
}
|
|
2198
2260
|
const currentMax = maxAbs[j];
|
|
2199
2261
|
if (currentMax === void 0) {
|
|
2200
|
-
throw new
|
|
2262
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: maxAbs array access failed");
|
|
2201
2263
|
}
|
|
2202
2264
|
maxAbs[j] = Math.max(currentMax, Math.abs(Number(raw)));
|
|
2203
2265
|
}
|
|
2204
2266
|
}
|
|
2205
|
-
this.maxAbs_ =
|
|
2267
|
+
this.maxAbs_ = chunk724CXHFH_cjs.tensor(maxAbs, { dtype: "float64" });
|
|
2206
2268
|
this.fitted = true;
|
|
2207
2269
|
return this;
|
|
2208
2270
|
}
|
|
2209
2271
|
transform(X) {
|
|
2210
2272
|
if (!this.fitted) {
|
|
2211
|
-
throw new
|
|
2273
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("MaxAbsScaler must be fitted before transform");
|
|
2212
2274
|
}
|
|
2213
2275
|
assert2D(X, "X");
|
|
2214
2276
|
assertNumericTensor(X, "X");
|
|
@@ -2218,7 +2280,7 @@ var MaxAbsScaler = class {
|
|
|
2218
2280
|
const [stride0, stride1] = getStrides2D(X);
|
|
2219
2281
|
const maxAbs = this.maxAbs_;
|
|
2220
2282
|
if (!maxAbs) {
|
|
2221
|
-
throw new
|
|
2283
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("MaxAbsScaler internal error: missing fitted maxAbs");
|
|
2222
2284
|
}
|
|
2223
2285
|
const maxData = getNumericData2(maxAbs, "maxAbs_");
|
|
2224
2286
|
const maxStride = getStride1D(maxAbs);
|
|
@@ -2228,30 +2290,30 @@ var MaxAbsScaler = class {
|
|
|
2228
2290
|
for (let j = 0; j < nFeatures; j++) {
|
|
2229
2291
|
const raw = data[rowBase + j * stride1];
|
|
2230
2292
|
if (raw === void 0) {
|
|
2231
|
-
throw new
|
|
2293
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2232
2294
|
}
|
|
2233
2295
|
const val = Number(raw);
|
|
2234
2296
|
const rawScale = maxData[maxAbs.offset + j * maxStride];
|
|
2235
2297
|
if (rawScale === void 0) {
|
|
2236
|
-
throw new
|
|
2298
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: maxAbs tensor access out of bounds");
|
|
2237
2299
|
}
|
|
2238
2300
|
const scale = Number(rawScale);
|
|
2239
2301
|
const safeScale = scale === 0 ? 1 : scale;
|
|
2240
2302
|
const row = result[i];
|
|
2241
2303
|
if (row === void 0) {
|
|
2242
|
-
throw new
|
|
2304
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2243
2305
|
}
|
|
2244
2306
|
row[j] = val / safeScale;
|
|
2245
2307
|
}
|
|
2246
2308
|
}
|
|
2247
|
-
return
|
|
2309
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2248
2310
|
}
|
|
2249
2311
|
fitTransform(X) {
|
|
2250
2312
|
return this.fit(X).transform(X);
|
|
2251
2313
|
}
|
|
2252
2314
|
inverseTransform(X) {
|
|
2253
2315
|
if (!this.fitted) {
|
|
2254
|
-
throw new
|
|
2316
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("MaxAbsScaler must be fitted before inverse_transform");
|
|
2255
2317
|
}
|
|
2256
2318
|
assert2D(X, "X");
|
|
2257
2319
|
assertNumericTensor(X, "X");
|
|
@@ -2260,7 +2322,7 @@ var MaxAbsScaler = class {
|
|
|
2260
2322
|
const [stride0, stride1] = getStrides2D(X);
|
|
2261
2323
|
const maxAbs = this.maxAbs_;
|
|
2262
2324
|
if (!maxAbs) {
|
|
2263
|
-
throw new
|
|
2325
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("MaxAbsScaler internal error: missing fitted maxAbs");
|
|
2264
2326
|
}
|
|
2265
2327
|
const maxData = getNumericData2(maxAbs, "maxAbs_");
|
|
2266
2328
|
const maxStride = getStride1D(maxAbs);
|
|
@@ -2270,22 +2332,22 @@ var MaxAbsScaler = class {
|
|
|
2270
2332
|
for (let j = 0; j < nFeatures; j++) {
|
|
2271
2333
|
const raw = data[rowBase + j * stride1];
|
|
2272
2334
|
if (raw === void 0) {
|
|
2273
|
-
throw new
|
|
2335
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2274
2336
|
}
|
|
2275
2337
|
const val = Number(raw);
|
|
2276
2338
|
const rawScale = maxData[maxAbs.offset + j * maxStride];
|
|
2277
2339
|
if (rawScale === void 0) {
|
|
2278
|
-
throw new
|
|
2340
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: maxAbs tensor access out of bounds");
|
|
2279
2341
|
}
|
|
2280
2342
|
const scale = Number(rawScale);
|
|
2281
2343
|
const row = result[i];
|
|
2282
2344
|
if (row === void 0) {
|
|
2283
|
-
throw new
|
|
2345
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2284
2346
|
}
|
|
2285
2347
|
row[j] = val * scale;
|
|
2286
2348
|
}
|
|
2287
2349
|
}
|
|
2288
|
-
return
|
|
2350
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2289
2351
|
}
|
|
2290
2352
|
};
|
|
2291
2353
|
var RobustScaler = class {
|
|
@@ -2314,7 +2376,7 @@ var RobustScaler = class {
|
|
|
2314
2376
|
parseBooleanOption(options.copy, "copy", true);
|
|
2315
2377
|
const [lower, upper] = this.quantileRange;
|
|
2316
2378
|
if (!Number.isFinite(lower) || !Number.isFinite(upper) || lower < 0 || upper > 100 || lower >= upper) {
|
|
2317
|
-
throw new
|
|
2379
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
2318
2380
|
"quantileRange must be a valid ascending percentile range",
|
|
2319
2381
|
"quantileRange",
|
|
2320
2382
|
this.quantileRange
|
|
@@ -2323,7 +2385,7 @@ var RobustScaler = class {
|
|
|
2323
2385
|
}
|
|
2324
2386
|
fit(X) {
|
|
2325
2387
|
if (X.size === 0) {
|
|
2326
|
-
throw new
|
|
2388
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X must contain at least one sample", "X");
|
|
2327
2389
|
}
|
|
2328
2390
|
assert2D(X, "X");
|
|
2329
2391
|
assertNumericTensor(X, "X");
|
|
@@ -2338,26 +2400,26 @@ var RobustScaler = class {
|
|
|
2338
2400
|
const upperFraction = upperPercentile / 100;
|
|
2339
2401
|
const normalizer = this.unitVariance ? normalQuantile(upperFraction) - normalQuantile(lowerFraction) : 1;
|
|
2340
2402
|
if (this.unitVariance && (!Number.isFinite(normalizer) || normalizer <= 0)) {
|
|
2341
|
-
throw new
|
|
2403
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("RobustScaler internal error: invalid unit variance normalizer");
|
|
2342
2404
|
}
|
|
2343
2405
|
for (let j = 0; j < nFeatures; j++) {
|
|
2344
2406
|
const values = [];
|
|
2345
2407
|
for (let i = 0; i < nSamples; i++) {
|
|
2346
2408
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
2347
2409
|
if (raw === void 0) {
|
|
2348
|
-
throw new
|
|
2410
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2349
2411
|
}
|
|
2350
2412
|
values.push(Number(raw));
|
|
2351
2413
|
}
|
|
2352
2414
|
values.sort((a, b) => a - b);
|
|
2353
2415
|
const interpolate = (q) => {
|
|
2354
2416
|
if (values.length === 0) {
|
|
2355
|
-
throw new
|
|
2417
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: cannot interpolate empty values");
|
|
2356
2418
|
}
|
|
2357
2419
|
if (values.length === 1) {
|
|
2358
2420
|
const only = values[0];
|
|
2359
2421
|
if (only === void 0) {
|
|
2360
|
-
throw new
|
|
2422
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing sorted value");
|
|
2361
2423
|
}
|
|
2362
2424
|
return only;
|
|
2363
2425
|
}
|
|
@@ -2367,7 +2429,7 @@ var RobustScaler = class {
|
|
|
2367
2429
|
const lowerValue = values[lower];
|
|
2368
2430
|
const upperValue = values[upper];
|
|
2369
2431
|
if (lowerValue === void 0 || upperValue === void 0) {
|
|
2370
|
-
throw new
|
|
2432
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: quantile interpolation index out of bounds");
|
|
2371
2433
|
}
|
|
2372
2434
|
if (upper === lower) {
|
|
2373
2435
|
return lowerValue;
|
|
@@ -2381,14 +2443,14 @@ var RobustScaler = class {
|
|
|
2381
2443
|
const iqr = qUpper - qLower;
|
|
2382
2444
|
scales[j] = this.unitVariance ? iqr / normalizer : iqr;
|
|
2383
2445
|
}
|
|
2384
|
-
this.center_ = this.withCentering ?
|
|
2385
|
-
this.scale_ = this.withScaling ?
|
|
2446
|
+
this.center_ = this.withCentering ? chunk724CXHFH_cjs.tensor(centers, { dtype: "float64" }) : void 0;
|
|
2447
|
+
this.scale_ = this.withScaling ? chunk724CXHFH_cjs.tensor(scales, { dtype: "float64" }) : void 0;
|
|
2386
2448
|
this.fitted = true;
|
|
2387
2449
|
return this;
|
|
2388
2450
|
}
|
|
2389
2451
|
transform(X) {
|
|
2390
2452
|
if (!this.fitted) {
|
|
2391
|
-
throw new
|
|
2453
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("RobustScaler must be fitted before transform");
|
|
2392
2454
|
}
|
|
2393
2455
|
assert2D(X, "X");
|
|
2394
2456
|
assertNumericTensor(X, "X");
|
|
@@ -2403,10 +2465,10 @@ var RobustScaler = class {
|
|
|
2403
2465
|
const centerStride = center ? getStride1D(center) : 0;
|
|
2404
2466
|
const scaleStride = scale ? getStride1D(scale) : 0;
|
|
2405
2467
|
if (this.withCentering && !center) {
|
|
2406
|
-
throw new
|
|
2468
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("RobustScaler internal error: missing center_");
|
|
2407
2469
|
}
|
|
2408
2470
|
if (this.withScaling && !scale) {
|
|
2409
|
-
throw new
|
|
2471
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("RobustScaler internal error: missing scale_");
|
|
2410
2472
|
}
|
|
2411
2473
|
const result = Array.from({ length: nSamples }, () => new Array(nFeatures).fill(0));
|
|
2412
2474
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -2414,20 +2476,20 @@ var RobustScaler = class {
|
|
|
2414
2476
|
for (let j = 0; j < nFeatures; j++) {
|
|
2415
2477
|
const raw = data[rowBase + j * stride1];
|
|
2416
2478
|
if (raw === void 0) {
|
|
2417
|
-
throw new
|
|
2479
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2418
2480
|
}
|
|
2419
2481
|
let val = Number(raw);
|
|
2420
2482
|
if (this.withCentering && center && centerData) {
|
|
2421
2483
|
const rawCenter = centerData[center.offset + j * centerStride];
|
|
2422
2484
|
if (rawCenter === void 0) {
|
|
2423
|
-
throw new
|
|
2485
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: center tensor access out of bounds");
|
|
2424
2486
|
}
|
|
2425
2487
|
val -= Number(rawCenter);
|
|
2426
2488
|
}
|
|
2427
2489
|
if (this.withScaling && scale && scaleData) {
|
|
2428
2490
|
const rawScale = scaleData[scale.offset + j * scaleStride];
|
|
2429
2491
|
if (rawScale === void 0) {
|
|
2430
|
-
throw new
|
|
2492
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: scale tensor access out of bounds");
|
|
2431
2493
|
}
|
|
2432
2494
|
const scaleValue = Number(rawScale);
|
|
2433
2495
|
const safeScale = scaleValue === 0 ? 1 : scaleValue;
|
|
@@ -2435,19 +2497,19 @@ var RobustScaler = class {
|
|
|
2435
2497
|
}
|
|
2436
2498
|
const resultRow = result[i];
|
|
2437
2499
|
if (resultRow === void 0) {
|
|
2438
|
-
throw new
|
|
2500
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2439
2501
|
}
|
|
2440
2502
|
resultRow[j] = val;
|
|
2441
2503
|
}
|
|
2442
2504
|
}
|
|
2443
|
-
return
|
|
2505
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2444
2506
|
}
|
|
2445
2507
|
fitTransform(X) {
|
|
2446
2508
|
return this.fit(X).transform(X);
|
|
2447
2509
|
}
|
|
2448
2510
|
inverseTransform(X) {
|
|
2449
2511
|
if (!this.fitted) {
|
|
2450
|
-
throw new
|
|
2512
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("RobustScaler must be fitted before inverse_transform");
|
|
2451
2513
|
}
|
|
2452
2514
|
assert2D(X, "X");
|
|
2453
2515
|
assertNumericTensor(X, "X");
|
|
@@ -2461,10 +2523,10 @@ var RobustScaler = class {
|
|
|
2461
2523
|
const centerStride = center ? getStride1D(center) : 0;
|
|
2462
2524
|
const scaleStride = scale ? getStride1D(scale) : 0;
|
|
2463
2525
|
if (this.withCentering && !center) {
|
|
2464
|
-
throw new
|
|
2526
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("RobustScaler internal error: missing center_");
|
|
2465
2527
|
}
|
|
2466
2528
|
if (this.withScaling && !scale) {
|
|
2467
|
-
throw new
|
|
2529
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("RobustScaler internal error: missing scale_");
|
|
2468
2530
|
}
|
|
2469
2531
|
const result = Array.from({ length: nSamples }, () => new Array(nFeatures).fill(0));
|
|
2470
2532
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -2472,13 +2534,13 @@ var RobustScaler = class {
|
|
|
2472
2534
|
for (let j = 0; j < nFeatures; j++) {
|
|
2473
2535
|
const raw = data[rowBase + j * stride1];
|
|
2474
2536
|
if (raw === void 0) {
|
|
2475
|
-
throw new
|
|
2537
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2476
2538
|
}
|
|
2477
2539
|
let val = Number(raw);
|
|
2478
2540
|
if (this.withScaling && scale && scaleData) {
|
|
2479
2541
|
const rawScale = scaleData[scale.offset + j * scaleStride];
|
|
2480
2542
|
if (rawScale === void 0) {
|
|
2481
|
-
throw new
|
|
2543
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: scale tensor access out of bounds");
|
|
2482
2544
|
}
|
|
2483
2545
|
const scaleValue = Number(rawScale);
|
|
2484
2546
|
const safeScale = scaleValue === 0 ? 1 : scaleValue;
|
|
@@ -2487,18 +2549,18 @@ var RobustScaler = class {
|
|
|
2487
2549
|
if (this.withCentering && center && centerData) {
|
|
2488
2550
|
const rawCenter = centerData[center.offset + j * centerStride];
|
|
2489
2551
|
if (rawCenter === void 0) {
|
|
2490
|
-
throw new
|
|
2552
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: center tensor access out of bounds");
|
|
2491
2553
|
}
|
|
2492
2554
|
val += Number(rawCenter);
|
|
2493
2555
|
}
|
|
2494
2556
|
const resultRow = result[i];
|
|
2495
2557
|
if (resultRow === void 0) {
|
|
2496
|
-
throw new
|
|
2558
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2497
2559
|
}
|
|
2498
2560
|
resultRow[j] = val;
|
|
2499
2561
|
}
|
|
2500
2562
|
}
|
|
2501
|
-
return
|
|
2563
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2502
2564
|
}
|
|
2503
2565
|
};
|
|
2504
2566
|
var Normalizer = class {
|
|
@@ -2513,7 +2575,7 @@ var Normalizer = class {
|
|
|
2513
2575
|
constructor(options = {}) {
|
|
2514
2576
|
this.norm = options.norm ?? "l2";
|
|
2515
2577
|
if (this.norm !== "l1" && this.norm !== "l2" && this.norm !== "max") {
|
|
2516
|
-
throw new
|
|
2578
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("norm must be one of: l1, l2, max", "norm", this.norm);
|
|
2517
2579
|
}
|
|
2518
2580
|
parseBooleanOption(options.copy, "copy", true);
|
|
2519
2581
|
}
|
|
@@ -2535,7 +2597,7 @@ var Normalizer = class {
|
|
|
2535
2597
|
for (let j = 0; j < nFeatures; j++) {
|
|
2536
2598
|
const raw = data[rowBase + j * stride1];
|
|
2537
2599
|
if (raw === void 0) {
|
|
2538
|
-
throw new
|
|
2600
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2539
2601
|
}
|
|
2540
2602
|
const val = Number(raw);
|
|
2541
2603
|
norm += val * val;
|
|
@@ -2545,7 +2607,7 @@ var Normalizer = class {
|
|
|
2545
2607
|
for (let j = 0; j < nFeatures; j++) {
|
|
2546
2608
|
const raw = data[rowBase + j * stride1];
|
|
2547
2609
|
if (raw === void 0) {
|
|
2548
|
-
throw new
|
|
2610
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2549
2611
|
}
|
|
2550
2612
|
norm += Math.abs(Number(raw));
|
|
2551
2613
|
}
|
|
@@ -2553,7 +2615,7 @@ var Normalizer = class {
|
|
|
2553
2615
|
for (let j = 0; j < nFeatures; j++) {
|
|
2554
2616
|
const raw = data[rowBase + j * stride1];
|
|
2555
2617
|
if (raw === void 0) {
|
|
2556
|
-
throw new
|
|
2618
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2557
2619
|
}
|
|
2558
2620
|
norm = Math.max(norm, Math.abs(Number(raw)));
|
|
2559
2621
|
}
|
|
@@ -2561,17 +2623,17 @@ var Normalizer = class {
|
|
|
2561
2623
|
for (let j = 0; j < nFeatures; j++) {
|
|
2562
2624
|
const raw = data[rowBase + j * stride1];
|
|
2563
2625
|
if (raw === void 0) {
|
|
2564
|
-
throw new
|
|
2626
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2565
2627
|
}
|
|
2566
2628
|
const val = Number(raw);
|
|
2567
2629
|
const row = result[i];
|
|
2568
2630
|
if (row === void 0) {
|
|
2569
|
-
throw new
|
|
2631
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2570
2632
|
}
|
|
2571
2633
|
row[j] = norm === 0 ? val : val / norm;
|
|
2572
2634
|
}
|
|
2573
2635
|
}
|
|
2574
|
-
return
|
|
2636
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2575
2637
|
}
|
|
2576
2638
|
fitTransform(X) {
|
|
2577
2639
|
return this.transform(X);
|
|
@@ -2601,14 +2663,14 @@ var QuantileTransformer = class {
|
|
|
2601
2663
|
this.randomState = options.randomState;
|
|
2602
2664
|
parseBooleanOption(options.copy, "copy", true);
|
|
2603
2665
|
if (!Number.isFinite(this.nQuantiles) || !Number.isInteger(this.nQuantiles) || this.nQuantiles < 2) {
|
|
2604
|
-
throw new
|
|
2666
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
2605
2667
|
"nQuantiles must be at least 2",
|
|
2606
2668
|
"nQuantiles",
|
|
2607
2669
|
this.nQuantiles
|
|
2608
2670
|
);
|
|
2609
2671
|
}
|
|
2610
2672
|
if (this.outputDistribution !== "uniform" && this.outputDistribution !== "normal") {
|
|
2611
|
-
throw new
|
|
2673
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
2612
2674
|
"outputDistribution must be 'uniform' or 'normal'",
|
|
2613
2675
|
"outputDistribution",
|
|
2614
2676
|
this.outputDistribution
|
|
@@ -2616,7 +2678,7 @@ var QuantileTransformer = class {
|
|
|
2616
2678
|
}
|
|
2617
2679
|
if (this.subsample !== void 0) {
|
|
2618
2680
|
if (!Number.isFinite(this.subsample) || !Number.isInteger(this.subsample) || this.subsample < 2) {
|
|
2619
|
-
throw new
|
|
2681
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
2620
2682
|
"subsample must be an integer >= 2",
|
|
2621
2683
|
"subsample",
|
|
2622
2684
|
this.subsample
|
|
@@ -2626,7 +2688,7 @@ var QuantileTransformer = class {
|
|
|
2626
2688
|
}
|
|
2627
2689
|
fit(X) {
|
|
2628
2690
|
if (X.size === 0) {
|
|
2629
|
-
throw new
|
|
2691
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X must contain at least one sample", "X");
|
|
2630
2692
|
}
|
|
2631
2693
|
assert2D(X, "X");
|
|
2632
2694
|
assertNumericTensor(X, "X");
|
|
@@ -2651,7 +2713,7 @@ var QuantileTransformer = class {
|
|
|
2651
2713
|
for (const idx of sampleIndices) {
|
|
2652
2714
|
const raw = data[X.offset + idx * stride0 + j * stride1];
|
|
2653
2715
|
if (raw === void 0) {
|
|
2654
|
-
throw new
|
|
2716
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2655
2717
|
}
|
|
2656
2718
|
values.push(Number(raw));
|
|
2657
2719
|
}
|
|
@@ -2659,7 +2721,7 @@ var QuantileTransformer = class {
|
|
|
2659
2721
|
for (let i = 0; i < nSamples; i++) {
|
|
2660
2722
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
2661
2723
|
if (raw === void 0) {
|
|
2662
|
-
throw new
|
|
2724
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2663
2725
|
}
|
|
2664
2726
|
values.push(Number(raw));
|
|
2665
2727
|
}
|
|
@@ -2673,7 +2735,7 @@ var QuantileTransformer = class {
|
|
|
2673
2735
|
}
|
|
2674
2736
|
transform(X) {
|
|
2675
2737
|
if (!this.fitted || !this.quantiles_) {
|
|
2676
|
-
throw new
|
|
2738
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("QuantileTransformer must be fitted before transform");
|
|
2677
2739
|
}
|
|
2678
2740
|
assert2D(X, "X");
|
|
2679
2741
|
assertNumericTensor(X, "X");
|
|
@@ -2682,7 +2744,7 @@ var QuantileTransformer = class {
|
|
|
2682
2744
|
const data = getNumericData2(X, "X");
|
|
2683
2745
|
const [stride0, stride1] = getStrides2D(X);
|
|
2684
2746
|
if (nSamples === 0) {
|
|
2685
|
-
return
|
|
2747
|
+
return chunk724CXHFH_cjs.zeros([0, nFeatures], { dtype: "float64" });
|
|
2686
2748
|
}
|
|
2687
2749
|
const result = new Array(nSamples);
|
|
2688
2750
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -2691,18 +2753,18 @@ var QuantileTransformer = class {
|
|
|
2691
2753
|
for (let j = 0; j < nFeatures; j++) {
|
|
2692
2754
|
const feature = this.quantiles_.get(j);
|
|
2693
2755
|
if (!feature) {
|
|
2694
|
-
throw new
|
|
2756
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError(`Internal error: missing fitted quantiles for feature ${j}`);
|
|
2695
2757
|
}
|
|
2696
2758
|
for (let i = 0; i < nSamples; i++) {
|
|
2697
2759
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
2698
2760
|
if (raw === void 0) {
|
|
2699
|
-
throw new
|
|
2761
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2700
2762
|
}
|
|
2701
2763
|
const val = Number(raw);
|
|
2702
2764
|
const quantile = this.mapValueToQuantile(val, feature.quantiles, feature.references);
|
|
2703
2765
|
const row = result[i];
|
|
2704
2766
|
if (!row) {
|
|
2705
|
-
throw new
|
|
2767
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2706
2768
|
}
|
|
2707
2769
|
if (this.outputDistribution === "uniform") {
|
|
2708
2770
|
row[j] = quantile;
|
|
@@ -2713,7 +2775,7 @@ var QuantileTransformer = class {
|
|
|
2713
2775
|
}
|
|
2714
2776
|
}
|
|
2715
2777
|
}
|
|
2716
|
-
return
|
|
2778
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2717
2779
|
}
|
|
2718
2780
|
/**
|
|
2719
2781
|
* Inverse transform data back to the original feature space.
|
|
@@ -2727,7 +2789,7 @@ var QuantileTransformer = class {
|
|
|
2727
2789
|
*/
|
|
2728
2790
|
inverseTransform(X) {
|
|
2729
2791
|
if (!this.fitted || !this.quantiles_) {
|
|
2730
|
-
throw new
|
|
2792
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("QuantileTransformer must be fitted before inverse_transform");
|
|
2731
2793
|
}
|
|
2732
2794
|
assert2D(X, "X");
|
|
2733
2795
|
assertNumericTensor(X, "X");
|
|
@@ -2736,7 +2798,7 @@ var QuantileTransformer = class {
|
|
|
2736
2798
|
const data = getNumericData2(X, "X");
|
|
2737
2799
|
const [stride0, stride1] = getStrides2D(X);
|
|
2738
2800
|
if (nSamples === 0) {
|
|
2739
|
-
return
|
|
2801
|
+
return chunk724CXHFH_cjs.zeros([0, nFeatures], { dtype: "float64" });
|
|
2740
2802
|
}
|
|
2741
2803
|
const result = new Array(nSamples);
|
|
2742
2804
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -2745,24 +2807,24 @@ var QuantileTransformer = class {
|
|
|
2745
2807
|
for (let j = 0; j < nFeatures; j++) {
|
|
2746
2808
|
const feature = this.quantiles_.get(j);
|
|
2747
2809
|
if (!feature) {
|
|
2748
|
-
throw new
|
|
2810
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError(`Internal error: missing fitted quantiles for feature ${j}`);
|
|
2749
2811
|
}
|
|
2750
2812
|
for (let i = 0; i < nSamples; i++) {
|
|
2751
2813
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
2752
2814
|
if (raw === void 0) {
|
|
2753
|
-
throw new
|
|
2815
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2754
2816
|
}
|
|
2755
2817
|
const value = Number(raw);
|
|
2756
2818
|
let quantile = this.outputDistribution === "normal" ? this.normalCdf(value) : value;
|
|
2757
2819
|
quantile = Math.max(0, Math.min(1, quantile));
|
|
2758
2820
|
const row = result[i];
|
|
2759
2821
|
if (!row) {
|
|
2760
|
-
throw new
|
|
2822
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
2761
2823
|
}
|
|
2762
2824
|
row[j] = this.mapQuantileToValue(quantile, feature.quantiles, feature.references);
|
|
2763
2825
|
}
|
|
2764
2826
|
}
|
|
2765
|
-
return
|
|
2827
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
2766
2828
|
}
|
|
2767
2829
|
erf(x) {
|
|
2768
2830
|
const sign = x < 0 ? -1 : 1;
|
|
@@ -2787,12 +2849,12 @@ var QuantileTransformer = class {
|
|
|
2787
2849
|
}
|
|
2788
2850
|
interpolateFromSorted(sorted, q) {
|
|
2789
2851
|
if (sorted.length === 0) {
|
|
2790
|
-
throw new
|
|
2852
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: cannot interpolate empty sorted values");
|
|
2791
2853
|
}
|
|
2792
2854
|
if (sorted.length === 1) {
|
|
2793
2855
|
const only = sorted[0];
|
|
2794
2856
|
if (only === void 0) {
|
|
2795
|
-
throw new
|
|
2857
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing sorted value");
|
|
2796
2858
|
}
|
|
2797
2859
|
return only;
|
|
2798
2860
|
}
|
|
@@ -2802,7 +2864,7 @@ var QuantileTransformer = class {
|
|
|
2802
2864
|
const lowerValue = sorted[lower];
|
|
2803
2865
|
const upperValue = sorted[upper];
|
|
2804
2866
|
if (lowerValue === void 0 || upperValue === void 0) {
|
|
2805
|
-
throw new
|
|
2867
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: quantile interpolation index out of bounds");
|
|
2806
2868
|
}
|
|
2807
2869
|
if (upper === lower) {
|
|
2808
2870
|
return lowerValue;
|
|
@@ -2818,14 +2880,14 @@ var QuantileTransformer = class {
|
|
|
2818
2880
|
if (n === 1) {
|
|
2819
2881
|
const onlyReference = references[0];
|
|
2820
2882
|
if (onlyReference === void 0) {
|
|
2821
|
-
throw new
|
|
2883
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile reference");
|
|
2822
2884
|
}
|
|
2823
2885
|
return onlyReference;
|
|
2824
2886
|
}
|
|
2825
2887
|
const firstQuantile = quantiles[0];
|
|
2826
2888
|
const lastQuantile = quantiles[n - 1];
|
|
2827
2889
|
if (firstQuantile === void 0 || lastQuantile === void 0) {
|
|
2828
|
-
throw new
|
|
2890
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile endpoints");
|
|
2829
2891
|
}
|
|
2830
2892
|
if (value <= firstQuantile) {
|
|
2831
2893
|
return 0;
|
|
@@ -2839,7 +2901,7 @@ var QuantileTransformer = class {
|
|
|
2839
2901
|
const mid = Math.floor((left + right) / 2);
|
|
2840
2902
|
const midValue = quantiles[mid];
|
|
2841
2903
|
if (midValue === void 0) {
|
|
2842
|
-
throw new
|
|
2904
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile midpoint");
|
|
2843
2905
|
}
|
|
2844
2906
|
if (midValue <= value) {
|
|
2845
2907
|
left = mid;
|
|
@@ -2852,7 +2914,7 @@ var QuantileTransformer = class {
|
|
|
2852
2914
|
const rLeft = references[left];
|
|
2853
2915
|
const rRight = references[right];
|
|
2854
2916
|
if (qLeft === void 0 || qRight === void 0 || rLeft === void 0 || rRight === void 0) {
|
|
2855
|
-
throw new
|
|
2917
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile interpolation points");
|
|
2856
2918
|
}
|
|
2857
2919
|
if (qRight <= qLeft) {
|
|
2858
2920
|
return (rLeft + rRight) / 2;
|
|
@@ -2868,26 +2930,26 @@ var QuantileTransformer = class {
|
|
|
2868
2930
|
if (n === 1) {
|
|
2869
2931
|
const onlyQuantile = quantiles[0];
|
|
2870
2932
|
if (onlyQuantile === void 0) {
|
|
2871
|
-
throw new
|
|
2933
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile value");
|
|
2872
2934
|
}
|
|
2873
2935
|
return onlyQuantile;
|
|
2874
2936
|
}
|
|
2875
2937
|
const firstRef = references[0];
|
|
2876
2938
|
const lastRef = references[n - 1];
|
|
2877
2939
|
if (firstRef === void 0 || lastRef === void 0) {
|
|
2878
|
-
throw new
|
|
2940
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing reference endpoints");
|
|
2879
2941
|
}
|
|
2880
2942
|
if (quantile <= firstRef) {
|
|
2881
2943
|
const firstQuantile = quantiles[0];
|
|
2882
2944
|
if (firstQuantile === void 0) {
|
|
2883
|
-
throw new
|
|
2945
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile endpoints");
|
|
2884
2946
|
}
|
|
2885
2947
|
return firstQuantile;
|
|
2886
2948
|
}
|
|
2887
2949
|
if (quantile >= lastRef) {
|
|
2888
2950
|
const lastQuantile = quantiles[n - 1];
|
|
2889
2951
|
if (lastQuantile === void 0) {
|
|
2890
|
-
throw new
|
|
2952
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile endpoints");
|
|
2891
2953
|
}
|
|
2892
2954
|
return lastQuantile;
|
|
2893
2955
|
}
|
|
@@ -2897,7 +2959,7 @@ var QuantileTransformer = class {
|
|
|
2897
2959
|
const mid = Math.floor((left + right) / 2);
|
|
2898
2960
|
const midRef = references[mid];
|
|
2899
2961
|
if (midRef === void 0) {
|
|
2900
|
-
throw new
|
|
2962
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile reference");
|
|
2901
2963
|
}
|
|
2902
2964
|
if (midRef <= quantile) {
|
|
2903
2965
|
left = mid;
|
|
@@ -2910,7 +2972,7 @@ var QuantileTransformer = class {
|
|
|
2910
2972
|
const qLeft = quantiles[left];
|
|
2911
2973
|
const qRight = quantiles[right];
|
|
2912
2974
|
if (rLeft === void 0 || rRight === void 0 || qLeft === void 0 || qRight === void 0) {
|
|
2913
|
-
throw new
|
|
2975
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing quantile interpolation points");
|
|
2914
2976
|
}
|
|
2915
2977
|
if (rRight <= rLeft) {
|
|
2916
2978
|
return (qLeft + qRight) / 2;
|
|
@@ -2940,7 +3002,7 @@ var PowerTransformer = class {
|
|
|
2940
3002
|
constructor(options = {}) {
|
|
2941
3003
|
this.method = options.method ?? "yeo-johnson";
|
|
2942
3004
|
if (this.method !== "box-cox" && this.method !== "yeo-johnson") {
|
|
2943
|
-
throw new
|
|
3005
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
2944
3006
|
"method must be 'box-cox' or 'yeo-johnson'",
|
|
2945
3007
|
"method",
|
|
2946
3008
|
this.method
|
|
@@ -2951,7 +3013,7 @@ var PowerTransformer = class {
|
|
|
2951
3013
|
}
|
|
2952
3014
|
fit(X) {
|
|
2953
3015
|
if (X.size === 0) {
|
|
2954
|
-
throw new
|
|
3016
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X must contain at least one sample", "X");
|
|
2955
3017
|
}
|
|
2956
3018
|
assert2D(X, "X");
|
|
2957
3019
|
assertNumericTensor(X, "X");
|
|
@@ -2967,11 +3029,11 @@ var PowerTransformer = class {
|
|
|
2967
3029
|
for (let i = 0; i < nSamples; i++) {
|
|
2968
3030
|
const raw = data[X.offset + i * stride0 + j * stride1];
|
|
2969
3031
|
if (raw === void 0) {
|
|
2970
|
-
throw new
|
|
3032
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
2971
3033
|
}
|
|
2972
3034
|
const value = Number(raw);
|
|
2973
3035
|
if (this.method === "box-cox" && value <= 0) {
|
|
2974
|
-
throw new
|
|
3036
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
2975
3037
|
`Box-Cox requires strictly positive values in fit data (feature ${j})`,
|
|
2976
3038
|
"X",
|
|
2977
3039
|
value
|
|
@@ -3008,7 +3070,7 @@ var PowerTransformer = class {
|
|
|
3008
3070
|
}
|
|
3009
3071
|
transform(X) {
|
|
3010
3072
|
if (!this.fitted || !this.lambdas_) {
|
|
3011
|
-
throw new
|
|
3073
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("PowerTransformer must be fitted before transform");
|
|
3012
3074
|
}
|
|
3013
3075
|
assert2D(X, "X");
|
|
3014
3076
|
assertNumericTensor(X, "X");
|
|
@@ -3017,7 +3079,7 @@ var PowerTransformer = class {
|
|
|
3017
3079
|
const data = getNumericData2(X, "X");
|
|
3018
3080
|
const [stride0, stride1] = getStrides2D(X);
|
|
3019
3081
|
if (this.standardize && (!this.mean_ || !this.scale_)) {
|
|
3020
|
-
throw new
|
|
3082
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("PowerTransformer internal error: missing standardization stats");
|
|
3021
3083
|
}
|
|
3022
3084
|
const result = Array.from({ length: nSamples }, () => new Array(nFeatures).fill(0));
|
|
3023
3085
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -3025,17 +3087,17 @@ var PowerTransformer = class {
|
|
|
3025
3087
|
for (let j = 0; j < nFeatures; j++) {
|
|
3026
3088
|
const raw = data[rowBase + j * stride1];
|
|
3027
3089
|
if (raw === void 0) {
|
|
3028
|
-
throw new
|
|
3090
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
3029
3091
|
}
|
|
3030
3092
|
const val = Number(raw);
|
|
3031
3093
|
const lambda = this.lambdas_[j];
|
|
3032
3094
|
if (lambda === void 0) {
|
|
3033
|
-
throw new
|
|
3095
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError(`Internal error: missing fitted lambda for feature ${j}`);
|
|
3034
3096
|
}
|
|
3035
3097
|
let transformed;
|
|
3036
3098
|
if (this.method === "box-cox") {
|
|
3037
3099
|
if (val <= 0) {
|
|
3038
|
-
throw new
|
|
3100
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Box-Cox requires strictly positive values", "X", val);
|
|
3039
3101
|
}
|
|
3040
3102
|
transformed = this.boxCoxTransformValue(val, lambda);
|
|
3041
3103
|
} else {
|
|
@@ -3048,12 +3110,12 @@ var PowerTransformer = class {
|
|
|
3048
3110
|
}
|
|
3049
3111
|
const row = result[i];
|
|
3050
3112
|
if (row === void 0) {
|
|
3051
|
-
throw new
|
|
3113
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
3052
3114
|
}
|
|
3053
3115
|
row[j] = transformed;
|
|
3054
3116
|
}
|
|
3055
3117
|
}
|
|
3056
|
-
return
|
|
3118
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
3057
3119
|
}
|
|
3058
3120
|
/**
|
|
3059
3121
|
* Inverse transform data back to the original feature space.
|
|
@@ -3065,7 +3127,7 @@ var PowerTransformer = class {
|
|
|
3065
3127
|
*/
|
|
3066
3128
|
inverseTransform(X) {
|
|
3067
3129
|
if (!this.fitted || !this.lambdas_) {
|
|
3068
|
-
throw new
|
|
3130
|
+
throw new chunkZ6BGACIH_cjs.NotFittedError("PowerTransformer must be fitted before inverse_transform");
|
|
3069
3131
|
}
|
|
3070
3132
|
assert2D(X, "X");
|
|
3071
3133
|
assertNumericTensor(X, "X");
|
|
@@ -3074,7 +3136,7 @@ var PowerTransformer = class {
|
|
|
3074
3136
|
const data = getNumericData2(X, "X");
|
|
3075
3137
|
const [stride0, stride1] = getStrides2D(X);
|
|
3076
3138
|
if (this.standardize && (!this.mean_ || !this.scale_)) {
|
|
3077
|
-
throw new
|
|
3139
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("PowerTransformer internal error: missing standardization stats");
|
|
3078
3140
|
}
|
|
3079
3141
|
const result = Array.from({ length: nSamples }, () => new Array(nFeatures).fill(0));
|
|
3080
3142
|
for (let i = 0; i < nSamples; i++) {
|
|
@@ -3082,7 +3144,7 @@ var PowerTransformer = class {
|
|
|
3082
3144
|
for (let j = 0; j < nFeatures; j++) {
|
|
3083
3145
|
const raw = data[rowBase + j * stride1];
|
|
3084
3146
|
if (raw === void 0) {
|
|
3085
|
-
throw new
|
|
3147
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: numeric tensor access out of bounds");
|
|
3086
3148
|
}
|
|
3087
3149
|
let val = Number(raw);
|
|
3088
3150
|
if (this.standardize && this.mean_ && this.scale_) {
|
|
@@ -3092,7 +3154,7 @@ var PowerTransformer = class {
|
|
|
3092
3154
|
}
|
|
3093
3155
|
const lambda = this.lambdas_[j];
|
|
3094
3156
|
if (lambda === void 0) {
|
|
3095
|
-
throw new
|
|
3157
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError(`Internal error: missing fitted lambda for feature ${j}`);
|
|
3096
3158
|
}
|
|
3097
3159
|
let inverted;
|
|
3098
3160
|
if (this.method === "box-cox") {
|
|
@@ -3102,12 +3164,12 @@ var PowerTransformer = class {
|
|
|
3102
3164
|
}
|
|
3103
3165
|
const row = result[i];
|
|
3104
3166
|
if (row === void 0) {
|
|
3105
|
-
throw new
|
|
3167
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: result row access failed");
|
|
3106
3168
|
}
|
|
3107
3169
|
row[j] = inverted;
|
|
3108
3170
|
}
|
|
3109
3171
|
}
|
|
3110
|
-
return
|
|
3172
|
+
return chunk724CXHFH_cjs.tensor(result, { dtype: "float64", device: X.device });
|
|
3111
3173
|
}
|
|
3112
3174
|
boxCoxTransformValue(value, lambda) {
|
|
3113
3175
|
return Math.abs(lambda) < 1e-12 ? Math.log(value) : (value ** lambda - 1) / lambda;
|
|
@@ -3125,7 +3187,7 @@ var PowerTransformer = class {
|
|
|
3125
3187
|
}
|
|
3126
3188
|
const base = value * lambda + 1;
|
|
3127
3189
|
if (base <= 0) {
|
|
3128
|
-
throw new
|
|
3190
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Box-Cox inverse encountered invalid value", "X", value);
|
|
3129
3191
|
}
|
|
3130
3192
|
return base ** (1 / lambda);
|
|
3131
3193
|
}
|
|
@@ -3136,7 +3198,7 @@ var PowerTransformer = class {
|
|
|
3136
3198
|
}
|
|
3137
3199
|
const base2 = value * lambda + 1;
|
|
3138
3200
|
if (base2 <= 0) {
|
|
3139
|
-
throw new
|
|
3201
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3140
3202
|
"Yeo-Johnson inverse encountered invalid value",
|
|
3141
3203
|
"X",
|
|
3142
3204
|
value
|
|
@@ -3150,7 +3212,7 @@ var PowerTransformer = class {
|
|
|
3150
3212
|
}
|
|
3151
3213
|
const base = 1 - value * twoMinusLambda;
|
|
3152
3214
|
if (base <= 0) {
|
|
3153
|
-
throw new
|
|
3215
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Yeo-Johnson inverse encountered invalid value", "X", value);
|
|
3154
3216
|
}
|
|
3155
3217
|
return 1 - base ** (1 / twoMinusLambda);
|
|
3156
3218
|
}
|
|
@@ -3160,7 +3222,7 @@ var PowerTransformer = class {
|
|
|
3160
3222
|
for (let i = 0; i < values.length; i++) {
|
|
3161
3223
|
const value = values[i];
|
|
3162
3224
|
if (value === void 0) {
|
|
3163
|
-
throw new
|
|
3225
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: missing feature value during optimization");
|
|
3164
3226
|
}
|
|
3165
3227
|
let transformedValue;
|
|
3166
3228
|
if (this.method === "box-cox") {
|
|
@@ -3250,7 +3312,7 @@ var PowerTransformer = class {
|
|
|
3250
3312
|
// src/preprocess/split.ts
|
|
3251
3313
|
function validateNSplits(nSplits) {
|
|
3252
3314
|
if (!Number.isFinite(nSplits) || !Number.isInteger(nSplits) || nSplits < 2) {
|
|
3253
|
-
throw new
|
|
3315
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("nSplits must be an integer at least 2", "nSplits", nSplits);
|
|
3254
3316
|
}
|
|
3255
3317
|
}
|
|
3256
3318
|
function parseSplitSpec(value, name) {
|
|
@@ -3258,13 +3320,13 @@ function parseSplitSpec(value, name) {
|
|
|
3258
3320
|
return void 0;
|
|
3259
3321
|
}
|
|
3260
3322
|
if (!Number.isFinite(value) || value <= 0) {
|
|
3261
|
-
throw new
|
|
3323
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(`${name} must be a positive number`, name, value);
|
|
3262
3324
|
}
|
|
3263
3325
|
if (value < 1) {
|
|
3264
3326
|
return { kind: "fraction", value };
|
|
3265
3327
|
}
|
|
3266
3328
|
if (!Number.isInteger(value)) {
|
|
3267
|
-
throw new
|
|
3329
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3268
3330
|
`${name} must be an integer when provided as an absolute size`,
|
|
3269
3331
|
name,
|
|
3270
3332
|
value
|
|
@@ -3284,21 +3346,21 @@ function resolveTrainTestCounts(nSamples, trainSize, testSize) {
|
|
|
3284
3346
|
const trainSpec = parseSplitSpec(trainSize, "trainSize");
|
|
3285
3347
|
const testSpec = parseSplitSpec(defaultTestSize, "testSize");
|
|
3286
3348
|
if (trainSpec?.kind === "count" && trainSpec.value > nSamples) {
|
|
3287
|
-
throw new
|
|
3349
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3288
3350
|
"trainSize must not exceed number of samples",
|
|
3289
3351
|
"trainSize",
|
|
3290
3352
|
trainSpec.value
|
|
3291
3353
|
);
|
|
3292
3354
|
}
|
|
3293
3355
|
if (testSpec?.kind === "count" && testSpec.value > nSamples) {
|
|
3294
|
-
throw new
|
|
3356
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3295
3357
|
"testSize must not exceed number of samples",
|
|
3296
3358
|
"testSize",
|
|
3297
3359
|
testSpec.value
|
|
3298
3360
|
);
|
|
3299
3361
|
}
|
|
3300
3362
|
if (trainSpec?.kind === "fraction" && testSpec?.kind === "fraction" && trainSpec.value + testSpec.value > 1) {
|
|
3301
|
-
throw new
|
|
3363
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3302
3364
|
"trainSize and testSize fractions must sum to at most 1",
|
|
3303
3365
|
"trainSize",
|
|
3304
3366
|
trainSpec.value
|
|
@@ -3307,7 +3369,7 @@ function resolveTrainTestCounts(nSamples, trainSize, testSize) {
|
|
|
3307
3369
|
let nTrain = trainSpec === void 0 ? void 0 : resolveSplitCount(trainSpec, nSamples, true);
|
|
3308
3370
|
let nTest = testSpec === void 0 ? void 0 : resolveSplitCount(testSpec, nSamples, false);
|
|
3309
3371
|
if (nTrain === void 0 && nTest === void 0) {
|
|
3310
|
-
throw new
|
|
3372
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: failed to resolve split sizes");
|
|
3311
3373
|
}
|
|
3312
3374
|
if (nTrain === void 0) {
|
|
3313
3375
|
nTrain = nSamples - (nTest ?? 0);
|
|
@@ -3316,17 +3378,17 @@ function resolveTrainTestCounts(nSamples, trainSize, testSize) {
|
|
|
3316
3378
|
nTest = nSamples - nTrain;
|
|
3317
3379
|
}
|
|
3318
3380
|
if (nTrain + nTest > nSamples) {
|
|
3319
|
-
throw new
|
|
3381
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3320
3382
|
"trainSize and testSize exceed number of samples",
|
|
3321
3383
|
"trainSize",
|
|
3322
3384
|
trainSize
|
|
3323
3385
|
);
|
|
3324
3386
|
}
|
|
3325
3387
|
if (nTrain < 1) {
|
|
3326
|
-
throw new
|
|
3388
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("trainSize must be at least 1 sample", "trainSize", trainSize);
|
|
3327
3389
|
}
|
|
3328
3390
|
if (nTest < 1) {
|
|
3329
|
-
throw new
|
|
3391
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("testSize must be at least 1 sample", "testSize", testSize);
|
|
3330
3392
|
}
|
|
3331
3393
|
return [nTrain, nTest];
|
|
3332
3394
|
}
|
|
@@ -3349,18 +3411,18 @@ function readTensorValue(t, indices) {
|
|
|
3349
3411
|
if (typeof value === "string" || typeof value === "number" || typeof value === "bigint") {
|
|
3350
3412
|
return value;
|
|
3351
3413
|
}
|
|
3352
|
-
throw new
|
|
3414
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: unsupported tensor value type");
|
|
3353
3415
|
}
|
|
3354
3416
|
function writeTensorValue(t, flatIndex, value) {
|
|
3355
3417
|
if (t.dtype === "string") {
|
|
3356
3418
|
if (typeof value !== "string") {
|
|
3357
|
-
throw new
|
|
3419
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: expected string value for string tensor");
|
|
3358
3420
|
}
|
|
3359
3421
|
t.data[flatIndex] = value;
|
|
3360
3422
|
return;
|
|
3361
3423
|
}
|
|
3362
3424
|
if (typeof value === "string") {
|
|
3363
|
-
throw new
|
|
3425
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: encountered string value in numeric tensor");
|
|
3364
3426
|
}
|
|
3365
3427
|
if (t.data instanceof BigInt64Array) {
|
|
3366
3428
|
t.data[flatIndex] = typeof value === "bigint" ? value : BigInt(value);
|
|
@@ -3370,11 +3432,11 @@ function writeTensorValue(t, flatIndex, value) {
|
|
|
3370
3432
|
}
|
|
3371
3433
|
function takeRows2D(X, sampleIndices) {
|
|
3372
3434
|
const [, nFeatures] = getShape2D(X);
|
|
3373
|
-
const out =
|
|
3435
|
+
const out = chunk724CXHFH_cjs.zeros([sampleIndices.length, nFeatures], { dtype: X.dtype });
|
|
3374
3436
|
for (let i = 0; i < sampleIndices.length; i++) {
|
|
3375
3437
|
const sampleIndex = sampleIndices[i];
|
|
3376
3438
|
if (sampleIndex === void 0) {
|
|
3377
|
-
throw new
|
|
3439
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: sample index access failed");
|
|
3378
3440
|
}
|
|
3379
3441
|
for (let j = 0; j < nFeatures; j++) {
|
|
3380
3442
|
const value = readTensorValue(X, [sampleIndex, j]);
|
|
@@ -3385,13 +3447,13 @@ function takeRows2D(X, sampleIndices) {
|
|
|
3385
3447
|
}
|
|
3386
3448
|
function takeVector(y, sampleIndices) {
|
|
3387
3449
|
if (y.ndim !== 1) {
|
|
3388
|
-
throw new
|
|
3450
|
+
throw new chunkZ6BGACIH_cjs.ShapeError(`y must be a 1D tensor, got ${y.ndim}D`);
|
|
3389
3451
|
}
|
|
3390
|
-
const out =
|
|
3452
|
+
const out = chunk724CXHFH_cjs.zeros([sampleIndices.length], { dtype: y.dtype });
|
|
3391
3453
|
for (let i = 0; i < sampleIndices.length; i++) {
|
|
3392
3454
|
const sampleIndex = sampleIndices[i];
|
|
3393
3455
|
if (sampleIndex === void 0) {
|
|
3394
|
-
throw new
|
|
3456
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: sample index access failed");
|
|
3395
3457
|
}
|
|
3396
3458
|
const value = readTensorValue(y, [sampleIndex]);
|
|
3397
3459
|
writeTensorValue(out, out.offset + i, value);
|
|
@@ -3404,21 +3466,21 @@ function trainTestSplit(X, y, options) {
|
|
|
3404
3466
|
const randomState = opts.randomState;
|
|
3405
3467
|
const [nSamples] = getShape2D(X);
|
|
3406
3468
|
if (nSamples === 0) {
|
|
3407
|
-
throw new
|
|
3469
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("Cannot split empty array", "X");
|
|
3408
3470
|
}
|
|
3409
3471
|
if (y) {
|
|
3410
3472
|
const yShape0 = y.shape[0];
|
|
3411
3473
|
if (yShape0 === void 0 || yShape0 !== nSamples) {
|
|
3412
|
-
throw new
|
|
3474
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X and y must have same number of samples", "y", yShape0);
|
|
3413
3475
|
}
|
|
3414
3476
|
}
|
|
3415
3477
|
if (opts.stratify) {
|
|
3416
3478
|
if (opts.stratify.ndim !== 1) {
|
|
3417
|
-
throw new
|
|
3479
|
+
throw new chunkZ6BGACIH_cjs.ShapeError(`stratify must be a 1D tensor, got ${opts.stratify.ndim}D`);
|
|
3418
3480
|
}
|
|
3419
3481
|
const stratifyShape0 = opts.stratify.shape[0];
|
|
3420
3482
|
if (stratifyShape0 === void 0 || stratifyShape0 !== nSamples) {
|
|
3421
|
-
throw new
|
|
3483
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3422
3484
|
"stratify must have same number of samples as X",
|
|
3423
3485
|
"stratify",
|
|
3424
3486
|
stratifyShape0
|
|
@@ -3451,21 +3513,21 @@ function trainTestSplit(X, y, options) {
|
|
|
3451
3513
|
const classSizes = labels.map((label) => labelMap.get(label)?.length ?? 0);
|
|
3452
3514
|
const hasSingleton = classSizes.some((size) => size < 2);
|
|
3453
3515
|
if (hasSingleton && shuffle && randomState === void 0) {
|
|
3454
|
-
throw new
|
|
3516
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3455
3517
|
"stratify requires at least 2 samples per class",
|
|
3456
3518
|
"stratify",
|
|
3457
3519
|
classSizes
|
|
3458
3520
|
);
|
|
3459
3521
|
}
|
|
3460
3522
|
if (opts.trainSize !== void 0 && nTrain < nClasses) {
|
|
3461
|
-
throw new
|
|
3523
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3462
3524
|
"trainSize must be at least the number of classes when stratifying",
|
|
3463
3525
|
"trainSize",
|
|
3464
3526
|
nTrain
|
|
3465
3527
|
);
|
|
3466
3528
|
}
|
|
3467
3529
|
if (nTest < nClasses) {
|
|
3468
|
-
throw new
|
|
3530
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3469
3531
|
"testSize must be at least the number of classes when stratifying",
|
|
3470
3532
|
"testSize",
|
|
3471
3533
|
nTest
|
|
@@ -3515,7 +3577,7 @@ function trainTestSplit(X, y, options) {
|
|
|
3515
3577
|
guard += 1;
|
|
3516
3578
|
}
|
|
3517
3579
|
if (remaining !== 0) {
|
|
3518
|
-
throw new
|
|
3580
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: unable to allocate stratified split sizes");
|
|
3519
3581
|
}
|
|
3520
3582
|
}
|
|
3521
3583
|
const remainingTrainPool = [];
|
|
@@ -3534,7 +3596,7 @@ function trainTestSplit(X, y, options) {
|
|
|
3534
3596
|
testIndices = indices.slice(nTrain, nTrain + nTest);
|
|
3535
3597
|
}
|
|
3536
3598
|
if (trainIndices.length !== nTrain || testIndices.length !== nTest) {
|
|
3537
|
-
throw new
|
|
3599
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: resolved split indices do not match requested sizes");
|
|
3538
3600
|
}
|
|
3539
3601
|
const XTrain = takeRows2D(X, trainIndices);
|
|
3540
3602
|
const XTest = takeRows2D(X, testIndices);
|
|
@@ -3557,12 +3619,12 @@ var KFold = class {
|
|
|
3557
3619
|
split(X) {
|
|
3558
3620
|
const shape0 = X.shape[0];
|
|
3559
3621
|
if (shape0 === void 0) {
|
|
3560
|
-
throw new
|
|
3622
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("X must have valid shape[0]");
|
|
3561
3623
|
}
|
|
3562
3624
|
const nSamples = shape0;
|
|
3563
3625
|
validateNSplits(this.nSplits);
|
|
3564
3626
|
if (this.nSplits > nSamples) {
|
|
3565
|
-
throw new
|
|
3627
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3566
3628
|
"nSplits must not be greater than number of samples",
|
|
3567
3629
|
"nSplits",
|
|
3568
3630
|
this.nSplits
|
|
@@ -3582,7 +3644,7 @@ var KFold = class {
|
|
|
3582
3644
|
const testEnd = current + foldSize;
|
|
3583
3645
|
const testIndices = indices.slice(testStart, testEnd);
|
|
3584
3646
|
const trainIndices = [...indices.slice(0, testStart), ...indices.slice(testEnd)];
|
|
3585
|
-
splits.push(
|
|
3647
|
+
splits.push({ trainIndex: trainIndices, testIndex: testIndices });
|
|
3586
3648
|
current = testEnd;
|
|
3587
3649
|
}
|
|
3588
3650
|
return splits;
|
|
@@ -3603,12 +3665,12 @@ var StratifiedKFold = class {
|
|
|
3603
3665
|
split(X, y) {
|
|
3604
3666
|
const shape0 = X.shape[0];
|
|
3605
3667
|
if (shape0 === void 0) {
|
|
3606
|
-
throw new
|
|
3668
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("X must have valid shape[0]");
|
|
3607
3669
|
}
|
|
3608
3670
|
const nSamples = shape0;
|
|
3609
3671
|
validateNSplits(this.nSplits);
|
|
3610
3672
|
if (this.nSplits > nSamples) {
|
|
3611
|
-
throw new
|
|
3673
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3612
3674
|
"nSplits must not be greater than number of samples",
|
|
3613
3675
|
"nSplits",
|
|
3614
3676
|
this.nSplits
|
|
@@ -3616,10 +3678,10 @@ var StratifiedKFold = class {
|
|
|
3616
3678
|
}
|
|
3617
3679
|
const yShape0 = y.shape[0];
|
|
3618
3680
|
if (yShape0 === void 0 || yShape0 !== nSamples) {
|
|
3619
|
-
throw new
|
|
3681
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("X and y must have same number of samples", "y", yShape0);
|
|
3620
3682
|
}
|
|
3621
3683
|
if (y.ndim !== 1) {
|
|
3622
|
-
throw new
|
|
3684
|
+
throw new chunkZ6BGACIH_cjs.ShapeError(`y must be a 1D tensor, got ${y.ndim}D`);
|
|
3623
3685
|
}
|
|
3624
3686
|
const labelMap = /* @__PURE__ */ new Map();
|
|
3625
3687
|
const random = this.randomState !== void 0 ? createSeededRandom(this.randomState) : Math.random;
|
|
@@ -3637,7 +3699,7 @@ var StratifiedKFold = class {
|
|
|
3637
3699
|
shuffleIndicesInPlace(indices, random);
|
|
3638
3700
|
}
|
|
3639
3701
|
if (indices.length < this.nSplits) {
|
|
3640
|
-
throw new
|
|
3702
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3641
3703
|
`Each class must have at least nSplits samples; class ${label} has ${indices.length}`,
|
|
3642
3704
|
"nSplits",
|
|
3643
3705
|
this.nSplits
|
|
@@ -3653,7 +3715,7 @@ var StratifiedKFold = class {
|
|
|
3653
3715
|
const end = start + size;
|
|
3654
3716
|
const target = foldIndices[fold];
|
|
3655
3717
|
if (!target) {
|
|
3656
|
-
throw new
|
|
3718
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: stratified fold storage missing");
|
|
3657
3719
|
}
|
|
3658
3720
|
target.push(...indices.slice(start, end));
|
|
3659
3721
|
start = end;
|
|
@@ -3667,7 +3729,7 @@ var StratifiedKFold = class {
|
|
|
3667
3729
|
if (other === fold) continue;
|
|
3668
3730
|
trainIndices.push(...foldIndices[other] ?? []);
|
|
3669
3731
|
}
|
|
3670
|
-
splits.push(
|
|
3732
|
+
splits.push({ trainIndex: trainIndices, testIndex: testIndices });
|
|
3671
3733
|
}
|
|
3672
3734
|
return splits;
|
|
3673
3735
|
}
|
|
@@ -3683,16 +3745,16 @@ var GroupKFold = class {
|
|
|
3683
3745
|
split(X, _y, groups) {
|
|
3684
3746
|
const shape0 = X.shape[0];
|
|
3685
3747
|
if (shape0 === void 0) {
|
|
3686
|
-
throw new
|
|
3748
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("X must have valid shape[0]");
|
|
3687
3749
|
}
|
|
3688
3750
|
const nSamples = shape0;
|
|
3689
3751
|
validateNSplits(this.nSplits);
|
|
3690
3752
|
if (groups.ndim !== 1) {
|
|
3691
|
-
throw new
|
|
3753
|
+
throw new chunkZ6BGACIH_cjs.ShapeError(`groups must be a 1D tensor, got ${groups.ndim}D`);
|
|
3692
3754
|
}
|
|
3693
3755
|
const groupsShape0 = groups.shape[0];
|
|
3694
3756
|
if (groupsShape0 === void 0 || groupsShape0 !== nSamples) {
|
|
3695
|
-
throw new
|
|
3757
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3696
3758
|
"X and groups must have same number of samples",
|
|
3697
3759
|
"groups",
|
|
3698
3760
|
groupsShape0
|
|
@@ -3714,7 +3776,7 @@ var GroupKFold = class {
|
|
|
3714
3776
|
size: indices.length
|
|
3715
3777
|
}));
|
|
3716
3778
|
if (this.nSplits > groupEntries.length) {
|
|
3717
|
-
throw new
|
|
3779
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3718
3780
|
"Number of groups must be at least nSplits",
|
|
3719
3781
|
"nSplits",
|
|
3720
3782
|
this.nSplits
|
|
@@ -3738,7 +3800,7 @@ var GroupKFold = class {
|
|
|
3738
3800
|
}
|
|
3739
3801
|
const target = foldIndices[bestFold];
|
|
3740
3802
|
if (!target) {
|
|
3741
|
-
throw new
|
|
3803
|
+
throw new chunkZ6BGACIH_cjs.DeepboxError("Internal error: group fold storage missing");
|
|
3742
3804
|
}
|
|
3743
3805
|
target.push(...entry.indices);
|
|
3744
3806
|
foldSizes[bestFold] = bestSize + entry.size;
|
|
@@ -3751,7 +3813,7 @@ var GroupKFold = class {
|
|
|
3751
3813
|
if (other === fold) continue;
|
|
3752
3814
|
trainIndices.push(...foldIndices[other] ?? []);
|
|
3753
3815
|
}
|
|
3754
|
-
splits.push(
|
|
3816
|
+
splits.push({ trainIndex: trainIndices, testIndex: testIndices });
|
|
3755
3817
|
}
|
|
3756
3818
|
return splits;
|
|
3757
3819
|
}
|
|
@@ -3763,7 +3825,7 @@ var LeaveOneOut = class {
|
|
|
3763
3825
|
split(X) {
|
|
3764
3826
|
const shape0 = X.shape[0];
|
|
3765
3827
|
if (shape0 === void 0) {
|
|
3766
|
-
throw new
|
|
3828
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("X must have valid shape[0]");
|
|
3767
3829
|
}
|
|
3768
3830
|
const nSamples = shape0;
|
|
3769
3831
|
const splits = [];
|
|
@@ -3773,14 +3835,14 @@ var LeaveOneOut = class {
|
|
|
3773
3835
|
...Array.from({ length: nSamples - i - 1 }, (_, j) => i + 1 + j)
|
|
3774
3836
|
];
|
|
3775
3837
|
const testIndices = [i];
|
|
3776
|
-
splits.push(
|
|
3838
|
+
splits.push({ trainIndex: trainIndices, testIndex: testIndices });
|
|
3777
3839
|
}
|
|
3778
3840
|
return splits;
|
|
3779
3841
|
}
|
|
3780
3842
|
getNSplits(X) {
|
|
3781
3843
|
const shape0 = X.shape[0];
|
|
3782
3844
|
if (shape0 === void 0) {
|
|
3783
|
-
throw new
|
|
3845
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("X must have valid shape[0]");
|
|
3784
3846
|
}
|
|
3785
3847
|
return shape0;
|
|
3786
3848
|
}
|
|
@@ -3789,18 +3851,18 @@ var LeavePOut = class {
|
|
|
3789
3851
|
p;
|
|
3790
3852
|
constructor(p) {
|
|
3791
3853
|
if (!Number.isFinite(p) || !Number.isInteger(p) || p <= 0) {
|
|
3792
|
-
throw new
|
|
3854
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("p must be a positive integer", "p", p);
|
|
3793
3855
|
}
|
|
3794
3856
|
this.p = p;
|
|
3795
3857
|
}
|
|
3796
3858
|
split(X) {
|
|
3797
3859
|
const shape0 = X.shape[0];
|
|
3798
3860
|
if (shape0 === void 0) {
|
|
3799
|
-
throw new
|
|
3861
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("X must have valid shape[0]");
|
|
3800
3862
|
}
|
|
3801
3863
|
const nSamples = shape0;
|
|
3802
3864
|
if (this.p > nSamples) {
|
|
3803
|
-
throw new
|
|
3865
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("p must not be greater than number of samples", "p", this.p);
|
|
3804
3866
|
}
|
|
3805
3867
|
let nCombos = 1;
|
|
3806
3868
|
const k = this.p > nSamples / 2 ? nSamples - this.p : this.p;
|
|
@@ -3808,7 +3870,7 @@ var LeavePOut = class {
|
|
|
3808
3870
|
nCombos = nCombos * (nSamples - i) / (i + 1);
|
|
3809
3871
|
}
|
|
3810
3872
|
if (nCombos > 1e5) {
|
|
3811
|
-
throw new
|
|
3873
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError(
|
|
3812
3874
|
`LeavePOut produces ${Math.floor(nCombos)} splits, which exceeds memory safety limit of 100,000`,
|
|
3813
3875
|
"p",
|
|
3814
3876
|
this.p
|
|
@@ -3821,7 +3883,7 @@ var LeavePOut = class {
|
|
|
3821
3883
|
const testSet = new Set(currentCombo);
|
|
3822
3884
|
const testIndices = [...currentCombo];
|
|
3823
3885
|
const trainIndices = allIndices.filter((i) => !testSet.has(i));
|
|
3824
|
-
splits.push(
|
|
3886
|
+
splits.push({ trainIndex: trainIndices, testIndex: testIndices });
|
|
3825
3887
|
return;
|
|
3826
3888
|
}
|
|
3827
3889
|
for (let i = start; i < nSamples; i++) {
|
|
@@ -3836,11 +3898,11 @@ var LeavePOut = class {
|
|
|
3836
3898
|
getNSplits(X) {
|
|
3837
3899
|
const shape0 = X.shape[0];
|
|
3838
3900
|
if (shape0 === void 0) {
|
|
3839
|
-
throw new
|
|
3901
|
+
throw new chunkZ6BGACIH_cjs.ShapeError("X must have valid shape[0]");
|
|
3840
3902
|
}
|
|
3841
3903
|
const n = shape0;
|
|
3842
3904
|
if (this.p > n) {
|
|
3843
|
-
throw new
|
|
3905
|
+
throw new chunkZ6BGACIH_cjs.InvalidParameterError("p must not be greater than number of samples", "p", this.p);
|
|
3844
3906
|
}
|
|
3845
3907
|
let result = 1;
|
|
3846
3908
|
const k = this.p > n / 2 ? n - this.p : this.p;
|
|
@@ -3870,5 +3932,5 @@ exports.StandardScaler = StandardScaler;
|
|
|
3870
3932
|
exports.StratifiedKFold = StratifiedKFold;
|
|
3871
3933
|
exports.preprocess_exports = preprocess_exports;
|
|
3872
3934
|
exports.trainTestSplit = trainTestSplit;
|
|
3873
|
-
//# sourceMappingURL=chunk-
|
|
3874
|
-
//# sourceMappingURL=chunk-
|
|
3935
|
+
//# sourceMappingURL=chunk-IT4BZUYE.cjs.map
|
|
3936
|
+
//# sourceMappingURL=chunk-IT4BZUYE.cjs.map
|