@wlearn/automl 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/CHANGELOG.md +19 -0
- package/LICENSE +177 -0
- package/NOTICE +5 -0
- package/README.md +108 -0
- package/dist/automl.js +1 -0
- package/dist/automl.mjs +2 -0
- package/package.json +45 -9
- package/src/auto-fit.js +20 -8
- package/src/common.js +9 -7
- package/src/executor.js +6 -4
- package/src/halving.js +8 -6
- package/src/index.js +19 -12
- package/src/leaderboard.js +3 -1
- package/src/portfolio.js +130 -9
- package/src/progressive.js +8 -6
- package/src/sampler.js +7 -5
- package/src/search.js +8 -6
- package/src/strategy-halving.js +6 -4
- package/src/strategy-progressive.js +6 -4
- package/src/strategy-random.js +6 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Add optional Bayesian search strategy through `@wlearn/bo`
|
|
6
|
+
- Depend on the CommonJS `@wlearn/core` and `@wlearn/ensemble` releases
|
|
7
|
+
- Add package homepage and GitHub issue metadata
|
|
8
|
+
|
|
9
|
+
- Add portfolio configs for 8 new model families: rf, mlp, tabm, nam, gam, bart, fm, xlr
|
|
10
|
+
- Portfolio now covers 15 model families (up from 7) for both classification and regression
|
|
11
|
+
|
|
12
|
+
## 0.1.0
|
|
13
|
+
|
|
14
|
+
- Initial release
|
|
15
|
+
- autoFit with RandomSearch, SuccessiveHalvingSearch, PortfolioSearch, ProgressiveSearch
|
|
16
|
+
- Caruana ensemble selection, diversity filtering
|
|
17
|
+
- Leaderboard with ranking and provenance
|
|
18
|
+
- Portfolio configs for 7 model families: xgb, lgb, ebm, linear, svm, knn, tsetlin
|
|
19
|
+
- 135 tests
|
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @wlearn/automl
|
|
2
|
+
|
|
3
|
+
Automated model selection for wlearn. Searches over model families and hyperparameters, runs cross-validation, and optionally builds a Caruana ensemble from top candidates.
|
|
4
|
+
|
|
5
|
+
Part of [wlearn](https://wlearn.org) ([GitHub](https://github.com/wlearn-org), [all packages](https://github.com/wlearn-org/wlearn#repository-structure)).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @wlearn/automl
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires at least one model package (e.g. `@wlearn/xgboost`) to do anything useful.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const { autoFit } = require('@wlearn/automl')
|
|
19
|
+
const { LinearModel } = require('@wlearn/liblinear')
|
|
20
|
+
const { XGBModel } = require('@wlearn/xgboost')
|
|
21
|
+
|
|
22
|
+
const models = [
|
|
23
|
+
['linear', LinearModel, { task: 'classification' }],
|
|
24
|
+
['xgb', XGBModel, { task: 'classification' }]
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
const result = await autoFit(models, X, y, {
|
|
28
|
+
scoring: 'accuracy',
|
|
29
|
+
cv: 5,
|
|
30
|
+
nIter: 20,
|
|
31
|
+
ensemble: true,
|
|
32
|
+
ensembleSize: 10,
|
|
33
|
+
refit: true
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
result.model // best fitted estimator (or ensemble)
|
|
37
|
+
result.leaderboard // ranked candidate results
|
|
38
|
+
result.bestScore // best CV score
|
|
39
|
+
result.bestModelName // e.g. 'xgb'
|
|
40
|
+
result.bestParams // winning hyperparameters
|
|
41
|
+
|
|
42
|
+
result.model.dispose()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Search strategies
|
|
46
|
+
|
|
47
|
+
- `RandomSearch` -- random hyperparameter sampling (default)
|
|
48
|
+
- `SuccessiveHalvingSearch` -- early stopping with increasing resource allocation
|
|
49
|
+
- `PortfolioSearch` -- predefined portfolio of known-good configurations
|
|
50
|
+
- `ProgressiveSearch` -- progressive resource allocation
|
|
51
|
+
|
|
52
|
+
Each model provides a default search space via `Model.defaultSearchSpace()`. AutoML samples from these automatically.
|
|
53
|
+
|
|
54
|
+
## Portfolio
|
|
55
|
+
|
|
56
|
+
The portfolio contains pre-tuned hyperparameter configs for 15 model families:
|
|
57
|
+
|
|
58
|
+
| Model | Configs | Package |
|
|
59
|
+
|-------|---------|---------|
|
|
60
|
+
| xgb | 10 | `@wlearn/xgboost` |
|
|
61
|
+
| lgb | 6 | `@wlearn/lightgbm` |
|
|
62
|
+
| ebm | 4 | `@wlearn/ebm` |
|
|
63
|
+
| linear | 4 | `@wlearn/liblinear` |
|
|
64
|
+
| svm | 4 | `@wlearn/libsvm` |
|
|
65
|
+
| knn | 3 | `@wlearn/nanoflann` |
|
|
66
|
+
| tsetlin | 3 | `@wlearn/tsetlin` |
|
|
67
|
+
| rf | 4 | `@wlearn/rf` |
|
|
68
|
+
| mlp | 3 | `@wlearn/nn` (MLPClassifier/Regressor) |
|
|
69
|
+
| tabm | 3 | `@wlearn/nn` (TabMClassifier/Regressor) |
|
|
70
|
+
| nam | 3 | `@wlearn/nn` (NAMClassifier/Regressor) |
|
|
71
|
+
| gam | 4 | `@wlearn/gam` |
|
|
72
|
+
| bart | 3 | `@wlearn/stochtree` |
|
|
73
|
+
| fm | 2 | `@wlearn/xlearn` (FM) |
|
|
74
|
+
| xlr | 2 | `@wlearn/xlearn` (LR) |
|
|
75
|
+
|
|
76
|
+
Classification and regression have separate config sets with task-appropriate parameters.
|
|
77
|
+
|
|
78
|
+
## autoFit options
|
|
79
|
+
|
|
80
|
+
- `scoring` -- metric name (`'accuracy'`, `'r2'`, `'neg_mse'`) or custom function
|
|
81
|
+
- `cv` -- number of CV folds (default: 5)
|
|
82
|
+
- `nIter` -- number of random search iterations (default: 10)
|
|
83
|
+
- `seed` -- random seed for reproducibility
|
|
84
|
+
- `task` -- `'classification'` or `'regression'` (auto-detected if omitted)
|
|
85
|
+
- `ensemble` -- build Caruana ensemble from top candidates (default: false)
|
|
86
|
+
- `ensembleSize` -- max ensemble members (default: 20)
|
|
87
|
+
- `refit` -- refit best model on full data (default: true)
|
|
88
|
+
|
|
89
|
+
## Leaderboard
|
|
90
|
+
|
|
91
|
+
`result.leaderboard` is an array of `CandidateResult` objects sorted by score:
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
{
|
|
95
|
+
id: 0,
|
|
96
|
+
modelName: 'xgb',
|
|
97
|
+
params: { max_depth: 6, eta: 0.1, ... },
|
|
98
|
+
scores: Float64Array([0.92, 0.94, 0.91, 0.93, 0.90]),
|
|
99
|
+
meanScore: 0.92,
|
|
100
|
+
stdScore: 0.014,
|
|
101
|
+
fitTimeMs: 42,
|
|
102
|
+
rank: 1
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
Apache-2.0
|
package/dist/automl.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var automl=(()=>{var Jn=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var S=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var z=S((oc,ve)=>{var $=class extends Error{constructor(t,n){super(t),this.name="WlearnError",this.code=n||"ERR_WLEARN"}},St=class extends ${constructor(t){super(t,"ERR_BUNDLE"),this.name="BundleError"}},_t=class extends ${constructor(t){super(t,"ERR_REGISTRY"),this.name="RegistryError"}},vt=class extends ${constructor(t){super(t,"ERR_VALIDATION"),this.name="ValidationError"}},Ft=class extends ${constructor(t="Model is not fitted. Call fit() first."){super(t,"ERR_NOT_FITTED"),this.name="NotFittedError"}},At=class extends ${constructor(t="Model has been disposed."){super(t,"ERR_DISPOSED"),this.name="DisposedError"}};ve.exports={WlearnError:$,BundleError:St,RegistryError:_t,ValidationError:vt,NotFittedError:Ft,DisposedError:At}});var G=S((ac,Fe)=>{var{ValidationError:N}=z();function Kn(s,t="auto"){if(s&&typeof s=="object"&&!Array.isArray(s)&&s.data){let{data:n,rows:e,cols:i}=s;if(!(n instanceof Float64Array)){if(t==="error")throw new N("Expected Float64Array in typed matrix");return{data:new Float64Array(n),rows:e,cols:i}}return{data:n,rows:e,cols:i}}if(Array.isArray(s)&&Array.isArray(s[0])){if(t==="error")throw new N('Input coercion disabled (coerce: "error"). Pass { data: Float64Array, rows, cols } instead of number[][].');let n=s.length,e=s[0].length,i=new Float64Array(n*e);for(let r=0;r<n;r++)for(let o=0;o<e;o++)i[r*e+o]=s[r][o];if(t==="warn"){let r=i.byteLength;console.warn(`@wlearn/core: Converted number[][] to Float64Array (copied ${(r/1024).toFixed(1)} KB, shape ${n}x${e}). For performance, pass { data, rows, cols }.`)}return{data:i,rows:n,cols:e}}throw new N("X must be number[][] or { data: Float64Array, rows, cols }")}function Hn(s){return s instanceof Int32Array||s instanceof Float32Array||s instanceof Float64Array?s:new Float64Array(s)}function Zn(s,t,n){if(!t||!n||t<1||n<1)throw new N(`Invalid dimensions: rows=${t}, cols=${n}`);if(!(s instanceof Float32Array)&&!(s instanceof Float64Array))throw new N("data must be Float32Array or Float64Array");if(s.length!==t*n)throw new N(`data.length (${s.length}) !== rows * cols (${t*n})`);return{data:s,rows:t,cols:n}}function Qn(s){if(!s||typeof s!="object")throw new N("Matrix must be an object");let{data:t,rows:n,cols:e}=s;if(typeof n!="number"||typeof e!="number"||n<1||e<1)throw new N(`Invalid dimensions: rows=${n}, cols=${e}`);if(!(t instanceof Float32Array)&&!(t instanceof Float64Array))throw new N("data must be Float32Array or Float64Array");if(t.length!==n*e)throw new N(`data.length (${t.length}) !== rows * cols (${n*e})`);return s}Fe.exports={normalizeX:Kn,normalizeY:Hn,makeDense:Zn,validateMatrix:Qn}});var kt=S((cc,Ae)=>{var tr=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),R=new Uint32Array(64);function L(s,t){return s>>>t|s<<32-t}function er(s,t,n){for(let f=0;f<16;f++)R[f]=(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0,n+=4;for(let f=16;f<64;f++){let u=L(R[f-15],7)^L(R[f-15],18)^R[f-15]>>>3,d=L(R[f-2],17)^L(R[f-2],19)^R[f-2]>>>10;R[f]=R[f-16]+u+R[f-7]+d>>>0}let e=s[0],i=s[1],r=s[2],o=s[3],a=s[4],l=s[5],h=s[6],c=s[7];for(let f=0;f<64;f++){let u=L(a,6)^L(a,11)^L(a,25),d=a&l^~a&h,m=c+u+d+tr[f]+R[f]>>>0,p=L(e,2)^L(e,13)^L(e,22),g=e&i^e&r^i&r,w=p+g>>>0;c=h,h=l,l=a,a=o+m>>>0,o=r,r=i,i=e,e=m+w>>>0}s[0]=s[0]+e>>>0,s[1]=s[1]+i>>>0,s[2]=s[2]+r>>>0,s[3]=s[3]+o>>>0,s[4]=s[4]+a>>>0,s[5]=s[5]+l>>>0,s[6]=s[6]+h>>>0,s[7]=s[7]+c>>>0}function sr(s){let t=s instanceof Uint8Array?s:new Uint8Array(s),n=t.length,e=n*8,i=n+9+63&-64,r=new Uint8Array(i);r.set(t),r[n]=128;let o=new DataView(r.buffer);o.setUint32(i-4,e>>>0,!1),e>4294967295&&o.setUint32(i-8,e/4294967296>>>0,!1);let a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);for(let h=0;h<i;h+=64)er(a,r,h);let l="";for(let h=0;h<8;h++)l+=a[h].toString(16).padStart(8,"0");return l}Ae.exports={sha256Sync:sr}});var qe=S((lc,ke)=>{var nr=new Uint8Array([87,76,82,78]),rr=1,ir=16,or={FLOAT32:"float32",FLOAT64:"float64",INT32:"int32"};ke.exports={BUNDLE_MAGIC:nr,BUNDLE_VERSION:rr,HEADER_SIZE:ir,DTYPE:or}});var tt=S((fc,Re)=>{var{BUNDLE_MAGIC:Ee,BUNDLE_VERSION:at,HEADER_SIZE:E}=qe(),{BundleError:C}=z(),{sha256Sync:Ie}=kt();function Q(s){return s==null||typeof s!="object"?JSON.stringify(s):Array.isArray(s)?"["+s.map(n=>Q(n)).join(",")+"]":"{"+Object.keys(s).sort().map(n=>JSON.stringify(n)+":"+Q(s[n])).join(",")+"}"}var qt=new TextEncoder,Et=new TextDecoder;function ar(s,t){let n=[...t].sort((d,m)=>d.id<m.id?-1:d.id>m.id?1:0),e=0,i=[],r=[];for(let d of n){let m=d.data instanceof Uint8Array?d.data:new Uint8Array(d.data),p=Ie(m),g={id:d.id,offset:e,length:m.length,sha256:p};d.mediaType&&(g.mediaType=d.mediaType),i.push(g),r.push(m),e+=m.length}let o={...s,bundleVersion:at},a=qt.encode(Q(o)),l=qt.encode(Q(i)),h=E+a.length+l.length+e,c=new Uint8Array(h),f=new DataView(c.buffer);c.set(Ee,0),f.setUint32(4,at,!0),f.setUint32(8,a.length,!0),f.setUint32(12,l.length,!0),c.set(a,E),c.set(l,E+a.length);let u=E+a.length+l.length;for(let d of r)c.set(d,u),u+=d.length;return c}function Pe(s){let t=s instanceof Uint8Array?s:new Uint8Array(s);if(t.length<E)throw new C(`Bundle too small: ${t.length} bytes (minimum ${E})`);for(let f=0;f<4;f++)if(t[f]!==Ee[f])throw new C("Invalid bundle magic (expected WLRN)");let n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=n.getUint32(4,!0);if(e!==at)throw new C(`Unsupported bundle version: ${e} (expected ${at})`);let i=n.getUint32(8,!0),r=n.getUint32(12,!0);if(E+i+r>t.length)throw new C(`Bundle truncated: header declares ${E+i+r} bytes but got ${t.length}`);let o,a;try{o=JSON.parse(Et.decode(t.subarray(E,E+i)))}catch(f){throw new C(`Invalid manifest JSON: ${f.message}`)}try{a=JSON.parse(Et.decode(t.subarray(E+i,E+i+r)))}catch(f){throw new C(`Invalid TOC JSON: ${f.message}`)}let l=E+i+r,h=t.length-l;for(let f=0;f<a.length;f++){let u=a[f];if(u.offset<0||u.length<0||u.offset+u.length>h)throw new C(`TOC entry "${u.id}" out of bounds: offset=${u.offset}, length=${u.length}, blobRegion=${h}`);for(let d=f+1;d<a.length;d++){let m=a[d],p=u.offset,g=u.offset+u.length,w=m.offset,b=m.offset+m.length;if(p<b&&w<g&&u.length>0&&m.length>0)throw new C(`TOC entries "${u.id}" and "${m.id}" overlap`)}}let c=t.subarray(l);return{manifest:o,toc:a,blobs:c}}function cr(s){return qt.encode(Q(s))}function lr(s){let t=s instanceof Uint8Array?s:new Uint8Array(s);return JSON.parse(Et.decode(t))}function fr(s){let{manifest:t,toc:n,blobs:e}=Pe(s);for(let i of n){let r=e.subarray(i.offset,i.offset+i.length),o=Ie(r);if(o!==i.sha256)throw new C(`SHA-256 mismatch for "${i.id}": expected ${i.sha256}, got ${o}`)}return{manifest:t,toc:n,blobs:e}}Re.exports={encodeBundle:ar,decodeBundle:Pe,encodeJSON:cr,decodeJSON:lr,validateBundle:fr}});var ct=S((hc,ze)=>{var{RegistryError:V}=z(),{decodeBundle:Me}=tt(),W=new Map;function hr(s,t){if(typeof s!="string"||!s.includes("@"))throw new V(`Invalid typeId "${s}": must contain "@" (e.g. "wlearn.liblinear.classifier@1")`);if(typeof t!="function")throw new V("loaderFn must be a function");W.set(s,t)}async function ur(s){let{manifest:t,toc:n,blobs:e}=Me(s),{typeId:i}=t;if(!i)throw new V("Bundle manifest missing typeId");let r=W.get(i);if(!r){let o=[...W.keys()],a=o.length>0?`Registered loaders: ${o.join(", ")}`:"No loaders registered";throw new V(`No loader registered for typeId "${i}". ${a}. Install the corresponding @wlearn/* package and import it to register the loader.`)}return await r(t,n,e)}function dr(s){let{manifest:t,toc:n,blobs:e}=Me(s),{typeId:i}=t;if(!i)throw new V("Bundle manifest missing typeId");let r=W.get(i);if(!r){let a=[...W.keys()],l=a.length>0?`Registered loaders: ${a.join(", ")}`:"No loaders registered";throw new V(`No loader registered for typeId "${i}". ${l}. Install the corresponding @wlearn/* package and import it to register the loader.`)}let o=r(t,n,e);if(o&&typeof o.then=="function")throw new V(`Loader for "${i}" returned a Promise. Use async load() instead of loadSync().`);return o}function mr(){return new Map(W)}ze.exports={register:hr,load:ur,loadSync:dr,getRegistry:mr}});var Pt=S((uc,Ne)=>{var It=class{#t;#e;constructor(t,n){this.#t=t,this.#e=n}get name(){return this.#t}get estimator(){return this.#e}get isFitted(){return this.#e.isFitted}get isTransformer(){return typeof this.#e.transform=="function"}};Ne.exports={Step:It}});var je=S((dc,Ce)=>{var{Step:pr}=Pt(),{DisposedError:gr,NotFittedError:br,ValidationError:lt}=z(),{encodeBundle:wr,decodeBundle:yr}=tt(),{register:xr,load:Le}=ct(),Be="wlearn.pipeline@1",Oe=!1,ft=class s{#t;#e=!1;#s=!1;constructor(t){if(this.#t=t.map(([n,e])=>new pr(n,e)),this.#t.length===0)throw new lt("Pipeline requires at least one step")}#n(){if(this.#s)throw new gr("Pipeline has been disposed.")}#i(){if(this.#n(),!this.#e)throw new br("Pipeline is not fitted. Call fit() first.")}#r(t){let n=t;for(let e=0;e<this.#t.length-1;e++)n=this.#t[e].estimator.transform(n);return n}fit(t,n){this.#n();let e=t;for(let r=0;r<this.#t.length-1;r++){let o=this.#t[r].estimator;typeof o.fitTransform=="function"?e=o.fitTransform(e,n):(o.fit(e,n),e=o.transform(e))}return this.#t[this.#t.length-1].estimator.fit(e,n),this.#e=!0,this}predict(t){this.#i();let n=this.#r(t);return this.#t[this.#t.length-1].estimator.predict(n)}predictProba(t){this.#i();let n=this.#t[this.#t.length-1].estimator;if(typeof n.predictProba!="function")throw new lt("Last step does not support predictProba");let e=this.#r(t);return n.predictProba(e)}score(t,n){this.#i();let e=this.#r(t);return this.#t[this.#t.length-1].estimator.score(e,n)}save(){this.#i();let t={typeId:Be,steps:this.#t.map(e=>({name:e.name,params:e.estimator.getParams()}))},n=this.#t.map(e=>({id:e.name,data:e.estimator.save(),mediaType:"application/x-wlearn-bundle"}));return wr(t,n)}static async load(t){let{manifest:n,toc:e,blobs:i}=yr(t),r=[];for(let a of n.steps){let l=e.find(f=>f.id===a.name);if(!l)throw new lt(`No artifact found for pipeline step "${a.name}"`);let h=i.subarray(l.offset,l.offset+l.length),c=await Le(h);r.push([a.name,c])}let o=new s(r);return o.#e=!0,o}dispose(){if(!this.#s){this.#s=!0;for(let t of this.#t)t.estimator.dispose()}}getParams(){let t={};for(let n of this.#t)t[n.name]=n.estimator.getParams();return t}setParams(t){this.#n();for(let n of this.#t)t[n.name]&&n.estimator.setParams(t[n.name]);return this}get capabilities(){return this.#t[this.#t.length-1].estimator.capabilities}get isFitted(){return this.#e}static registerLoader(){Oe||(Oe=!0,xr(Be,(t,n,e)=>s._loadFromParts(t,n,e)))}static async _loadFromParts(t,n,e){let i=[];for(let o of t.steps){let a=n.find(c=>c.id===o.name);if(!a)throw new lt(`No artifact found for pipeline step "${o.name}"`);let l=e.subarray(a.offset,a.offset+a.length),h=await Le(l);i.push([o.name,h])}let r=new s(i);return r.#e=!0,r}};ft.registerLoader();Ce.exports={Pipeline:ft}});var Xe=S((pc,De)=>{var{normalizeX:Te,normalizeY:mc}=G(),{ValidationError:$e}=z(),Rt=class s{#t;#e=!1;#s=null;#n=null;#i=null;#r=null;#o=0;constructor(t={}){this.#t={impute:t.impute??"auto",encode:t.encode??"auto",scale:t.scale??!1,maxCategories:t.maxCategories??20,...t}}fit(t,n){let e=Te(t),{data:i,rows:r,cols:o}=e;this.#s=new Array(o),this.#n=new Float64Array(o);let a=new Array(o);for(let h=0;h<o;h++){let c=[],f=!1,u=0,d=0;for(let w=0;w<r;w++){let b=i[w*o+h];Number.isNaN(b)?f=!0:(c.push(b),u+=b,d++)}let m=new Set(c),p=c.every(w=>w===Math.floor(w)),g=this.#t.encode!==!1&&p&&m.size<=this.#t.maxCategories&&m.size>=2;if(this.#s[h]=g?"categorical":"numeric",this.#t.impute!==!1&&f)if(g){let w=new Map;for(let _ of c)w.set(_,(w.get(_)||0)+1);let b=c[0],y=0;for(let[_,A]of w)A>y&&(b=_,y=A);this.#n[h]=b}else this.#n[h]=d>0?u/d:0;a[h]={values:c,unique:m,sum:u,count:d}}this.#i=new Array(o).fill(null);let l=0;if(this.#t.encode!==!1)for(let h=0;h<o;h++)if(this.#s[h]==="categorical"){let c=[...a[h].unique].sort((f,u)=>f-u);if(this.#t.encode==="label"||this.#t.encode===!1){let f=new Map;c.forEach((u,d)=>f.set(u,d)),this.#i[h]={type:"label",mapping:f,startIdx:l},l++}else{let f=new Map;c.forEach((u,d)=>f.set(u,l+d)),this.#i[h]={type:"onehot",mapping:f,startIdx:l,size:c.length},l+=c.length}}else l++;else l=o;if(this.#o=l,this.#r=new Array(this.#o).fill(null),this.#t.scale){let h=0;for(let c=0;c<o;c++){if(this.#s[c]==="categorical"&&this.#t.encode!==!1){let u=this.#i[c];h+=u.type==="onehot"?u.size:1;continue}let f=a[c].values;if(this.#t.scale==="standard"){let u=a[c].sum/(a[c].count||1),d=0;for(let p of f)d+=(p-u)**2;d/=f.length||1;let m=Math.sqrt(d);this.#r[h]={mean:u,std:m||1}}else if(this.#t.scale==="minmax"){let u=1/0,d=-1/0;for(let p of f)p<u&&(u=p),p>d&&(d=p);let m=d-u||1;this.#r[h]={min:u,range:m}}h++}}return this.#e=!0,this}transform(t){if(!this.#e)throw new $e("Preprocessor not fitted");let n=Te(t),{data:e,rows:i,cols:r}=n,o=this.#o,a=new Float64Array(i*o);for(let l=0;l<i;l++){let h=0;for(let c=0;c<r;c++){let f=e[l*r+c];if(Number.isNaN(f)&&this.#t.impute!==!1&&(f=this.#n[c]),this.#s[c]==="categorical"&&this.#i[c]){let u=this.#i[c];if(u.type==="onehot"){let d=u.mapping.get(f);d!==void 0&&(a[l*o+d]=1),h=u.startIdx+u.size}else{let d=u.mapping.get(f);a[l*o+h]=d!==void 0?d:-1,h++}}else a[l*o+h]=f,h++}if(this.#t.scale)for(let c=0;c<o;c++){let f=this.#r[c];f&&(this.#t.scale==="standard"?a[l*o+c]=(a[l*o+c]-f.mean)/f.std:this.#t.scale==="minmax"&&(a[l*o+c]=(a[l*o+c]-f.min)/f.range))}}return{data:a,rows:i,cols:o}}fitTransform(t,n){return this.fit(t,n),this.transform(t)}getState(){if(!this.#e)throw new $e("Preprocessor not fitted");return{config:this.#t,colTypes:this.#s,imputeValues:[...this.#n],encodings:this.#i.map(t=>t?{type:t.type,mapping:[...t.mapping.entries()],startIdx:t.startIdx,size:t.size}:null),scaleParams:this.#r,outputCols:this.#o}}static fromState(t){let n=new s(t.config);return n.#s=t.colTypes,n.#n=new Float64Array(t.imputeValues),n.#i=t.encodings.map(e=>e?{type:e.type,mapping:new Map(e.mapping),startIdx:e.startIdx,size:e.size}:null),n.#r=t.scaleParams,n.#o=t.outputCols,n.#e=!0,n}get isFitted(){return this.#e}get outputCols(){return this.#o}get capabilities(){return{transformer:!0}}dispose(){}};De.exports={Preprocessor:Rt}});var Qe=S((gc,Ze)=>{var{NotFittedError:Ve,DisposedError:Ue,ValidationError:J}=z(),{normalizeX:ht}=G(),{encodeBundle:Ye,encodeJSON:Ge,decodeJSON:We}=tt(),{register:Je}=ct(),Ke="wlearn.preprocess.standard_scaler@1",He="wlearn.preprocess.minmax_scaler@1",ut=class s{#t=null;#e=null;#s=!1;#n=!1;#i={};constructor(t={}){this.#i={...t}}fit(t){this.#r();let{rows:n,cols:e,data:i}=ht(t);if(n===0)throw new J("Cannot fit on empty data");let r=new Float64Array(e),o=new Float64Array(e);for(let l=0;l<n;l++){let h=l+1;for(let c=0;c<e;c++){let f=i[l*e+c],u=f-r[c];r[c]+=u/h;let d=f-r[c];o[c]+=u*d}}let a=new Float64Array(e);for(let l=0;l<e;l++)a[l]=n>1?Math.sqrt(o[l]/(n-1)):0;return this.#t=r,this.#e=a,this.#s=!0,this}transform(t){this.#o();let{rows:n,cols:e,data:i}=ht(t);if(e!==this.#t.length)throw new J(`Expected ${this.#t.length} columns, got ${e}`);let r=new Float64Array(n*e);for(let o=0;o<n;o++)for(let a=0;a<e;a++){let l=o*e+a,h=this.#e[a];r[l]=h>0?(i[l]-this.#t[a])/h:0}return{rows:n,cols:e,data:r}}fitTransform(t){return this.fit(t),this.transform(t)}save(){this.#o();let t={means:Array.from(this.#t),stds:Array.from(this.#e)};return Ye({typeId:Ke,params:this.getParams()},[{id:"params",data:Ge(t),mediaType:"application/json"}])}static _fromBundle(t,n,e){let i=n.find(a=>a.id==="params");if(!i)throw new J('Bundle missing "params" artifact');let r=We(e.subarray(i.offset,i.offset+i.length)),o=new s(t.params||{});return o.#t=new Float64Array(r.means),o.#e=new Float64Array(r.stds),o.#s=!0,o}dispose(){this.#n||(this.#n=!0,this.#t=null,this.#e=null,this.#s=!1)}getParams(){return{...this.#i}}setParams(t){return Object.assign(this.#i,t),this}get isFitted(){return this.#s&&!this.#n}#r(){if(this.#n)throw new Ue("StandardScaler has been disposed.")}#o(){if(this.#r(),!this.#s)throw new Ve("StandardScaler is not fitted.")}},dt=class s{#t=null;#e=null;#s=!1;#n=!1;#i={};constructor(t={}){this.#i={...t}}fit(t){this.#r();let{rows:n,cols:e,data:i}=ht(t);if(n===0)throw new J("Cannot fit on empty data");let r=new Float64Array(e).fill(1/0),o=new Float64Array(e).fill(-1/0);for(let a=0;a<n;a++)for(let l=0;l<e;l++){let h=i[a*e+l];h<r[l]&&(r[l]=h),h>o[l]&&(o[l]=h)}return this.#t=r,this.#e=o,this.#s=!0,this}transform(t){this.#o();let{rows:n,cols:e,data:i}=ht(t);if(e!==this.#t.length)throw new J(`Expected ${this.#t.length} columns, got ${e}`);let r=new Float64Array(n*e);for(let o=0;o<n;o++)for(let a=0;a<e;a++){let l=o*e+a,h=this.#e[a]-this.#t[a];r[l]=h>0?(i[l]-this.#t[a])/h:0}return{rows:n,cols:e,data:r}}fitTransform(t){return this.fit(t),this.transform(t)}save(){this.#o();let t={mins:Array.from(this.#t),maxs:Array.from(this.#e)};return Ye({typeId:He,params:this.getParams()},[{id:"params",data:Ge(t),mediaType:"application/json"}])}static _fromBundle(t,n,e){let i=n.find(a=>a.id==="params");if(!i)throw new J('Bundle missing "params" artifact');let r=We(e.subarray(i.offset,i.offset+i.length)),o=new s(t.params||{});return o.#t=new Float64Array(r.mins),o.#e=new Float64Array(r.maxs),o.#s=!0,o}dispose(){this.#n||(this.#n=!0,this.#t=null,this.#e=null,this.#s=!1)}getParams(){return{...this.#i}}setParams(t){return Object.assign(this.#i,t),this}get isFitted(){return this.#s&&!this.#n}#r(){if(this.#n)throw new Ue("MinMaxScaler has been disposed.")}#o(){if(this.#r(),!this.#s)throw new Ve("MinMaxScaler is not fitted.")}};Je(Ke,ut._fromBundle);Je(He,dt._fromBundle);Ze.exports={StandardScaler:ut,MinMaxScaler:dt}});var Mt=S((bc,ts)=>{function Sr(s=42){let t=s|0;return()=>(t=t*1664525+1013904223&2147483647,t/2147483647)}function _r(s,t){for(let n=s.length-1;n>0;n--){let e=t()*(n+1)|0,i=s[n];s[n]=s[e],s[e]=i}return s}ts.exports={makeLCG:Sr,shuffle:_r}});var Lt=S((wc,es)=>{var{ValidationError:D}=z();function X(s,t,n){if(!s||!t||s.length===0||t.length===0)throw new D(`${n}: inputs must be non-empty`);if(s.length!==t.length)throw new D(`${n}: length mismatch (${s.length} vs ${t.length})`)}function K(s,t){let n=new Set;for(let r=0;r<s.length;r++)n.add(s[r]);if(t)for(let r=0;r<t.length;r++)n.add(t[r]);let e=new Int32Array([...n].sort((r,o)=>r-o)),i=new Map;for(let r=0;r<e.length;r++)i.set(e[r],r);return{labels:e,labelMap:i,nClasses:e.length}}function mt(s,t,n,e){let i=new Int32Array(e*e);for(let r=0;r<s.length;r++){let o=n.get(s[r]),a=n.get(t[r]);i[o*e+a]++}return i}function zt(s,t){let n=new Float64Array(t),e=new Float64Array(t),i=new Float64Array(t);for(let r=0;r<t;r++){n[r]=s[r*t+r];for(let o=0;o<t;o++)o!==r&&(e[r]+=s[o*t+r],i[r]+=s[r*t+o])}return{tp:n,fp:e,fn:i}}function vr(s,t){X(s,t,"accuracy");let n=0;for(let e=0;e<s.length;e++)s[e]===t[e]&&n++;return n/s.length}function Fr(s,t){X(s,t,"r2Score");let n=s.length,e=0;for(let o=0;o<n;o++)e+=s[o];e/=n;let i=0,r=0;for(let o=0;o<n;o++){let a=s[o]-e;i+=a*a;let l=s[o]-t[o];r+=l*l}return i===0?0:1-r/i}function Ar(s,t){X(s,t,"meanSquaredError");let n=0;for(let e=0;e<s.length;e++){let i=s[e]-t[e];n+=i*i}return n/s.length}function kr(s,t){X(s,t,"meanAbsoluteError");let n=0;for(let e=0;e<s.length;e++)n+=Math.abs(s[e]-t[e]);return n/s.length}function qr(s,t){X(s,t,"confusionMatrix");let{labels:n,labelMap:e,nClasses:i}=K(s,t);return{matrix:mt(s,t,e,i),labels:n}}function Nt(s,t,n){if(s==="binary"){if(t>2)throw new D('average="binary" requires exactly 2 classes');return"binary"}return s||"binary"}function Er(s,t,{average:n="binary"}={}){X(s,t,"precisionScore");let{labels:e,labelMap:i,nClasses:r}=K(s,t),o=mt(s,t,i,r),{tp:a,fp:l}=zt(o,r),h=Nt(n,r,e);if(h==="binary"){let f=r-1,u=a[f]+l[f];return u===0?0:a[f]/u}if(h==="micro"){let f=0,u=0;for(let d=0;d<r;d++)f+=a[d],u+=l[d];return f+u===0?0:f/(f+u)}let c=0;for(let f=0;f<r;f++){let u=a[f]+l[f];c+=u===0?0:a[f]/u}return c/r}function Ir(s,t,{average:n="binary"}={}){X(s,t,"recallScore");let{labels:e,labelMap:i,nClasses:r}=K(s,t),o=mt(s,t,i,r),{tp:a,fn:l}=zt(o,r),h=Nt(n,r,e);if(h==="binary"){let f=r-1,u=a[f]+l[f];return u===0?0:a[f]/u}if(h==="micro"){let f=0,u=0;for(let d=0;d<r;d++)f+=a[d],u+=l[d];return f+u===0?0:f/(f+u)}let c=0;for(let f=0;f<r;f++){let u=a[f]+l[f];c+=u===0?0:a[f]/u}return c/r}function Pr(s,t,{average:n="binary"}={}){X(s,t,"f1Score");let{labels:e,labelMap:i,nClasses:r}=K(s,t),o=mt(s,t,i,r),{tp:a,fp:l,fn:h}=zt(o,r),c=Nt(n,r,e);function f(d,m,p){let g=d+m===0?0:d/(d+m),w=d+p===0?0:d/(d+p);return g+w===0?0:2*g*w/(g+w)}if(c==="binary"){let d=r-1;return f(a[d],l[d],h[d])}if(c==="micro"){let d=0,m=0,p=0;for(let g=0;g<r;g++)d+=a[g],m+=l[g],p+=h[g];return f(d,m,p)}let u=0;for(let d=0;d<r;d++)u+=f(a[d],l[d],h[d]);return u/r}function Rr(s,t,{nClasses:n,eps:e=1e-15}={}){if(!s||s.length===0)throw new D("logLoss: yTrue must be non-empty");let i=s.length;if(!n){let a=new Set;for(let l=0;l<i;l++)a.add(s[l]);n=a.size}if(t.length!==i*n)throw new D(`logLoss: yProba length (${t.length}) must be n * nClasses (${i*n})`);let{labelMap:r}=K(s),o=0;for(let a=0;a<i;a++){let l=r.get(s[a]),h=t[a*n+l];h=Math.max(e,Math.min(1-e,h)),o-=Math.log(h)}return o/i}function Mr(s,t){if(!s||s.length===0)throw new D("rocAuc: yTrue must be non-empty");if(s.length!==t.length)throw new D("rocAuc: length mismatch");let{labels:n}=K(s);if(n.length!==2)throw new D("rocAuc: requires exactly 2 classes");let e=n[n.length-1],i=s.length,r=Array.from({length:i},(d,m)=>m);r.sort((d,m)=>t[m]-t[d]);let o=0,a=0;for(let d=0;d<i;d++)s[d]===e?o++:a++;if(o===0||a===0)return 0;let l=0,h=0,c=0,f=0,u=0;for(let d=0;d<i;d++){let m=r[d];s[m]===e?l++:h++;let p=l/o,g=h/a;u+=(g-f)*(p+c)/2,c=p,f=g}return u}es.exports={accuracy:vr,r2Score:Fr,meanSquaredError:Ar,meanAbsoluteError:kr,confusionMatrix:qr,precisionScore:Er,recallScore:Ir,f1Score:Pr,logLoss:Rr,rocAuc:Mr}});var cs=S((yc,as)=>{var{ValidationError:U}=z(),{makeLCG:Bt,shuffle:Ot}=Mt(),{normalizeX:zr,normalizeY:Nr}=G(),{accuracy:Lr,r2Score:Br,meanSquaredError:Or,meanAbsoluteError:Cr}=Lt(),ss={accuracy:(s,t)=>Lr(s,t),r2:(s,t)=>Br(s,t),neg_mse:(s,t)=>-Or(s,t),neg_mae:(s,t)=>-Cr(s,t)};function is(s){if(typeof s=="function")return s;let t=ss[s];if(!t)throw new U(`Unknown scoring: "${s}". Available: ${Object.keys(ss).join(", ")}`);return t}function jr(s,t=5,{shuffle:n=!0,seed:e=42}={}){if(s<t)throw new U(`kFold: n (${s}) must be >= k (${t})`);if(t<2)throw new U("kFold: k must be >= 2");let i=Int32Array.from({length:s},(h,c)=>c);if(n){let h=Bt(e);Ot(i,h)}let r=Math.floor(s/t),o=s%t,a=[],l=0;for(let h=0;h<t;h++){let c=r+(h<o?1:0),f=i.slice(l,l+c),u=[];l>0&&u.push(i.slice(0,l)),l+c<s&&u.push(i.slice(l+c));let d=Dr(u);a.push({train:d,test:f}),l+=c}return a}function os(s,t=5,{shuffle:n=!0,seed:e=42}={}){let i=s.length;if(i<t)throw new U(`stratifiedKFold: n (${i}) must be >= k (${t})`);if(t<2)throw new U("stratifiedKFold: k must be >= 2");let r=new Map;for(let h=0;h<i;h++){let c=s[h];r.has(c)||r.set(c,[]),r.get(c).push(h)}if(n){let h=Bt(e);for(let c of r.values())Ot(c,h)}let o=Array.from({length:t},()=>[]);for(let h of r.values())for(let c=0;c<h.length;c++)o[c%t].push(h[c]);let a=Int32Array.from({length:i},(h,c)=>c),l=[];for(let h=0;h<t;h++){let c=new Set(o[h]),f=new Int32Array(o[h]),u=a.filter(d=>!c.has(d));l.push({train:u,test:f})}return l}function Tr(s,{testSize:t=.2,shuffle:n=!0,seed:e=42}={}){if(s<2)throw new U("trainTestSplit: n must be >= 2");let i=Math.max(1,Math.round(s*t)),r=s-i;if(r<1)throw new U("trainTestSplit: testSize too large");let o=Int32Array.from({length:s},(a,l)=>l);if(n){let a=Bt(e);Ot(o,a)}return{train:o.slice(0,r),test:o.slice(r)}}async function $r(s,t,n,{cv:e=5,scoring:i="accuracy",seed:r=42,params:o={}}={}){let a=zr(t),l=Nr(n),h=is(i),c;Array.isArray(e)?c=e:c=os(l,e,{shuffle:!0,seed:r});let f=new Float64Array(c.length);for(let u=0;u<c.length;u++){let{train:d,test:m}=c[u],p=ns(a,d),g=rs(l,d),w=ns(a,m),b=rs(l,m),y=await s.create(o);try{y.fit(p,g);let _=await y.predict(w);f[u]=h(b,_)}finally{y.dispose()}}return f}function Dr(s){let t=0;for(let i of s)t+=i.length;let n=new Int32Array(t),e=0;for(let i of s)n.set(i,e),e+=i.length;return n}function ns(s,t){let{data:n,cols:e}=s,i=t.length,r=new Float64Array(i*e);for(let o=0;o<i;o++){let a=t[o]*e;r.set(n.subarray(a,a+e),o*e)}return{data:r,rows:i,cols:e}}function rs(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}as.exports={kFold:jr,stratifiedKFold:os,trainTestSplit:Tr,crossValScore:$r,getScorer:is}});var hs=S((xc,fs)=>{function ls(s){return s!=null&&typeof s.then=="function"}function Xr(s,t){return ls(s)?s.then(t):t(s)}fs.exports={isPromiseLike:ls,lift:Xr}});var ps=S((Sc,ms)=>{var{normalizeY:Vr}=G(),{round:Ur}=Math;function us(s){let t=Vr(s);if(t instanceof Int32Array)return"classification";let n=new Set;for(let e=0;e<t.length;e++){if(t[e]!==Ur(t[e]))return"regression";n.add(t[e])}return n.size<=20?"classification":"regression"}var ds=new WeakMap;function I(s){let t=ds.get(s);if(!t)throw new Error("Model: invalid instance");return t}function et(s,t){let n=I(s);if(n.disposed)throw new Error(`${t} has been disposed.`);if(!n.inner)throw new Error(`${t}: not fitted`);return n.inner}function Yr(s,t,n={}){let e=n.name||"Model",i=n.load||null,r=s===t;class o{constructor(c,f){ds.set(this,{inner:null,task:c,params:f,disposed:!1})}static async create(c={}){let f={...c},u=f.task||null;delete f.task,i&&await i();let d=new o(u,f),m=I(d);if(u){let p=u==="classification"?s:t;m.inner=await p.create({...f,task:u})}else r&&(m.inner=await s.create(f));return d}static async load(c){try{let f=await s.load(c),u=new o("classification",{}),d=I(u);return d.inner=f,typeof f.getParams=="function"&&(d.params=f.getParams(),d.params.task&&(d.task=d.params.task)),u}catch{let u=await t.load(c),d=new o("regression",{}),m=I(d);return m.inner=u,typeof u.getParams=="function"&&(m.params=u.getParams(),m.params.task&&(m.task=m.params.task)),d}}fit(c,f,u){let d=I(this);if(d.task||(d.task=us(f)),!d.inner){let m=d.task==="classification"?s:t;d.inner=new m({...d.params,task:d.task})}return d.inner.fit(c,f,u),this}predict(c,f){return et(this,e).predict(c,f)}predictProba(c,f){let u=et(this,e);if(typeof u.predictProba!="function")throw new Error(`${e}: predictProba not available`);return u.predictProba(c,f)}score(c,f,u){return et(this,e).score(c,f,u)}save(){return et(this,e).save()}dispose(){let c=I(this);c.inner&&typeof c.inner.dispose=="function"&&c.inner.dispose(),c.inner=null,c.disposed=!0}getParams(){let c=I(this),f=c.inner&&typeof c.inner.getParams=="function"?c.inner.getParams():{...c.params};return c.task&&(f.task=c.task),f}setParams(c){let f=I(this),u={...c};if(u.task){let d=u.task;delete u.task,d!==f.task&&f.inner&&this.dispose(),f.task=d}return f.params=u,f.inner&&typeof f.inner.setParams=="function"&&f.inner.setParams(u),this}get task(){return I(this).task}get isFitted(){let c=I(this);return c.inner?c.inner.isFitted!==void 0?c.inner.isFitted:!0:!1}get classes(){let c=I(this);return c.inner?typeof c.inner.classes=="function"?c.inner.classes():c.inner.classes!==void 0?c.inner.classes:new Int32Array(0):new Int32Array(0)}get capabilities(){let c=I(this);return c.inner&&c.inner.capabilities!==void 0?c.inner.capabilities:{}}}let a=new Set(["constructor","fit","predict","predictProba","score","save","dispose","getParams","setParams"]),l=new Set(["classes","task","isFitted","capabilities"]);for(let h of[s,t])if(!(!h||!h.prototype))for(let c of Object.getOwnPropertyNames(h.prototype)){if(c.startsWith("_")||c.startsWith("#")||a.has(c)||l.has(c)||c in o.prototype)continue;let f=Object.getOwnPropertyDescriptor(h.prototype,c);f&&(typeof f.value=="function"?o.prototype[c]=function(...u){return et(this,e)[c](...u)}:f.get&&Object.defineProperty(o.prototype,c,{get(){let u=I(this);if(u.inner)return u.inner[c]},configurable:!0}))}return(s.defaultSearchSpace||t.defaultSearchSpace)&&(o.defaultSearchSpace=()=>s.defaultSearchSpace?.()||t.defaultSearchSpace?.()||{}),(s.budgetSpec||t.budgetSpec)&&(o.budgetSpec=()=>s.budgetSpec?.()||t.budgetSpec?.()||void 0),Object.defineProperty(o,"name",{value:e,configurable:!0}),o}ms.exports={createModelClass:Yr,detectTask:us}});var q=S((_c,gs)=>{var{WlearnError:Gr,BundleError:Wr,RegistryError:Jr,ValidationError:Kr,NotFittedError:Hr,DisposedError:Zr}=z(),{normalizeX:Qr,normalizeY:ti,makeDense:ei,validateMatrix:si}=G(),{sha256Sync:ni}=kt(),{encodeBundle:ri,decodeBundle:ii,validateBundle:oi,encodeJSON:ai,decodeJSON:ci}=tt(),{register:li,load:fi,loadSync:hi,getRegistry:ui}=ct(),{Pipeline:di}=je(),{Step:mi}=Pt(),{Preprocessor:pi}=Xe(),{StandardScaler:gi,MinMaxScaler:bi}=Qe(),{makeLCG:wi,shuffle:yi}=Mt(),{accuracy:xi,r2Score:Si,meanSquaredError:_i,meanAbsoluteError:vi,confusionMatrix:Fi,precisionScore:Ai,recallScore:ki,f1Score:qi,logLoss:Ei,rocAuc:Ii}=Lt(),{kFold:Pi,stratifiedKFold:Ri,trainTestSplit:Mi,crossValScore:zi,getScorer:Ni}=cs(),{isPromiseLike:Li,lift:Bi}=hs(),{createModelClass:Oi,detectTask:Ci}=ps();gs.exports={WlearnError:Gr,BundleError:Wr,RegistryError:Jr,ValidationError:Kr,NotFittedError:Hr,DisposedError:Zr,normalizeX:Qr,normalizeY:ti,makeDense:ei,validateMatrix:si,sha256Sync:ni,encodeBundle:ri,decodeBundle:ii,validateBundle:oi,encodeJSON:ai,decodeJSON:ci,register:li,load:fi,loadSync:hi,getRegistry:ui,Pipeline:di,Step:mi,Preprocessor:pi,StandardScaler:gi,MinMaxScaler:bi,makeLCG:wi,shuffle:yi,accuracy:xi,r2Score:Si,meanSquaredError:_i,meanAbsoluteError:vi,confusionMatrix:Fi,precisionScore:Ai,recallScore:ki,f1Score:qi,logLoss:Ei,rocAuc:Ii,kFold:Pi,stratifiedKFold:Ri,trainTestSplit:Mi,crossValScore:zi,getScorer:Ni,isPromiseLike:Li,lift:Bi,createModelClass:Oi,detectTask:Ci}});var st=S((Fc,ys)=>{var{makeLCG:ji}=q(),{floor:Ct,round:jt,log:B,exp:gt,min:vc,max:pt}=Math;function Tt(s,t){let{type:n}=s;switch(n){case"categorical":return s.values[Ct(t()*s.values.length)];case"uniform":return s.low+t()*(s.high-s.low);case"log_uniform":return gt(B(s.low)+t()*(B(s.high)-B(s.low)));case"int_uniform":return s.low+Ct(t()*(s.high-s.low+1));case"int_log_uniform":return jt(gt(B(s.low)+t()*(B(s.high)-B(s.low))));default:throw new Error(`Unknown SearchParam type: "${n}"`)}}function ws(s,t){let n={},e=Object.keys(s);for(let i of e)s[i].condition||(n[i]=Tt(s[i],t));for(let i of e){let{condition:r}=s[i];if(!r)continue;let o=!0;for(let[a,l]of Object.entries(r))if(n[a]!==l){o=!1;break}o&&(n[i]=Tt(s[i],t))}return n}function Ti(s,t,{seed:n=42}={}){let e=ji(n),i=[];for(let r=0;r<t;r++)i.push(ws(s,e));return i}function $i(s,{steps:t=5}={}){let n=Object.keys(s);if(n.length===0)return[{}];let e=n.filter(a=>!s[a].condition),i=n.filter(a=>s[a].condition),r=e.map(a=>bs(s[a],t)),o=[{}];for(let a=0;a<e.length;a++){let l=e[a],h=r[a],c=[];for(let f of o)for(let u of h)c.push({...f,[l]:u});o=c}for(let a of o)for(let l of i){let{condition:h}=s[l],c=!0;for(let[f,u]of Object.entries(h))if(a[f]!==u){c=!1;break}if(c){let f=bs(s[l],t);a[l]=f[Ct(f.length/2)]}}return o}function bs(s,t){let{type:n}=s;switch(n){case"categorical":return[...s.values];case"uniform":{let e=[];for(let i=0;i<t;i++)e.push(s.low+(s.high-s.low)*i/pt(1,t-1));return e}case"log_uniform":{let e=B(s.low),i=B(s.high),r=[];for(let o=0;o<t;o++)r.push(gt(e+(i-e)*o/pt(1,t-1)));return r}case"int_uniform":{if(s.high-s.low+1<=t){let r=[];for(let o=s.low;o<=s.high;o++)r.push(o);return r}let i=[];for(let r=0;r<t;r++)i.push(s.low+jt((s.high-s.low)*r/pt(1,t-1)));return[...new Set(i)].sort((r,o)=>r-o)}case"int_log_uniform":{let e=B(s.low),i=B(s.high),r=[];for(let o=0;o<t;o++)r.push(jt(gt(e+(i-e)*o/pt(1,t-1))));return[...new Set(r)].sort((o,a)=>o-a)}default:throw new Error(`Unknown SearchParam type: "${n}"`)}}ys.exports={sampleParam:Tt,sampleConfig:ws,randomConfigs:Ti,gridConfigs:$i}});var Dt=S((Ac,xs)=>{var $t=class s{#t=[];#e=0;#s=!0;add({modelName:t,params:n,scores:e,fitTimeMs:i}){let r=0;for(let c=0;c<e.length;c++)r+=e[c];let o=r/e.length,a=0;for(let c=0;c<e.length;c++){let f=e[c]-o;a+=f*f}let l=Math.sqrt(a/e.length),h={id:this.#e++,modelName:t,params:n,scores:e,meanScore:o,stdScore:l,fitTimeMs:i,rank:0};return this.#t.push(h),this.#s=!0,h}ranked(){if(this.#s){this.#t.sort((t,n)=>n.meanScore-t.meanScore);for(let t=0;t<this.#t.length;t++)this.#t[t].rank=t+1;this.#s=!1}return this.#t.slice()}best(){return this.#t.length===0?null:(this.ranked(),this.#t[0])}top(t){return this.ranked().slice(0,t)}toJSON(){return this.ranked().map(t=>({id:t.id,modelName:t.modelName,params:t.params,scores:[...t.scores],meanScore:t.meanScore,stdScore:t.stdScore,fitTimeMs:t.fitTimeMs,rank:t.rank}))}static fromJSON(t){let n=new s;for(let e of t)n.#t.push({...e,scores:new Float64Array(e.scores)}),e.id>=n.#e&&(n.#e=e.id+1);return n.#s=!0,n}get length(){return this.#t.length}};xs.exports={Leaderboard:$t}});var M=S((qc,Ss)=>{var{makeLCG:kc}=q(),{round:Di}=Math;function Xi(s){if(s instanceof Int32Array)return"classification";let t=new Set;for(let n=0;n<s.length;n++){if(s[n]!==Di(s[n]))return"regression";t.add(s[n])}return t.size<=20?"classification":"regression"}function Vi(){return typeof performance<"u"?performance.now():Date.now()}function Xt(s){return s==null?String(s):typeof s=="number"?s.toString():typeof s=="string"?JSON.stringify(s):typeof s=="boolean"?String(s):Array.isArray(s)?"["+s.map(Xt).join(",")+"]":typeof s=="object"?"{"+Object.keys(s).sort().map(n=>JSON.stringify(n)+":"+Xt(s[n])).join(",")+"}":String(s)}function Ui(s,t){return s+":"+Xt(t)}function Yi(s){let t=2166136261;for(let n=0;n<s.length;n++)t^=s.charCodeAt(n),t=t*16777619&2147483647;return t}function Gi(s,t,n){let e=Yi(s),i=n*2654435761+e*40503+t*65537&2147483647;return i=(i>>>16^i)*73244475&2147483647,i}function Wi(s,t,n){let e=s.length,i=Math.min(t,e);for(let r=0;r<i;r++){let o=r+(n()*(e-r)|0),a=s[r];s[r]=s[o],s[o]=a}return s.subarray?s.subarray(0,i):s.slice(0,i)}function Ji(s){if(typeof s=="function")return!0;switch(s){case"accuracy":case"r2":case"neg_mse":case"neg_mae":return!0;default:return!0}}Ss.exports={detectTask:Xi,now:Vi,makeCandidateId:Ui,seedFor:Gi,partialShuffle:Wi,scorerGreaterIsBetter:Ji}});var H=S((Rc,Fs)=>{var{normalizeX:Ec,normalizeY:Ic,makeLCG:Ki,getScorer:Hi}=q(),{Leaderboard:Zi}=Dt(),{now:nt,seedFor:Qi,partialShuffle:to}=M(),{ceil:eo,min:Pc}=Math;function _s(s,t){let{data:n,cols:e}=s,i=t.length,r=new Float64Array(i*e);for(let o=0;o<i;o++){let a=t[o]*e;r.set(n.subarray(a,a+e),o*e)}return{data:r,rows:i,cols:e}}function vs(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}var Vt=class{#t;#e;#s;#n;#i;#r;#o;#l;#a;constructor({folds:t,scoring:n,X:e,y:i,timeLimitMs:r=0,seed:o=42,onProgress:a}){this.#t=t,this.#e=Hi(n),this.#s=e,this.#n=i,this.#i=r,this.#r=o,this.#o=nt(),this.#l=new Zi,this.#a=a||null}get leaderboard(){return this.#l}get isTimedOut(){return this.#i<=0?!1:nt()-this.#o>this.#i}async evaluateCandidate({candidateId:t,cls:n,params:e,budget:i}){let r=this.#t,o=new Float64Array(r.length),a=nt(),l=0,h=this.#c(n,e,i);for(let u=0;u<r.length;u++){let{train:d,test:m}=r[u];i&&i.type==="subsample"&&(d=this.#f(d,i.value,t,u)),l+=d.length;let p=_s(this.#s,d),g=vs(this.#n,d),w=_s(this.#s,m),b=vs(this.#n,m),y=await n.create(h);try{y.fit(p,g);let _=await y.predict(w);o[u]=this.#e(b,_)}finally{y.dispose()}}let c=nt()-a,f=this.#l.add({modelName:t.split(":")[0],params:e,scores:o,fitTimeMs:c});return{candidateId:t,meanScore:f.meanScore,foldScores:o,stdScore:f.stdScore,fitTimeMs:c,nTrainUsed:Math.round(l/r.length),nTest:r[0].test.length}}#c(t,n,e){if(!e||e.type!=="rounds")return n;let i=t.budgetSpec?.();return!i||!i.roundsParam||n[i.roundsParam]!==void 0?n:{...n,[i.roundsParam]:e.value}}#f(t,n,e,i){let r=Math.max(1,eo(t.length*n));if(r>=t.length)return t;let o=new Int32Array(t),a=Qi(e,i,this.#r),l=Ki(a);return to(o,r,l)}async runStrategy(t){let n=0;for(;!t.isDone()&&!this.isTimedOut;){let e=t.next();if(e===null)break;try{let i=await this.evaluateCandidate(e);if(t.report(i),n++,this.#a){let r=this.#l.best();this.#a({phase:"search",candidatesDone:n,bestScore:r?r.meanScore:null,bestModel:r?r.modelName:null,lastCandidate:{model:i.candidateId.split(":")[0],score:i.meanScore,timeMs:i.fitTimeMs},elapsedMs:nt()-this.#o})}}catch{n++}}return{leaderboard:this.#l}}};Fs.exports={Executor:Vt}});var Yt=S((Mc,ks)=>{var{makeLCG:As}=q(),{sampleConfig:so}=st(),{makeCandidateId:no}=M(),Ut=class{#t=[];#e=0;#s=0;constructor(t,{nIter:n=20,seed:e=42}={}){let i=As(e);for(let r of t){let a={...r.searchSpace||r.cls.defaultSearchSpace?.()||{}};if(r.params)for(let h of Object.keys(r.params))delete a[h];let l=As(i()*2147483647|0);for(let h=0;h<n;h++){let f={...so(a,l),...r.params||{}},u=no(r.name,f);this.#t.push({candidateId:u,cls:r.cls,params:f})}}this.#s=this.#t.length}next(){return this.#e>=this.#s?null:this.#t[this.#e++]}report(t){}isDone(){return this.#e>=this.#s}};ks.exports={RandomStrategy:Ut}});var Jt=S((Nc,Is)=>{var{stratifiedKFold:ro,kFold:io,normalizeX:qs,normalizeY:Es,ValidationError:Gt}=q(),{Executor:oo}=H(),{RandomStrategy:ao}=Yt(),{detectTask:co,scorerGreaterIsBetter:zc}=M(),Wt=class{#t;#e;#s=null;#n=null;constructor(t,n={}){if(!t||t.length===0)throw new Gt("RandomSearch: at least one model is required");this.#t=t,this.#e={scoring:null,cv:5,seed:42,task:null,nIter:20,maxTimeMs:0,onProgress:null,...n}}async fit(t,n){let e=qs(t),i=Es(n),r=this.#e.task||co(i),o=this.#e.scoring||(r==="classification"?"accuracy":"r2"),{cv:a,seed:l,nIter:h,maxTimeMs:c,onProgress:f}=this.#e,u=r==="classification"?ro(i,a,{shuffle:!0,seed:l}):io(i.length,a,{shuffle:!0,seed:l}),d=new oo({folds:u,scoring:o,X:e,y:i,timeLimitMs:c,seed:l,onProgress:f}),m=new ao(this.#t,{nIter:h,seed:l}),{leaderboard:p}=await d.runStrategy(m);if(p.length===0)throw new Gt("RandomSearch: no candidates were evaluated");return this.#s=p,this.#n=p.best(),{leaderboard:p,bestResult:this.#n}}async refitBest(t,n){if(!this.#n)throw new Gt("RandomSearch: must call fit() first");let e=this.#n,r=await this.#t.find(l=>l.name===e.modelName).cls.create(e.params),o=qs(t),a=Es(n);return r.fit(o,a),r}get leaderboard(){return this.#s}get bestResult(){return this.#n}};Is.exports={RandomSearch:Wt}});var Qt=S((Lc,zs)=>{var{makeLCG:Ps}=q(),{sampleConfig:lo}=st(),{makeCandidateId:fo}=M(),{ceil:Rs,log:Ms,max:Kt,min:bt,floor:Ht}=Math,Zt=class{#t;#e=0;#s=0;#n;#i;#r;#o;#l;#a=[];#c=[];#f=!1;#h=!1;constructor(t,{nIter:n=20,seed:e=42,factor:i=3,nSamples:r,greaterIsBetter:o=!0,cv:a=5}={}){this.#i=i,this.#r=r||0,this.#l=o;let l=Ps(e),h=[];for(let c of t){let u={...c.searchSpace||c.cls.defaultSearchSpace?.()||{}};if(c.params)for(let m of Object.keys(c.params))delete u[m];let d=Ps(l()*2147483647|0);for(let m=0;m<n;m++){let g={...lo(u,d),...c.params||{}},w=fo(c.name,g);h.push({candidateId:w,cls:c.cls,params:g})}}this.#t=h,this.#n=Kt(1,Rs(Ms(h.length)/Ms(i))),this.#o=Kt(a*2,Ht(this.#r/i**this.#n))}next(){if(this.#f||this.#e>=this.#t.length)return null;let t=this.#t[this.#e++];if(!this.#h){let n=bt(this.#r,Ht(this.#o*this.#i**this.#s)),e=bt(1,n/this.#r);if(e<1)return{...t,budget:{type:"subsample",value:e}}}return t}report(t){if(this.#a.push(t),this.#a.length<this.#t.length)return;if(this.#h){this.#f=!0;return}let n=bt(this.#r,Ht(this.#o*this.#i**this.#s)),e=bt(1,n/this.#r),i=[...this.#a];this.#l?i.sort((a,l)=>l.meanScore-a.meanScore):i.sort((a,l)=>a.meanScore-l.meanScore);let r=Kt(1,Rs(i.length/this.#i));this.#c.push({round:this.#s,nResources:n,fraction:e,nCandidates:this.#a.length,nSurvivors:r});let o=new Set(i.slice(0,r).map(a=>a.candidateId));this.#t=this.#t.filter(a=>o.has(a.candidateId)),this.#s++,this.#e=0,this.#a=[],(this.#t.length<=1||this.#s>=this.#n)&&(this.#h=!0)}isDone(){return this.#f}get rounds(){return this.#c}};zs.exports={HalvingStrategy:Zt}});var ee=S((Bc,Os)=>{var{stratifiedKFold:ho,kFold:uo,normalizeX:Ns,normalizeY:Ls,ValidationError:Bs}=q(),{Executor:mo}=H(),{HalvingStrategy:po}=Qt(),{detectTask:go,scorerGreaterIsBetter:bo}=M(),te=class{#t;#e;#s=null;#n=null;#i=null;constructor(t,n={}){if(!t||t.length===0)throw new Bs("SuccessiveHalvingSearch: at least one model is required");this.#t=t,this.#e={scoring:null,cv:5,seed:42,task:null,nIter:20,maxTimeMs:0,factor:3,minResources:0,onProgress:null,...n}}async fit(t,n){let e=Ns(t),i=Ls(n),r=e.rows,o=this.#e.task||go(i),a=this.#e.scoring||(o==="classification"?"accuracy":"r2"),l=bo(a),{cv:h,seed:c,nIter:f,maxTimeMs:u,factor:d,onProgress:m}=this.#e,p=o==="classification"?ho(i,h,{shuffle:!0,seed:c}):uo(r,h,{shuffle:!0,seed:c}),g=new mo({folds:p,scoring:a,X:e,y:i,timeLimitMs:u,seed:c,onProgress:m}),w=new po(this.#t,{nIter:f,seed:c,factor:d,nSamples:r,greaterIsBetter:l,cv:h}),{leaderboard:b}=await g.runStrategy(w);return this.#s=b,this.#n=b.best(),this.#i=w.rounds,{leaderboard:b,bestResult:this.#n,rounds:this.#i}}async refitBest(t,n){if(!this.#n)throw new Bs("SuccessiveHalvingSearch: must call fit() first");let e=this.#n,r=await this.#t.find(l=>l.name===e.modelName).cls.create(e.params),o=Ns(t),a=Ls(n);return r.fit(o,a),r}get leaderboard(){return this.#s}get bestResult(){return this.#n}get rounds(){return this.#i}};Os.exports={SuccessiveHalvingSearch:te}});var ie=S((Oc,$s)=>{var{stratifiedKFold:wo,kFold:yo,normalizeX:Cs,normalizeY:js,ValidationError:se}=q(),{Executor:xo}=H(),{detectTask:So,makeCandidateId:_o}=M(),ne={classification:{xgb:[{objective:"multi:softprob",eta:.05,max_depth:6,numRound:200,subsample:.8,colsample_bytree:.8,min_child_weight:1,lambda:1,alpha:0},{objective:"multi:softprob",eta:.01,max_depth:10,numRound:500,subsample:.7,colsample_bytree:.65,min_child_weight:.6,lambda:.1,alpha:0},{objective:"multi:softprob",eta:.1,max_depth:3,numRound:100,subsample:.9,colsample_bytree:.9,min_child_weight:1,lambda:1,alpha:0},{objective:"multi:softprob",eta:.03,max_depth:7,numRound:300,subsample:.8,colsample_bytree:.7,min_child_weight:1,lambda:5,alpha:1},{objective:"multi:softprob",eta:.02,max_depth:8,numRound:400,subsample:.8,colsample_bytree:.8,min_child_weight:.8,lambda:.1,alpha:0},{objective:"multi:softprob",eta:.08,max_depth:4,numRound:150,subsample:.85,colsample_bytree:.55,min_child_weight:1,lambda:1,alpha:.1},{objective:"multi:softprob",eta:.015,max_depth:9,numRound:350,subsample:.75,colsample_bytree:.55,min_child_weight:.9,lambda:.5,alpha:0},{objective:"multi:softprob",eta:.3,max_depth:3,numRound:50,subsample:.9,colsample_bytree:.9,min_child_weight:1,lambda:1,alpha:0},{objective:"multi:softprob",num_parallel_tree:100,numRound:1,subsample:.8,colsample_bynode:.8,learning_rate:1},{objective:"multi:softprob",num_parallel_tree:200,numRound:1,subsample:.7,colsample_bynode:.6,learning_rate:1}],lgb:[{objective:"multiclass",learning_rate:.05,max_depth:6,numRound:200,num_leaves:63,subsample:.8,colsample_bytree:.8,min_child_weight:1,reg_lambda:1,reg_alpha:0,verbosity:-1},{objective:"multiclass",learning_rate:.01,max_depth:-1,numRound:500,num_leaves:127,subsample:.7,colsample_bytree:.65,reg_lambda:.1,reg_alpha:0,verbosity:-1},{objective:"multiclass",learning_rate:.1,max_depth:4,numRound:100,num_leaves:15,subsample:.9,colsample_bytree:.9,reg_lambda:1,reg_alpha:0,verbosity:-1},{objective:"multiclass",learning_rate:.05,numRound:200,num_leaves:63,subsample:.8,colsample_bytree:.8,extra_trees:!0,reg_lambda:1,reg_alpha:0,verbosity:-1},{objective:"multiclass",learning_rate:.03,max_depth:7,numRound:300,num_leaves:63,subsample:.8,colsample_bytree:.7,reg_lambda:5,reg_alpha:1,verbosity:-1},{objective:"multiclass",learning_rate:.01,max_depth:8,numRound:500,num_leaves:95,subsample:.75,colsample_bytree:.55,reg_lambda:.5,reg_alpha:0,verbosity:-1}],ebm:[{objective:"classification",learningRate:.01,maxRounds:500,maxLeaves:3,maxBins:256},{objective:"classification",learningRate:.01,maxRounds:500,maxLeaves:4,maxInteractions:15,maxBins:256},{objective:"classification",learningRate:.05,maxRounds:300,maxLeaves:3,maxBins:128},{objective:"classification",learningRate:.005,maxRounds:800,maxLeaves:5,maxBins:512}],linear:[{solver:0,C:1},{solver:0,C:10},{solver:7,C:1},{solver:6,C:.1}],svm:[{svmType:0,kernel:2,C:1,gamma:0,probability:1},{svmType:0,kernel:2,C:10,gamma:.01,probability:1},{svmType:0,kernel:1,C:1,degree:3,gamma:0,probability:1},{svmType:0,kernel:0,C:1,probability:1}],knn:[{k:5,metric:"l2",task:"classification"},{k:15,metric:"l2",task:"classification"},{k:3,metric:"l1",task:"classification"}],tsetlin:[{task:"classification",nClauses:100,threshold:50,s:3,nEpochs:100},{task:"classification",nClauses:500,threshold:100,s:5,nEpochs:100},{task:"classification",nClauses:50,threshold:25,s:2,nEpochs:60}],rf:[{nEstimators:100,maxDepth:10,maxFeatures:"sqrt",criterion:"gini",minSamplesSplit:2,minSamplesLeaf:1},{nEstimators:300,maxDepth:0,maxFeatures:"log2",criterion:"gini",minSamplesSplit:5,minSamplesLeaf:2},{nEstimators:200,maxDepth:15,maxFeatures:"sqrt",criterion:"entropy",extraTrees:1,minSamplesSplit:2},{nEstimators:200,maxDepth:12,maxFeatures:"sqrt",criterion:"hellinger",minSamplesSplit:2,minSamplesLeaf:1},{nEstimators:150,maxDepth:10,maxFeatures:"sqrt",criterion:"gini",heterogeneous:1,oobWeighting:1,minSamplesLeaf:2},{nEstimators:200,maxDepth:10,maxFeatures:"sqrt",criterion:"gini",histogramBinning:1,minSamplesSplit:2,minSamplesLeaf:1},{nEstimators:150,maxDepth:12,maxFeatures:"sqrt",criterion:"gini",jarf:1,minSamplesSplit:2,minSamplesLeaf:1}],mlp:[{hidden_sizes:[64],activation:"relu",lr:.01,epochs:50,optimizer:"adam",batch_size:32},{hidden_sizes:[128,64],activation:"gelu",lr:.001,epochs:100,optimizer:"adam",batch_size:32},{hidden_sizes:[256,128],activation:"silu",lr:.001,epochs:150,optimizer:"adam",batch_size:16}],tabm:[{hidden_sizes:[128],activation:"relu",n_ensemble:32,lr:.005,epochs:100,optimizer:"adam"},{hidden_sizes:[64],activation:"gelu",n_ensemble:8,lr:.01,epochs:50,optimizer:"adam"},{hidden_sizes:[128,64],activation:"silu",n_ensemble:16,lr:.001,epochs:150,optimizer:"adam"}],nam:[{hidden_sizes:[64],activation:"exu",lr:.01,epochs:100,optimizer:"adam"},{hidden_sizes:[128],activation:"relu",lr:.001,epochs:100,optimizer:"adam"},{hidden_sizes:[64,32],activation:"exu",lr:.005,epochs:150,optimizer:"adam"}],gam:[{family:"binomial",penalty:"elasticnet",alpha:.5,nLambda:100,nFolds:5},{family:"binomial",penalty:"lasso",alpha:1,nLambda:100,nFolds:5},{family:"binomial",penalty:"ridge",alpha:0,nLambda:100,nFolds:5},{family:"binomial",penalty:"scad",nLambda:100,nFolds:5}],bart:[{numTrees:200,numBurnin:200,numSamples:100,alpha:.95,beta:2},{numTrees:500,numBurnin:300,numSamples:100,alpha:.95,beta:2},{numTrees:100,maxDepth:5,numBurnin:100,numSamples:100,alpha:.8,beta:1}],fm:[{k:4,lr:.01,epoch:10,opt:"adagrad"},{k:8,lr:.005,epoch:20,opt:"adagrad",lambda:.001}],xlr:[{lr:.01,opt:"ftrl",epoch:10},{lr:.01,lambda:.1,opt:"adagrad",epoch:20}]},regression:{xgb:[{objective:"reg:squarederror",eta:.05,max_depth:6,numRound:200,subsample:.8,colsample_bytree:.8,min_child_weight:1,lambda:1,alpha:0},{objective:"reg:squarederror",eta:.01,max_depth:10,numRound:500,subsample:.7,colsample_bytree:.65,min_child_weight:.6,lambda:.1,alpha:0},{objective:"reg:squarederror",eta:.1,max_depth:3,numRound:100,subsample:.9,colsample_bytree:.9,min_child_weight:1,lambda:1,alpha:0},{objective:"reg:squarederror",eta:.03,max_depth:7,numRound:300,subsample:.8,colsample_bytree:.7,min_child_weight:1,lambda:5,alpha:1},{objective:"reg:squarederror",eta:.02,max_depth:8,numRound:400,subsample:.8,colsample_bytree:.8,min_child_weight:.8,lambda:.1,alpha:0},{objective:"reg:squarederror",eta:.08,max_depth:4,numRound:150,subsample:.85,colsample_bytree:.55,min_child_weight:1,lambda:1,alpha:.1},{objective:"reg:squarederror",eta:.015,max_depth:9,numRound:350,subsample:.75,colsample_bytree:.55,min_child_weight:.9,lambda:.5,alpha:0},{objective:"reg:squarederror",eta:.3,max_depth:3,numRound:50,subsample:.9,colsample_bytree:.9,min_child_weight:1,lambda:1,alpha:0},{objective:"reg:squarederror",num_parallel_tree:100,numRound:1,subsample:.8,colsample_bynode:.8,learning_rate:1},{objective:"reg:squarederror",num_parallel_tree:200,numRound:1,subsample:.7,colsample_bynode:.6,learning_rate:1}],lgb:[{objective:"regression",learning_rate:.05,max_depth:6,numRound:200,num_leaves:63,subsample:.8,colsample_bytree:.8,min_child_weight:1,reg_lambda:1,reg_alpha:0,verbosity:-1},{objective:"regression",learning_rate:.01,max_depth:-1,numRound:500,num_leaves:127,subsample:.7,colsample_bytree:.65,reg_lambda:.1,reg_alpha:0,verbosity:-1},{objective:"regression",learning_rate:.1,max_depth:4,numRound:100,num_leaves:15,subsample:.9,colsample_bytree:.9,reg_lambda:1,reg_alpha:0,verbosity:-1},{objective:"regression",learning_rate:.05,numRound:200,num_leaves:63,subsample:.8,colsample_bytree:.8,extra_trees:!0,reg_lambda:1,reg_alpha:0,verbosity:-1},{objective:"regression",learning_rate:.03,max_depth:7,numRound:300,num_leaves:63,subsample:.8,colsample_bytree:.7,reg_lambda:5,reg_alpha:1,verbosity:-1},{objective:"regression",learning_rate:.01,max_depth:8,numRound:500,num_leaves:95,subsample:.75,colsample_bytree:.55,reg_lambda:.5,reg_alpha:0,verbosity:-1}],ebm:[{objective:"regression",learningRate:.01,maxRounds:500,maxLeaves:3,maxBins:256},{objective:"regression",learningRate:.01,maxRounds:500,maxLeaves:4,maxInteractions:15,maxBins:256},{objective:"regression",learningRate:.05,maxRounds:300,maxLeaves:3,maxBins:128},{objective:"regression",learningRate:.005,maxRounds:800,maxLeaves:5,maxBins:512}],linear:[{solver:11,C:1},{solver:11,C:10},{solver:12,C:1},{solver:13,C:.1}],svm:[{svmType:3,kernel:2,C:1,gamma:0},{svmType:3,kernel:2,C:10,gamma:.01},{svmType:3,kernel:1,C:1,degree:3,gamma:0},{svmType:3,kernel:0,C:1}],knn:[{k:5,metric:"l2",task:"regression"},{k:15,metric:"l2",task:"regression"},{k:3,metric:"l1",task:"regression"}],tsetlin:[{task:"regression",nClauses:100,threshold:50,s:3,nEpochs:100},{task:"regression",nClauses:500,threshold:100,s:5,nEpochs:100},{task:"regression",nClauses:50,threshold:25,s:2,nEpochs:60}],rf:[{nEstimators:100,maxDepth:10,maxFeatures:"sqrt",criterion:"mse",minSamplesSplit:2,minSamplesLeaf:1},{nEstimators:300,maxDepth:0,maxFeatures:"log2",criterion:"mse",minSamplesSplit:5,minSamplesLeaf:2},{nEstimators:200,maxDepth:15,maxFeatures:"sqrt",criterion:"mae",extraTrees:1,minSamplesSplit:2},{nEstimators:100,maxDepth:10,maxFeatures:"sqrt",criterion:"mse",leafModel:1,minSamplesLeaf:5},{nEstimators:150,maxDepth:10,maxFeatures:"sqrt",criterion:"mse",heterogeneous:1,oobWeighting:1,minSamplesLeaf:2},{nEstimators:200,maxDepth:10,maxFeatures:"sqrt",criterion:"mse",histogramBinning:1,minSamplesSplit:2,minSamplesLeaf:1},{nEstimators:150,maxDepth:12,maxFeatures:"sqrt",criterion:"mse",jarf:1,minSamplesSplit:2,minSamplesLeaf:1}],mlp:[{hidden_sizes:[64],activation:"relu",lr:.01,epochs:50,optimizer:"adam",batch_size:32},{hidden_sizes:[128,64],activation:"gelu",lr:.001,epochs:100,optimizer:"adam",batch_size:32},{hidden_sizes:[256,128],activation:"silu",lr:.001,epochs:150,optimizer:"adam",batch_size:16}],tabm:[{hidden_sizes:[128],activation:"relu",n_ensemble:32,lr:.005,epochs:100,optimizer:"adam"},{hidden_sizes:[64],activation:"gelu",n_ensemble:8,lr:.01,epochs:50,optimizer:"adam"},{hidden_sizes:[128,64],activation:"silu",n_ensemble:16,lr:.001,epochs:150,optimizer:"adam"}],nam:[{hidden_sizes:[64],activation:"exu",lr:.01,epochs:100,optimizer:"adam"},{hidden_sizes:[128],activation:"relu",lr:.001,epochs:100,optimizer:"adam"},{hidden_sizes:[64,32],activation:"exu",lr:.005,epochs:150,optimizer:"adam"}],gam:[{family:"gaussian",penalty:"elasticnet",alpha:.5,nLambda:100,nFolds:5},{family:"gaussian",penalty:"lasso",alpha:1,nLambda:100,nFolds:5},{family:"gaussian",penalty:"ridge",alpha:0,nLambda:100,nFolds:5},{family:"gaussian",penalty:"scad",nLambda:100,nFolds:5}],bart:[{numTrees:200,numBurnin:200,numSamples:100,alpha:.95,beta:2},{numTrees:500,numBurnin:300,numSamples:100,alpha:.95,beta:2},{numTrees:100,maxDepth:5,numBurnin:100,numSamples:100,alpha:.8,beta:1}],fm:[{k:4,lr:.01,epoch:10,opt:"adagrad"},{k:8,lr:.005,epoch:20,opt:"adagrad",lambda:.001}],xlr:[{lr:.01,opt:"ftrl",epoch:10},{lr:.01,lambda:.1,opt:"adagrad",epoch:20}]}};function Ts(s="classification"){return ne[s]||ne.classification}var wt=class{#t=[];#e=0;#s=0;constructor(t,{task:n="classification",seed:e=42}={}){let i=Ts(n);for(let r of t){let o=r.name,a=r.cls,l=r.params||{},h=i[o]||[{}];for(let c of h){let f={...c,...l},u=_o(o,f);this.#t.push({candidateId:u,cls:a,params:f})}}this.#s=this.#t.length}next(){return this.#e>=this.#s?null:this.#t[this.#e++]}report(t){}isDone(){return this.#e>=this.#s}},re=class{#t;#e;#s=null;#n=null;constructor(t,n={}){if(!t||t.length===0)throw new se("PortfolioSearch: at least one model is required");this.#t=t,this.#e={scoring:null,cv:5,seed:42,task:null,maxTimeMs:0,onProgress:null,...n}}async fit(t,n){let e=Cs(t),i=js(n),r=this.#e.task||So(i),o=this.#e.scoring||(r==="classification"?"accuracy":"r2"),{cv:a,seed:l,maxTimeMs:h,onProgress:c}=this.#e,f=r==="classification"?wo(i,a,{shuffle:!0,seed:l}):yo(i.length,a,{shuffle:!0,seed:l}),u=new xo({folds:f,scoring:o,X:e,y:i,timeLimitMs:h,seed:l,onProgress:c}),d=new wt(this.#t,{task:r,seed:l}),{leaderboard:m}=await u.runStrategy(d);if(m.length===0)throw new se("PortfolioSearch: no candidates were evaluated");return this.#s=m,this.#n=m.best(),{leaderboard:m,bestResult:this.#n}}async refitBest(t,n){if(!this.#n)throw new se("PortfolioSearch: must call fit() first");let e=this.#n,r=await this.#t.find(l=>l.name===e.modelName).cls.create(e.params),o=Cs(t),a=js(n);return r.fit(o,a),r}get leaderboard(){return this.#s}get bestResult(){return this.#n}};$s.exports={PORTFOLIO:ne,getPortfolio:Ts,PortfolioStrategy:wt,PortfolioSearch:re}});var Ks=S((Cc,Js)=>{var{encodeBundle:vo,decodeBundle:Fo,register:Ds,load:Xs,normalizeX:oe,normalizeY:Vs,accuracy:Ao,r2Score:ko,ValidationError:yt,NotFittedError:qo,DisposedError:Eo,lift:Us}=q(),Ys="wlearn.ensemble.voting.classifier@1",Gs="wlearn.ensemble.voting.regressor@1",Ws=!1,ae=class s{#t;#e;#s;#n;#i;#r;#o=!1;#l=!1;constructor(t){this.#t=t.estimators||[],this.#s=t.weights||null,this.#n=t.voting||"soft",this.#i=t.task||"classification",this.#e=null,this.#r=null,s._register()}static async create(t={}){return new s(t)}#a(){if(this.#l)throw new Eo("VotingEnsemble has been disposed.")}#c(){if(this.#a(),!this.#o)throw new qo("VotingEnsemble is not fitted. Call fit() first.")}async fit(t,n){this.#a();let e=oe(t),i=Vs(n);if(this.#i==="classification"){let r=new Set;for(let o=0;o<i.length;o++)r.add(i[o]);this.#r=new Int32Array([...r].sort((o,a)=>o-a))}this.#s||(this.#s=new Float64Array(this.#t.length).fill(1/this.#t.length)),this.#e=[];for(let[r,o,a]of this.#t){let l=await o.create(a||{});l.fit(e,i),this.#e.push(l)}return this.#o=!0,this}predict(t){this.#c();let n=oe(t),e=n.rows;if(this.#i==="regression")return this.#f(n,e);if(this.#n==="soft"){let i=this.predictProba(n);return Us(i,r=>{let o=this.#r.length,a=new Float64Array(e);for(let l=0;l<e;l++){let h=0,c=-1/0;for(let f=0;f<o;f++)r[l*o+f]>c&&(c=r[l*o+f],h=f);a[l]=this.#r[h]}return a})}return this.#h(n,e)}predictProba(t){if(this.#c(),this.#i!=="classification")throw new yt("predictProba is only available for classification");if(this.#n==="hard")throw new yt('predictProba requires voting="soft"');let n=oe(t),e=n.rows,i=this.#r.length,r=[],o=!1;for(let l=0;l<this.#e.length;l++){let h=this.#e[l].predictProba(n);h!=null&&typeof h.then=="function"&&(o=!0),r.push(h)}let a=l=>{let h=new Float64Array(e*i);for(let c=0;c<l.length;c++){let f=l[c],u=this.#s[c];for(let d=0;d<e*i;d++)h[d]+=u*f[d]}return h};return o?Promise.all(r).then(a):a(r)}score(t,n){this.#c();let e=this.predict(t),i=Vs(n),r=this.#i==="classification"?Ao:ko;return Us(e,o=>r(i,o))}save(){this.#c();let n={typeId:this.#i==="classification"?Ys:Gs,params:{task:this.#i,voting:this.#n,weights:[...this.#s],estimatorNames:this.#t.map(i=>i[0]),classes:this.#r?[...this.#r]:null}},e=this.#e.map((i,r)=>({id:this.#t[r][0],data:i.save(),mediaType:"application/x-wlearn-bundle"}));return vo(n,e)}static async load(t){let{manifest:n,toc:e,blobs:i}=Fo(t),r=n.params,o=new s({task:r.task,voting:r.voting,weights:new Float64Array(r.weights)});o.#r=r.classes?new Int32Array(r.classes):null,o.#t=r.estimatorNames.map(a=>[a,null,null]),o.#e=[];for(let a of r.estimatorNames){let l=e.find(f=>f.id===a);if(!l)throw new yt(`No artifact for estimator "${a}"`);let h=i.subarray(l.offset,l.offset+l.length),c=await Xs(h);o.#e.push(c)}return o.#o=!0,o}dispose(){if(!this.#l&&(this.#l=!0,this.#e))for(let t of this.#e)t.dispose()}getParams(){return{task:this.#i,voting:this.#n,weights:this.#s?[...this.#s]:null,estimatorNames:this.#t.map(t=>t[0])}}setParams(t){return this.#a(),t.voting!==void 0&&(this.#n=t.voting),t.weights!==void 0&&(this.#s=new Float64Array(t.weights)),this}get capabilities(){return{classifier:this.#i==="classification",regressor:this.#i==="regression",predictProba:this.#i==="classification"&&this.#n==="soft",decisionFunction:!1,sampleWeight:!1,csr:!1,earlyStopping:!1}}get isFitted(){return this.#o}get classes(){return this.#r}#f(t,n){let e=[],i=!1;for(let o=0;o<this.#e.length;o++){let a=this.#e[o].predict(t);a!=null&&typeof a.then=="function"&&(i=!0),e.push(a)}let r=o=>{let a=new Float64Array(n);for(let l=0;l<o.length;l++){let h=this.#s[l];for(let c=0;c<n;c++)a[c]+=h*o[l][c]}return a};return i?Promise.all(e).then(r):r(e)}#h(t,n){let e=[],i=!1;for(let o=0;o<this.#e.length;o++){let a=this.#e[o].predict(t);a!=null&&typeof a.then=="function"&&(i=!0),e.push(a)}let r=o=>{let a=this.#r.length,l=new Float64Array(n);for(let h=0;h<n;h++){let c=new Float64Array(a);for(let d=0;d<o.length;d++){let m=o[d][h],p=this.#r.indexOf(m);p>=0&&(c[p]+=this.#s[d])}let f=0,u=-1/0;for(let d=0;d<a;d++)c[d]>u&&(u=c[d],f=d);l[h]=this.#r[f]}return l};return i?Promise.all(e).then(r):r(e)}static _register(){if(Ws)return;Ws=!0;let t=(n,e,i)=>s._loadFromParts(n,e,i);Ds(Ys,t),Ds(Gs,t)}static async _loadFromParts(t,n,e){let i=t.params,r=new s({task:i.task,voting:i.voting,weights:new Float64Array(i.weights)});r.#r=i.classes?new Int32Array(i.classes):null,r.#t=i.estimatorNames.map(o=>[o,null,null]),r.#e=[];for(let o of i.estimatorNames){let a=n.find(c=>c.id===o);if(!a)throw new yt(`No artifact for estimator "${o}"`);let l=e.subarray(a.offset,a.offset+a.length),h=await Xs(l);r.#e.push(h)}return r.#o=!0,r}};Js.exports={VotingEnsemble:ae}});var an=S((jc,on)=>{var{encodeBundle:Io,decodeBundle:Po,register:Hs,load:Zs,normalizeX:Qs,normalizeY:tn,accuracy:Ro,r2Score:Mo,stratifiedKFold:zo,kFold:No,ValidationError:rt,NotFittedError:Lo,DisposedError:Bo,lift:ce}=q(),en="wlearn.ensemble.stacking.classifier@1",sn="wlearn.ensemble.stacking.regressor@1",nn=!1,le=class s{#t;#e;#s;#n;#i;#r;#o;#l;#a;#c;#f;#h=!1;#d=!1;constructor(t){this.#t=t.estimators||[],this.#e=t.finalEstimator||null,this.#i=t.cv||5,this.#r=t.task||"classification",this.#o=t.passthrough||!1,this.#l=t.seed??42,this.#s=null,this.#n=null,this.#a=null,this.#c=0,this.#f=0,s._register()}static async create(t={}){return new s(t)}#m(){if(this.#d)throw new Bo("StackingEnsemble has been disposed.")}#u(){if(this.#m(),!this.#h)throw new Lo("StackingEnsemble is not fitted. Call fit() first.")}async fit(t,n){if(this.#m(),!this.#e)throw new rt("StackingEnsemble requires a finalEstimator");let e=Qs(t),i=tn(n),r=e.rows;if(this.#r==="classification"){let m=new Set;for(let p=0;p<i.length;p++)m.add(i[p]);this.#a=new Int32Array([...m].sort((p,g)=>p-g)),this.#c=this.#a.length}let o=this.#r==="classification"?zo(i,this.#i,{shuffle:!0,seed:this.#l}):No(r,this.#i,{shuffle:!0,seed:this.#l}),a=this.#t.length,l=this.#r==="classification"?this.#c:1,h=a*l,c=new Float64Array(r*h);for(let m=0;m<a;m++){let[,p,g]=this.#t[m];for(let{train:w,test:b}of o){let y=rn(e,w),_=Oo(i,w),A=rn(e,b),v=await p.create(g||{});try{if(v.fit(y,_),this.#r==="classification"){let F=await v.predictProba(A);for(let k=0;k<b.length;k++){let O=b[k];for(let P=0;P<this.#c;P++)c[O*h+m*l+P]=F[k*this.#c+P]}}else{let F=await v.predict(A);for(let k=0;k<b.length;k++)c[b[k]*h+m]=F[k]}}finally{v.dispose()}}}let f;if(this.#o){this.#f=h+e.cols;let m=new Float64Array(r*this.#f);for(let p=0;p<r;p++)m.set(c.subarray(p*h,(p+1)*h),p*this.#f),m.set(e.data.subarray(p*e.cols,(p+1)*e.cols),p*this.#f+h);f={data:m,rows:r,cols:this.#f}}else this.#f=h,f={data:c,rows:r,cols:h};this.#s=[];for(let[,m,p]of this.#t){let g=await m.create(p||{});g.fit(e,i),this.#s.push(g)}let[,u,d]=this.#e;return this.#n=await u.create(d||{}),this.#n.fit(f,i),this.#h=!0,this}predict(t){this.#u();let n=this.#p(t);return ce(n,e=>this.#n.predict(e))}predictProba(t){if(this.#u(),this.#r!=="classification")throw new rt("predictProba is only available for classification");if(typeof this.#n.predictProba!="function")throw new rt("Meta-model does not support predictProba");let n=this.#p(t);return ce(n,e=>this.#n.predictProba(e))}score(t,n){this.#u();let e=this.predict(t),i=tn(n),r=this.#r==="classification"?Ro:Mo;return ce(e,o=>r(i,o))}save(){this.#u();let n={typeId:this.#r==="classification"?en:sn,params:{task:this.#r,cv:this.#i,passthrough:this.#o,seed:this.#l,estimatorNames:this.#t.map(i=>i[0]),metaName:this.#e[0],classes:this.#a?[...this.#a]:null,nMetaCols:this.#f}},e=this.#s.map((i,r)=>({id:this.#t[r][0],data:i.save(),mediaType:"application/x-wlearn-bundle"}));return e.push({id:this.#e[0],data:this.#n.save(),mediaType:"application/x-wlearn-bundle"}),Io(n,e)}static async load(t){let{manifest:n,toc:e,blobs:i}=Po(t);return s._loadFromParts(n,e,i)}dispose(){if(!this.#d){if(this.#d=!0,this.#s)for(let t of this.#s)t.dispose();this.#n&&this.#n.dispose()}}getParams(){return{task:this.#r,cv:this.#i,passthrough:this.#o,seed:this.#l,estimatorNames:this.#t.map(t=>t[0]),metaName:this.#e?this.#e[0]:null}}setParams(t){return this.#m(),t.cv!==void 0&&(this.#i=t.cv),t.passthrough!==void 0&&(this.#o=t.passthrough),t.seed!==void 0&&(this.#l=t.seed),this}get capabilities(){return{classifier:this.#r==="classification",regressor:this.#r==="regression",predictProba:this.#r==="classification",decisionFunction:!1,sampleWeight:!1,csr:!1,earlyStopping:!1}}get isFitted(){return this.#h}get classes(){return this.#a}#p(t){let n=Qs(t),e=n.rows,i=this.#s.length,r=this.#r==="classification"?this.#c:1,o=i*r,a=[],l=!1;for(let c=0;c<i;c++){let f=this.#r==="classification"?this.#s[c].predictProba(n):this.#s[c].predict(n);f!=null&&typeof f.then=="function"&&(l=!0),a.push(f)}let h=c=>{let f=new Float64Array(e*this.#f);for(let u=0;u<i;u++)if(this.#r==="classification"){let d=c[u];for(let m=0;m<e;m++)for(let p=0;p<this.#c;p++)f[m*this.#f+u*r+p]=d[m*this.#c+p]}else{let d=c[u];for(let m=0;m<e;m++)f[m*this.#f+u]=d[m]}if(this.#o)for(let u=0;u<e;u++)f.set(n.data.subarray(u*n.cols,(u+1)*n.cols),u*this.#f+o);return{data:f,rows:e,cols:this.#f}};return l?Promise.all(a).then(h):h(a)}static _register(){if(nn)return;nn=!0;let t=(n,e,i)=>s._loadFromParts(n,e,i);Hs(en,t),Hs(sn,t)}static async _loadFromParts(t,n,e){let i=t.params,r=new s({task:i.task,cv:i.cv,passthrough:i.passthrough,seed:i.seed});r.#a=i.classes?new Int32Array(i.classes):null,r.#c=r.#a?r.#a.length:0,r.#f=i.nMetaCols,r.#t=i.estimatorNames.map(l=>[l,null,null]),r.#e=[i.metaName,null,null],r.#s=[];for(let l of i.estimatorNames){let h=n.find(f=>f.id===l);if(!h)throw new rt(`No artifact for base estimator "${l}"`);let c=e.subarray(h.offset,h.offset+h.length);r.#s.push(await Zs(c))}let o=n.find(l=>l.id===i.metaName);if(!o)throw new rt(`No artifact for meta estimator "${i.metaName}"`);let a=e.subarray(o.offset,o.offset+o.length);return r.#n=await Zs(a),r.#h=!0,r}};function rn(s,t){let{data:n,cols:e}=s,i=t.length,r=new Float64Array(i*e);for(let o=0;o<i;o++){let a=t[o]*e;r.set(n.subarray(a,a+e),o*e)}return{data:r,rows:i,cols:e}}function Oo(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}on.exports={StackingEnsemble:le}});var bn=S((Tc,gn)=>{var{encodeBundle:Co,decodeBundle:jo,register:cn,load:To,normalizeX:fe,normalizeY:ln,accuracy:$o,r2Score:Do,stratifiedKFold:Xo,kFold:Vo,ValidationError:fn,NotFittedError:Uo,DisposedError:Yo,lift:hn}=q(),un="wlearn.ensemble.bagged.classifier@1",dn="wlearn.ensemble.bagged.regressor@1",mn=!1,he=class s{#t;#e;#s;#n;#i;#r;#o;#l=0;#a=0;#c;#f;#h=!1;#d=!1;constructor(t={}){this.#t=t.estimator||null,this.#e=t.kFold||5,this.#s=t.nRepeats||1,this.#n=t.task||"classification",this.#i=t.seed??42,this.#r=null,this.#o=null,this.#c=null,this.#f=null,s._register()}static async create(t={}){return new s(t)}#m(){if(this.#d)throw new Yo("BaggedEstimator has been disposed.")}#u(){if(this.#m(),!this.#h)throw new Uo("BaggedEstimator is not fitted. Call fit() first.")}async fit(t,n){this.#m();let e=fe(t),i=ln(n),r=e.rows;if(this.#a=r,this.#n==="classification"){let l=new Set;for(let h=0;h<i.length;h++)l.add(i[h]);this.#o=new Int32Array([...l].sort((h,c)=>h-c)),this.#l=this.#o.length}this.#n==="classification"?this.#c=new Float64Array(r*this.#l):this.#c=new Float64Array(r),this.#f=new Uint8Array(r);let[,o,a]=this.#t;this.#r=[];for(let l=0;l<this.#s;l++){let h=this.#i+l,c=this.#n==="classification"?Xo(i,this.#e,{shuffle:!0,seed:h}):Vo(r,this.#e,{shuffle:!0,seed:h});for(let{train:f,test:u}of c){let d=pn(e,f),m=Go(i,f),p=pn(e,u),g=await o.create(a||{});if(g.fit(d,m),this.#n==="classification"){let w=await g.predictProba(p),b=this.#l;for(let y=0;y<u.length;y++){let _=u[y];for(let A=0;A<b;A++)this.#c[_*b+A]+=w[y*b+A]}}else{let w=await g.predict(p);for(let b=0;b<u.length;b++)this.#c[u[b]]+=w[b]}for(let w=0;w<u.length;w++)this.#f[u[w]]+=1;this.#r.push(g)}}return this.#h=!0,this}predict(t){this.#u();let n=fe(t),e=n.rows;if(this.#n==="regression")return this.#p(n,e);let i=this.predictProba(n);return hn(i,r=>{let o=this.#l,a=new Float64Array(e);for(let l=0;l<e;l++){let h=0,c=-1/0;for(let f=0;f<o;f++)r[l*o+f]>c&&(c=r[l*o+f],h=f);a[l]=this.#o[h]}return a})}predictProba(t){if(this.#u(),this.#n!=="classification")throw new fn("predictProba is only available for classification");let n=fe(t),e=n.rows,i=this.#l,r=this.#r.length,o=[],a=!1;for(let h of this.#r){let c=h.predictProba(n);c!=null&&typeof c.then=="function"&&(a=!0),o.push(c)}let l=h=>{let c=new Float64Array(e*i);for(let f of h)for(let u=0;u<e*i;u++)c[u]+=f[u];for(let f=0;f<e*i;f++)c[f]/=r;return c};return a?Promise.all(o).then(l):l(o)}score(t,n){this.#u();let e=this.predict(t),i=ln(n),r=this.#n==="classification"?$o:Do;return hn(e,o=>r(i,o))}#p(t,n){let e=this.#r.length,i=[],r=!1;for(let a of this.#r){let l=a.predict(t);l!=null&&typeof l.then=="function"&&(r=!0),i.push(l)}let o=a=>{let l=new Float64Array(n);for(let h of a)for(let c=0;c<n;c++)l[c]+=h[c];for(let h=0;h<n;h++)l[h]/=e;return l};return r?Promise.all(i).then(o):o(i)}get oofPredictions(){this.#u();let t=new Uint8Array(this.#f);for(let e=0;e<t.length;e++)t[e]===0&&(t[e]=1);if(this.#n==="classification"){let e=this.#l,i=new Float64Array(this.#c);for(let r=0;r<this.#a;r++){let o=t[r];for(let a=0;a<e;a++)i[r*e+a]/=o}return i}let n=new Float64Array(this.#c);for(let e=0;e<this.#a;e++)n[e]/=t[e];return n}save(){this.#u();let n={typeId:this.#n==="classification"?un:dn,params:{task:this.#n,kFold:this.#e,nRepeats:this.#s,seed:this.#i,estimatorName:this.#t[0],classes:this.#o?[...this.#o]:null,nClasses:this.#l,nSamples:this.#a}},e=this.#r.map((o,a)=>({id:`fold_${a}`,data:o.save(),mediaType:"application/x-wlearn-bundle"})),i=this.oofPredictions,r=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);return e.push({id:"oof",data:r,mediaType:"application/octet-stream"}),Co(n,e)}static async load(t){let{manifest:n,toc:e,blobs:i}=jo(t);return s._loadFromParts(n,e,i)}dispose(){if(!this.#d){if(this.#d=!0,this.#r)for(let t of this.#r)t.dispose();this.#r=null,this.#c=null,this.#f=null}}getParams(){return{task:this.#n,kFold:this.#e,nRepeats:this.#s,seed:this.#i,estimatorName:this.#t?this.#t[0]:null}}setParams(t){return this.#m(),t.kFold!==void 0&&(this.#e=t.kFold),t.nRepeats!==void 0&&(this.#s=t.nRepeats),t.seed!==void 0&&(this.#i=t.seed),this}get capabilities(){return{classifier:this.#n==="classification",regressor:this.#n==="regression",predictProba:this.#n==="classification",decisionFunction:!1,sampleWeight:!1,csr:!1,earlyStopping:!1}}get isFitted(){return this.#h&&!this.#d}get classes(){return this.#o}static _register(){if(mn)return;mn=!0;let t=(n,e,i)=>s._loadFromParts(n,e,i);cn(un,t),cn(dn,t)}static async _loadFromParts(t,n,e){let i=t.params,r=new s({task:i.task,kFold:i.kFold||5,nRepeats:i.nRepeats||1,seed:i.seed??42});r.#o=i.classes?new Int32Array(i.classes):null,r.#l=i.nClasses||0,r.#a=i.nSamples||0,r.#t=[i.estimatorName||"base",null,null];let o=r.#e*r.#s;r.#r=[];for(let l=0;l<o;l++){let h=`fold_${l}`,c=n.find(u=>u.id===h);if(!c)throw new fn(`No artifact for "${h}"`);let f=e.subarray(c.offset,c.offset+c.length);r.#r.push(await To(f))}let a=n.find(l=>l.id==="oof");if(a){let l=e.subarray(a.offset,a.offset+a.length),h=new Float64Array(l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength));r.#c=h,r.#f=new Uint8Array(r.#a).fill(1)}else r.#n==="classification"?r.#c=new Float64Array(r.#a*r.#l):r.#c=new Float64Array(r.#a),r.#f=new Uint8Array(r.#a);return r.#h=!0,r}};function pn(s,t){let{data:n,cols:e}=s,i=t.length,r=new Float64Array(i*e);for(let o=0;o<i;o++){let a=t[o]*e;r.set(n.subarray(a,a+e),o*e)}return{data:r,rows:i,cols:e}}function Go(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}gn.exports={BaggedEstimator:he}});var de=S(($c,yn)=>{var{ValidationError:wn}=q();function ue(s){let t=s.length;if(t===0)return new Float64Array(0);if(t===1)return new Float64Array([1]);let n=new Float64Array(s);n.sort(),n.reverse();let e=new Float64Array(t);e[0]=n[0];for(let a=1;a<t;a++)e[a]=e[a-1]+n[a];let i=-1;for(let a=0;a<t;a++)n[a]*(a+1)>e[a]-1&&(i=a);if(i<0){let a=new Float64Array(t);return a.fill(1/t),a}let r=(e[i]-1)/(i+1),o=new Float64Array(t);for(let a=0;a<t;a++)o[a]=Math.max(s[a]-r,0);return o}function Wo(s,t,n,{task:e="classification",lr:i=.05,nIter:r=100}={}){let o=s.length,a=t.length;if(o===0)throw new wn("optimizeWeights: need at least 1 model");if(o===1)return new Float64Array([1]);let l=new Float64Array(n),h=1e-15;if(e==="classification"){let f=s[0].length/a;if(f!==Math.floor(f))throw new wn("optimizeWeights: prediction length must be divisible by n");for(let u=0;u<r;u++){let d=new Float64Array(o);for(let p=0;p<a;p++){let g=t[p]|0,w=0;for(let b=0;b<o;b++)w+=l[b]*s[b][p*f+g];w=Math.max(w,h);for(let b=0;b<o;b++)d[b]-=s[b][p*f+g]/w}for(let p=0;p<o;p++)d[p]/=a;for(let p=0;p<o;p++)l[p]-=i*d[p];let m=ue(l);for(let p=0;p<o;p++)l[p]=m[p]}}else for(let c=0;c<r;c++){let f=new Float64Array(o);for(let d=0;d<a;d++){let m=0;for(let g=0;g<o;g++)m+=l[g]*s[g][d];let p=t[d]-m;for(let g=0;g<o;g++)f[g]-=2*p*s[g][d]}for(let d=0;d<o;d++)f[d]/=a;for(let d=0;d<o;d++)l[d]-=i*f[d];let u=ue(l);for(let d=0;d<o;d++)l[d]=u[d]}return l}yn.exports={optimizeWeights:Wo,projectSimplex:ue}});var _n=S((Dc,Sn)=>{var{getScorer:Jo,normalizeY:Ko,ValidationError:xn}=q(),{optimizeWeights:Ho}=de();function Zo(s,t,{maxSize:n=20,scoring:e="accuracy",task:i="classification",nClasses:r=0,refineWeights:o=!0}={}){let a=Ko(t),l=a.length,h=s.length;if(h===0)throw new xn("caruanaSelect: need at least 1 candidate");let c=Jo(e),f=s[0].length/l;if(f!==Math.floor(f))throw new xn("caruanaSelect: oofPredictions[0].length must be divisible by n");i==="classification"&&r===0&&(r=f);let u=new Float64Array(s[0].length),d=[],m=[];for(let y=0;y<n;y++){let _=-1,A=-1/0;for(let F=0;F<h;F++){let k=Qo(u,s[F],y,y+1),O=ta(k,a,c,i,r,l);O>A&&(A=O,_=F)}d.push(_),m.push(A);let v=s[_];for(let F=0;F<u.length;F++)u[F]=(y*u[F]+v[F])/(y+1)}let p=new Map;for(let y of d)p.set(y,(p.get(y)||0)+1);let g=new Int32Array([...p.keys()].sort((y,_)=>y-_)),w=new Float64Array(g.length);for(let y=0;y<g.length;y++)w[y]=p.get(g[y])/n;let b={indices:g,weights:w,scores:new Float64Array(m)};if(o&&g.length>1){let y=Array.from(g,_=>s[_]);b.weights=Ho(y,a,w,{task:i})}return b}function Qo(s,t,n,e){let i=new Float64Array(s.length);for(let r=0;r<s.length;r++)i[r]=(n*s[r]+t[r])/e;return i}function ta(s,t,n,e,i,r){if(e==="regression")return n(t,s);let o=new Float64Array(r);for(let a=0;a<r;a++){let l=0,h=-1/0;for(let c=0;c<i;c++)s[a*i+c]>h&&(h=s[a*i+c],l=c);o[a]=l}return n(t,o)}Sn.exports={caruanaSelect:Zo}});var An=S((Vc,Fn)=>{var{stratifiedKFold:ea,kFold:sa,normalizeX:na,normalizeY:ra,ValidationError:Xc}=q();async function ia(s,t,n,{cv:e=5,seed:i=42,task:r="classification"}={}){let o=na(t),a=ra(n),l=o.rows,h=r==="classification"?ea(a,e,{shuffle:!0,seed:i}):sa(l,e,{shuffle:!0,seed:i}),c=null,f=0;if(r==="classification"){let d=new Set;for(let m=0;m<a.length;m++)d.add(a[m]);c=new Int32Array([...d].sort((m,p)=>m-p)),f=c.length}let u=[];for(let[d,m,p]of s){let g;r==="classification"?g=new Float64Array(l*f):g=new Float64Array(l);for(let{train:w,test:b}of h){let y=vn(o,w),_=oa(a,w),A=vn(o,b),v=await m.create(p||{});try{if(v.fit(y,_),r==="classification"){let F=await v.predictProba(A);for(let k=0;k<b.length;k++){let O=b[k];for(let P=0;P<f;P++)g[O*f+P]=F[k*f+P]}}else{let F=await v.predict(A);for(let k=0;k<b.length;k++)g[b[k]]=F[k]}}finally{v.dispose()}}u.push(g)}return{oofPreds:u,classes:c}}function vn(s,t){let{data:n,cols:e}=s,i=t.length,r=new Float64Array(i*e);for(let o=0;o<i;o++){let a=t[o]*e;r.set(n.subarray(a,a+e),o*e)}return{data:r,rows:i,cols:e}}function oa(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}Fn.exports={getOofPredictions:ia}});var qn=S((Uc,kn)=>{var{VotingEnsemble:aa}=Ks(),{StackingEnsemble:ca}=an(),{BaggedEstimator:la}=bn(),{caruanaSelect:fa}=_n(),{getOofPredictions:ha}=An(),{optimizeWeights:ua,projectSimplex:da}=de();kn.exports={VotingEnsemble:aa,StackingEnsemble:ca,BaggedEstimator:la,caruanaSelect:fa,getOofPredictions:ha,optimizeWeights:ua,projectSimplex:da}});var pe=S((Gc,In)=>{var{makeLCG:En}=q(),{sampleConfig:ma}=st(),{makeCandidateId:pa}=M(),{max:ga,ceil:Yc}=Math,me=class{#t=[];#e=[];#s="probe";#n=0;#i=0;#r=[];#o;#l;#a=!1;#c;constructor(t,{nIter:n=20,seed:e=42,promoteCount:i=10,greaterIsBetter:r=!0,probeFraction:o=.5}={}){this.#o=i,this.#l=r,this.#c=o;let a=En(e);for(let l of t){let c={...l.searchSpace||l.cls.defaultSearchSpace?.()||{}};if(l.params)for(let u of Object.keys(l.params))delete c[u];let f=En(a()*2147483647|0);for(let u=0;u<n;u++){let m={...ma(c,f),...l.params||{}},p=pa(l.name,m);this.#t.push({candidateId:p,cls:l.cls,params:m})}}}get phase(){return this.#s}next(){if(this.#a)return null;if(this.#s==="probe"){if(this.#n>=this.#t.length)return null;let t=this.#t[this.#n++];return this.#c<1?{...t,budget:{type:"subsample",value:this.#c}}:t}return this.#i>=this.#e.length?null:this.#e[this.#i++]}report(t){if(this.#s==="probe"){this.#r.push(t),this.#r.length>=this.#t.length&&this.#f();return}}#f(){let t=[...this.#r];this.#l?t.sort((i,r)=>r.meanScore-i.meanScore):t.sort((i,r)=>i.meanScore-r.meanScore);let n=t.slice(0,ga(1,this.#o)),e=new Set(n.map(i=>i.candidateId));this.#e=this.#t.filter(i=>e.has(i.candidateId)),this.#s="promote",this.#i=0}isDone(){return this.#a?!0:this.#s==="promote"&&this.#i>=this.#e.length&&this.#e.length>0?(this.#a=!0,!0):!1}};In.exports={ProgressiveStrategy:me}});var we=S((Wc,Ln)=>{var{stratifiedKFold:Pn,kFold:Rn,normalizeX:Mn,normalizeY:zn,ValidationError:ge}=q(),{Executor:Nn}=H(),{ProgressiveStrategy:ba}=pe(),{detectTask:wa,scorerGreaterIsBetter:ya}=M(),be=class{#t;#e;#s=null;#n=null;constructor(t,n={}){if(!t||t.length===0)throw new ge("ProgressiveSearch: at least one model is required");this.#t=t,this.#e={scoring:null,cv:5,seed:42,task:null,nIter:20,maxTimeMs:0,promoteCount:10,probeFraction:.5,onProgress:null,...n}}async fit(t,n){let e=Mn(t),i=zn(n),r=this.#e.task||wa(i),o=this.#e.scoring||(r==="classification"?"accuracy":"r2"),{cv:a,seed:l,nIter:h,maxTimeMs:c,promoteCount:f,probeFraction:u,onProgress:d}=this.#e,m=ya(o),g=[(r==="classification"?Pn(i,2,{shuffle:!0,seed:l}):Rn(i.length,2,{shuffle:!0,seed:l}))[0]],w=r==="classification"?Pn(i,a,{shuffle:!0,seed:l+1}):Rn(i.length,a,{shuffle:!0,seed:l+1}),b=new ba(this.#t,{nIter:h,seed:l,promoteCount:f,greaterIsBetter:m,probeFraction:u}),y=new Nn({folds:g,scoring:o,X:e,y:i,timeLimitMs:c>0?Math.floor(c*.3):0,seed:l,onProgress:d});for(;b.phase==="probe"&&!b.isDone()&&!y.isTimedOut;){let v=b.next();if(v===null)break;try{let F=await y.evaluateCandidate(v);b.report(F)}catch{b.report({candidateId:v.candidateId,meanScore:-1/0,foldScores:new Float64Array(1),stdScore:0,fitTimeMs:0,nTrainUsed:0,nTest:0})}}b.phase;let _=new Nn({folds:w,scoring:o,X:e,y:i,timeLimitMs:c>0?Math.floor(c*.7):0,seed:l,onProgress:d});for(;!b.isDone()&&!_.isTimedOut;){let v=b.next();if(v===null)break;try{await _.evaluateCandidate(v)}catch{}}let A=_.leaderboard;if(A.length===0){let v=y.leaderboard;if(v.length===0)throw new ge("ProgressiveSearch: no candidates were evaluated");this.#s=v}else this.#s=A;return this.#n=this.#s.best(),{leaderboard:this.#s,bestResult:this.#n}}async refitBest(t,n){if(!this.#n)throw new ge("ProgressiveSearch: must call fit() first");let e=this.#n,r=await this.#t.find(l=>l.name===e.modelName).cls.create(e.params),o=Mn(t),a=zn(n);return r.fit(o,a),r}get leaderboard(){return this.#s}get bestResult(){return this.#n}};Ln.exports={ProgressiveSearch:be}});var Tn=S((Jc,jn)=>{var{normalizeX:Bn,normalizeY:On,ValidationError:Cn,Preprocessor:xa}=q(),{getOofPredictions:Sa,caruanaSelect:_a,VotingEnsemble:va,StackingEnsemble:Fa}=qn(),{RandomSearch:Aa}=Jt(),{SuccessiveHalvingSearch:ka}=ee(),{PortfolioSearch:qa}=ie(),{ProgressiveSearch:Ea}=we(),{detectTask:Ia}=M();function Pa(s,t,n,e){if(e==="classification"){let f=s.length/n,u=0;for(let d=0;d<n;d++){let m=0,p=0,g=-1/0,w=-1/0;for(let b=0;b<f;b++){let y=d*f+b;s[y]>g&&(g=s[y],m=b),t[y]>w&&(w=t[y],p=b)}m!==p&&u++}return u/n}let i=0,r=0,o=0,a=0,l=0;for(let f=0;f<n;f++)i+=s[f],r+=t[f],o+=s[f]*s[f],a+=t[f]*t[f],l+=s[f]*t[f];let h=Math.sqrt((o-i*i/n)*(a-r*r/n));if(h<1e-12)return 1;let c=(l-i*r/n)/h;return 1-Math.abs(c)}function Ra(s,t,n,e){let i=t.length;if(s.length<=2||e<=0)return s.map((o,a)=>a);let r=[0];for(let o=1;o<s.length;o++){let a=!0;for(let l of r)if(Pa(s[o],s[l],i,n)<e){a=!1;break}a&&r.push(o)}return r.length<2&&s.length>=2&&(r.includes(1)||r.push(1)),r}function Ma(s){return s.map(t=>Array.isArray(t)?{name:t[0],cls:t[1],params:t[2]||{}}:t)}async function za(s,t,n,e={}){let{ensemble:i=!0,ensembleSize:r=20,refit:o=!0,strategy:a="random",minDisagreement:l=.05,stacking:h="auto",metaEstimator:c=null,preprocess:f=!1,onProgress:u=null,...d}=e,m=Ma(s);if(m.length===0)throw new Cn("autoFit: at least one model is required");let p=null;if(f){let j=typeof f=="object"?f:{};p=new xa(j);let Y=Bn(t),T=On(n);t=p.fitTransform(Y,T)}let g={...d,onProgress:u},w;if(a==="portfolio")w=new qa(m,g);else if(a==="halving")w=new ka(m,g);else if(a==="progressive")w=new Ea(m,g);else if(a==="bayesian"){let j;try{j=Jn("@wlearn/bo").BayesianSearch}catch{throw new Cn('autoFit: strategy "bayesian" requires @wlearn/bo. Install: npm i @wlearn/bo')}w=new j(m,g)}else w=new Aa(m,g);let{leaderboard:b,bestResult:y}=await w.fit(t,n),_=b.ranked(),A=Bn(t),v=On(n),F=d.task||Ia(v),k=d.scoring||(F==="classification"?"accuracy":"r2"),O=d.cv||5,P=d.seed||42,it=null;if(i){u&&u({phase:"ensemble",message:"building ensemble"});let j=new Map,Y=new Map;for(let x of _)j.has(x.modelName)?Y.has(x.modelName)||Y.set(x.modelName,x):j.set(x.modelName,x);let T=[...j.values()],Z=new Set(T.map(x=>x.id));for(let x of Y.values()){if(T.length>=r*2)break;Z.has(x.id)||(T.push(x),Z.add(x.id))}for(let x of _){if(T.length>=r*2)break;Z.has(x.id)||(T.push(x),Z.add(x.id))}let ye=new Map;for(let x of m)ye.set(x.name,x.cls);let xe=T.map((x,ot)=>{let Wn=ye.get(x.modelName);return[`${x.modelName}_${ot}`,Wn,x.params]}),{oofPreds:Se}=await Sa(xe,A,v,{cv:O,seed:P,task:F}),_e=Ra(Se,v,F,l),Dn=_e.map(x=>Se[x]),Xn=_e.map(x=>xe[x]),{indices:Vn,weights:Un}=_a(Dn,v,{maxSize:r,scoring:k,task:F}),xt=Array.from(Vn,x=>Xn[x]),Yn=Un,Gn=new Set(xt.map(x=>x[0].split("_")[0]));if((h===!0||h==="auto"&&Gn.size>=3&&c)&&c){let x=Array.isArray(c)?c:["meta",c.cls||c,c.params||{}],ot=await Fa.create({estimators:xt,finalEstimator:x,passthrough:!0,task:F,cv:O,seed:P});await ot.fit(A,v),it=ot}else{let x=await va.create({estimators:xt,weights:Yn,voting:F==="classification"?"soft":void 0,task:F});await x.fit(A,v),it=x}}else o&&(it=await w.refitBest(t,n));return{model:it,preprocessor:p,leaderboard:_,bestParams:y.params,bestModelName:y.modelName,bestScore:y.meanScore}}jn.exports={autoFit:za}});var sc=S((Kc,$n)=>{var{sampleParam:Na,sampleConfig:La,randomConfigs:Ba,gridConfigs:Oa}=st(),{RandomSearch:Ca}=Jt(),{SuccessiveHalvingSearch:ja}=ee(),{PortfolioSearch:Ta,PortfolioStrategy:$a,getPortfolio:Da,PORTFOLIO:Xa}=ie(),{Leaderboard:Va}=Dt(),{autoFit:Ua}=Tn(),{Executor:Ya}=H(),{RandomStrategy:Ga}=Yt(),{HalvingStrategy:Wa}=Qt(),{ProgressiveStrategy:Ja}=pe(),{ProgressiveSearch:Ka}=we(),{detectTask:Ha,makeCandidateId:Za,seedFor:Qa,partialShuffle:tc,scorerGreaterIsBetter:ec}=M();$n.exports={sampleParam:Na,sampleConfig:La,randomConfigs:Ba,gridConfigs:Oa,RandomSearch:Ca,SuccessiveHalvingSearch:ja,PortfolioSearch:Ta,PortfolioStrategy:$a,getPortfolio:Da,PORTFOLIO:Xa,Leaderboard:Va,autoFit:Ua,Executor:Ya,RandomStrategy:Ga,HalvingStrategy:Wa,ProgressiveStrategy:Ja,ProgressiveSearch:Ka,detectTask:Ha,makeCandidateId:Za,seedFor:Qa,partialShuffle:tc,scorerGreaterIsBetter:ec}});return sc();})();
|