@wlearn/ensemble 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 ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ - Depend on the CommonJS `@wlearn/core` release and remove the unused direct `@wlearn/types` dependency
6
+ - Add package homepage and GitHub issue metadata
7
+
8
+ ## 0.1.0
9
+
10
+ - Initial release
11
+ - VotingEnsemble: soft/hard voting with configurable weights
12
+ - StackingEnsemble: K-fold stacking with customizable meta-learner
13
+ - BaggedEstimator: bootstrap aggregating with configurable sample size
14
+ - Caruana greedy ensemble selection
15
+ - OOF prediction utilities
16
+ - Weight optimization with simplex projection
17
+ - 60 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
@@ -0,0 +1,5 @@
1
+ @wlearn/ensemble
2
+
3
+ Copyright (c) 2026 Anton Zemlyansky and contributors
4
+
5
+ This package is part of the wlearn project and is licensed under the Apache License, Version 2.0.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # @wlearn/ensemble
2
+
3
+ Ensemble methods for wlearn: voting, stacking, bagging, and Caruana greedy selection.
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/ensemble
11
+ ```
12
+
13
+ ## Voting
14
+
15
+ Combine multiple models by averaging predictions (soft) or majority vote (hard).
16
+
17
+ ```js
18
+ const { VotingEnsemble } = require('@wlearn/ensemble')
19
+ const { LinearModel } = require('@wlearn/liblinear')
20
+ const { XGBModel } = require('@wlearn/xgboost')
21
+
22
+ const ens = await VotingEnsemble.create({
23
+ estimators: [
24
+ ['linear', LinearModel, { task: 'classification' }],
25
+ ['xgb', XGBModel, { task: 'classification' }]
26
+ ],
27
+ voting: 'soft',
28
+ task: 'classification'
29
+ })
30
+
31
+ ens.fit(X, y)
32
+ const preds = ens.predict(X_test)
33
+ const acc = ens.score(X_test, y_test)
34
+
35
+ ens.dispose()
36
+ ```
37
+
38
+ ## Stacking
39
+
40
+ Train base models, collect out-of-fold predictions, then train a meta-learner on those predictions.
41
+
42
+ ```js
43
+ const { StackingEnsemble } = require('@wlearn/ensemble')
44
+ const { LinearModel } = require('@wlearn/liblinear')
45
+ const { XGBModel } = require('@wlearn/xgboost')
46
+
47
+ const stack = await StackingEnsemble.create({
48
+ estimators: [
49
+ ['xgb', XGBModel, { task: 'classification' }],
50
+ ['linear', LinearModel, { task: 'classification' }]
51
+ ],
52
+ finalEstimator: ['meta', LinearModel, { task: 'classification' }],
53
+ cv: 5,
54
+ task: 'classification'
55
+ })
56
+
57
+ stack.fit(X, y)
58
+ const preds = stack.predict(X_test)
59
+
60
+ stack.dispose()
61
+ ```
62
+
63
+ ## Bagging
64
+
65
+ Bootstrap aggregating: train multiple copies of the same model on bootstrap samples.
66
+
67
+ ```js
68
+ const { BaggedEstimator } = require('@wlearn/ensemble')
69
+ const { LinearModel } = require('@wlearn/liblinear')
70
+
71
+ const bag = await BaggedEstimator.create({
72
+ estimator: ['linear', LinearModel, { task: 'classification' }],
73
+ nEstimators: 10,
74
+ task: 'classification'
75
+ })
76
+
77
+ bag.fit(X, y)
78
+ const preds = bag.predict(X_test)
79
+
80
+ bag.dispose()
81
+ ```
82
+
83
+ ## Utilities
84
+
85
+ - `caruanaSelect(oofPredictions, yTrue, opts?)` -- Caruana greedy ensemble selection
86
+ - `getOofPredictions(estimatorSpecs, X, y, opts?)` -- compute out-of-fold predictions
87
+ - `optimizeWeights(oofPredictions, yTrue, opts?)` -- optimize ensemble weights
88
+ - `projectSimplex(weights)` -- project weights onto probability simplex
89
+
90
+ ## License
91
+
92
+ Apache-2.0
@@ -0,0 +1 @@
1
+ var ensemble=(()=>{var x=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var k=x((Yr,kt)=>{var O=class extends Error{constructor(t,n){super(t),this.name="WlearnError",this.code=n||"ERR_WLEARN"}},rt=class extends O{constructor(t){super(t,"ERR_BUNDLE"),this.name="BundleError"}},ot=class extends O{constructor(t){super(t,"ERR_REGISTRY"),this.name="RegistryError"}},it=class extends O{constructor(t){super(t,"ERR_VALIDATION"),this.name="ValidationError"}},at=class extends O{constructor(t="Model is not fitted. Call fit() first."){super(t,"ERR_NOT_FITTED"),this.name="NotFittedError"}},ct=class extends O{constructor(t="Model has been disposed."){super(t,"ERR_DISPOSED"),this.name="DisposedError"}};kt.exports={WlearnError:O,BundleError:rt,RegistryError:ot,ValidationError:it,NotFittedError:at,DisposedError:ct}});var U=x((Tr,Mt)=>{var{ValidationError:M}=k();function as(s,t="auto"){if(s&&typeof s=="object"&&!Array.isArray(s)&&s.data){let{data:n,rows:e,cols:o}=s;if(!(n instanceof Float64Array)){if(t==="error")throw new M("Expected Float64Array in typed matrix");return{data:new Float64Array(n),rows:e,cols:o}}return{data:n,rows:e,cols:o}}if(Array.isArray(s)&&Array.isArray(s[0])){if(t==="error")throw new M('Input coercion disabled (coerce: "error"). Pass { data: Float64Array, rows, cols } instead of number[][].');let n=s.length,e=s[0].length,o=new Float64Array(n*e);for(let r=0;r<n;r++)for(let i=0;i<e;i++)o[r*e+i]=s[r][i];if(t==="warn"){let r=o.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:o,rows:n,cols:e}}throw new M("X must be number[][] or { data: Float64Array, rows, cols }")}function cs(s){return s instanceof Int32Array||s instanceof Float32Array||s instanceof Float64Array?s:new Float64Array(s)}function ls(s,t,n){if(!t||!n||t<1||n<1)throw new M(`Invalid dimensions: rows=${t}, cols=${n}`);if(!(s instanceof Float32Array)&&!(s instanceof Float64Array))throw new M("data must be Float32Array or Float64Array");if(s.length!==t*n)throw new M(`data.length (${s.length}) !== rows * cols (${t*n})`);return{data:s,rows:t,cols:n}}function fs(s){if(!s||typeof s!="object")throw new M("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 M(`Invalid dimensions: rows=${n}, cols=${e}`);if(!(t instanceof Float32Array)&&!(t instanceof Float64Array))throw new M("data must be Float32Array or Float64Array");if(t.length!==n*e)throw new M(`data.length (${t.length}) !== rows * cols (${n*e})`);return s}Mt.exports={normalizeX:as,normalizeY:cs,makeDense:ls,validateMatrix:fs}});var lt=x((Cr,qt)=>{var hs=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]),N=new Uint32Array(64);function q(s,t){return s>>>t|s<<32-t}function us(s,t,n){for(let l=0;l<16;l++)N[l]=(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0,n+=4;for(let l=16;l<64;l++){let d=q(N[l-15],7)^q(N[l-15],18)^N[l-15]>>>3,u=q(N[l-2],17)^q(N[l-2],19)^N[l-2]>>>10;N[l]=N[l-16]+d+N[l-7]+u>>>0}let e=s[0],o=s[1],r=s[2],i=s[3],a=s[4],f=s[5],h=s[6],c=s[7];for(let l=0;l<64;l++){let d=q(a,6)^q(a,11)^q(a,25),u=a&f^~a&h,p=c+d+u+hs[l]+N[l]>>>0,m=q(e,2)^q(e,13)^q(e,22),w=e&o^e&r^o&r,b=m+w>>>0;c=h,h=f,f=a,a=i+p>>>0,i=r,r=o,o=e,e=p+b>>>0}s[0]=s[0]+e>>>0,s[1]=s[1]+o>>>0,s[2]=s[2]+r>>>0,s[3]=s[3]+i>>>0,s[4]=s[4]+a>>>0,s[5]=s[5]+f>>>0,s[6]=s[6]+h>>>0,s[7]=s[7]+c>>>0}function ds(s){let t=s instanceof Uint8Array?s:new Uint8Array(s),n=t.length,e=n*8,o=n+9+63&-64,r=new Uint8Array(o);r.set(t),r[n]=128;let i=new DataView(r.buffer);i.setUint32(o-4,e>>>0,!1),e>4294967295&&i.setUint32(o-8,e/4294967296>>>0,!1);let a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);for(let h=0;h<o;h+=64)us(a,r,h);let f="";for(let h=0;h<8;h++)f+=a[h].toString(16).padStart(8,"0");return f}qt.exports={sha256Sync:ds}});var $t=x((Wr,_t)=>{var ps=new Uint8Array([87,76,82,78]),ms=1,ws=16,gs={FLOAT32:"float32",FLOAT64:"float64",INT32:"int32"};_t.exports={BUNDLE_MAGIC:ps,BUNDLE_VERSION:ms,HEADER_SIZE:ws,DTYPE:gs}});var C=x((Jr,Dt)=>{var{BUNDLE_MAGIC:Ot,BUNDLE_VERSION:G,HEADER_SIZE:I}=$t(),{BundleError:$}=k(),{sha256Sync:Lt}=lt();function T(s){return s==null||typeof s!="object"?JSON.stringify(s):Array.isArray(s)?"["+s.map(n=>T(n)).join(",")+"]":"{"+Object.keys(s).sort().map(n=>JSON.stringify(n)+":"+T(s[n])).join(",")+"}"}var ft=new TextEncoder,ht=new TextDecoder;function bs(s,t){let n=[...t].sort((u,p)=>u.id<p.id?-1:u.id>p.id?1:0),e=0,o=[],r=[];for(let u of n){let p=u.data instanceof Uint8Array?u.data:new Uint8Array(u.data),m=Lt(p),w={id:u.id,offset:e,length:p.length,sha256:m};u.mediaType&&(w.mediaType=u.mediaType),o.push(w),r.push(p),e+=p.length}let i={...s,bundleVersion:G},a=ft.encode(T(i)),f=ft.encode(T(o)),h=I+a.length+f.length+e,c=new Uint8Array(h),l=new DataView(c.buffer);c.set(Ot,0),l.setUint32(4,G,!0),l.setUint32(8,a.length,!0),l.setUint32(12,f.length,!0),c.set(a,I),c.set(f,I+a.length);let d=I+a.length+f.length;for(let u of r)c.set(u,d),d+=u.length;return c}function Bt(s){let t=s instanceof Uint8Array?s:new Uint8Array(s);if(t.length<I)throw new $(`Bundle too small: ${t.length} bytes (minimum ${I})`);for(let l=0;l<4;l++)if(t[l]!==Ot[l])throw new $("Invalid bundle magic (expected WLRN)");let n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=n.getUint32(4,!0);if(e!==G)throw new $(`Unsupported bundle version: ${e} (expected ${G})`);let o=n.getUint32(8,!0),r=n.getUint32(12,!0);if(I+o+r>t.length)throw new $(`Bundle truncated: header declares ${I+o+r} bytes but got ${t.length}`);let i,a;try{i=JSON.parse(ht.decode(t.subarray(I,I+o)))}catch(l){throw new $(`Invalid manifest JSON: ${l.message}`)}try{a=JSON.parse(ht.decode(t.subarray(I+o,I+o+r)))}catch(l){throw new $(`Invalid TOC JSON: ${l.message}`)}let f=I+o+r,h=t.length-f;for(let l=0;l<a.length;l++){let d=a[l];if(d.offset<0||d.length<0||d.offset+d.length>h)throw new $(`TOC entry "${d.id}" out of bounds: offset=${d.offset}, length=${d.length}, blobRegion=${h}`);for(let u=l+1;u<a.length;u++){let p=a[u],m=d.offset,w=d.offset+d.length,b=p.offset,g=p.offset+p.length;if(m<g&&b<w&&d.length>0&&p.length>0)throw new $(`TOC entries "${d.id}" and "${p.id}" overlap`)}}let c=t.subarray(f);return{manifest:i,toc:a,blobs:c}}function ys(s){return ft.encode(T(s))}function xs(s){let t=s instanceof Uint8Array?s:new Uint8Array(s);return JSON.parse(ht.decode(t))}function As(s){let{manifest:t,toc:n,blobs:e}=Bt(s);for(let o of n){let r=e.subarray(o.offset,o.offset+o.length),i=Lt(r);if(i!==o.sha256)throw new $(`SHA-256 mismatch for "${o.id}": expected ${o.sha256}, got ${i}`)}return{manifest:t,toc:n,blobs:e}}Dt.exports={encodeBundle:bs,decodeBundle:Bt,encodeJSON:ys,decodeJSON:xs,validateBundle:As}});var K=x((Gr,Rt)=>{var{RegistryError:D}=k(),{decodeBundle:zt}=C(),V=new Map;function Fs(s,t){if(typeof s!="string"||!s.includes("@"))throw new D(`Invalid typeId "${s}": must contain "@" (e.g. "wlearn.liblinear.classifier@1")`);if(typeof t!="function")throw new D("loaderFn must be a function");V.set(s,t)}async function Ss(s){let{manifest:t,toc:n,blobs:e}=zt(s),{typeId:o}=t;if(!o)throw new D("Bundle manifest missing typeId");let r=V.get(o);if(!r){let i=[...V.keys()],a=i.length>0?`Registered loaders: ${i.join(", ")}`:"No loaders registered";throw new D(`No loader registered for typeId "${o}". ${a}. Install the corresponding @wlearn/* package and import it to register the loader.`)}return await r(t,n,e)}function Es(s){let{manifest:t,toc:n,blobs:e}=zt(s),{typeId:o}=t;if(!o)throw new D("Bundle manifest missing typeId");let r=V.get(o);if(!r){let a=[...V.keys()],f=a.length>0?`Registered loaders: ${a.join(", ")}`:"No loaders registered";throw new D(`No loader registered for typeId "${o}". ${f}. Install the corresponding @wlearn/* package and import it to register the loader.`)}let i=r(t,n,e);if(i&&typeof i.then=="function")throw new D(`Loader for "${o}" returned a Promise. Use async load() instead of loadSync().`);return i}function Is(){return new Map(V)}Rt.exports={register:Fs,load:Ss,loadSync:Es,getRegistry:Is}});var dt=x((Kr,jt)=>{var ut=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"}};jt.exports={Step:ut}});var Tt=x((Hr,Yt)=>{var{Step:Ps}=dt(),{DisposedError:vs,NotFittedError:Ns,ValidationError:H}=k(),{encodeBundle:ks,decodeBundle:Ms}=C(),{register:qs,load:Ut}=K(),Vt="wlearn.pipeline@1",Xt=!1,Z=class s{#t;#e=!1;#r=!1;constructor(t){if(this.#t=t.map(([n,e])=>new Ps(n,e)),this.#t.length===0)throw new H("Pipeline requires at least one step")}#n(){if(this.#r)throw new vs("Pipeline has been disposed.")}#o(){if(this.#n(),!this.#e)throw new Ns("Pipeline is not fitted. Call fit() first.")}#s(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 i=this.#t[r].estimator;typeof i.fitTransform=="function"?e=i.fitTransform(e,n):(i.fit(e,n),e=i.transform(e))}return this.#t[this.#t.length-1].estimator.fit(e,n),this.#e=!0,this}predict(t){this.#o();let n=this.#s(t);return this.#t[this.#t.length-1].estimator.predict(n)}predictProba(t){this.#o();let n=this.#t[this.#t.length-1].estimator;if(typeof n.predictProba!="function")throw new H("Last step does not support predictProba");let e=this.#s(t);return n.predictProba(e)}score(t,n){this.#o();let e=this.#s(t);return this.#t[this.#t.length-1].estimator.score(e,n)}save(){this.#o();let t={typeId:Vt,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 ks(t,n)}static async load(t){let{manifest:n,toc:e,blobs:o}=Ms(t),r=[];for(let a of n.steps){let f=e.find(l=>l.id===a.name);if(!f)throw new H(`No artifact found for pipeline step "${a.name}"`);let h=o.subarray(f.offset,f.offset+f.length),c=await Ut(h);r.push([a.name,c])}let i=new s(r);return i.#e=!0,i}dispose(){if(!this.#r){this.#r=!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(){Xt||(Xt=!0,qs(Vt,(t,n,e)=>s._loadFromParts(t,n,e)))}static async _loadFromParts(t,n,e){let o=[];for(let i of t.steps){let a=n.find(c=>c.id===i.name);if(!a)throw new H(`No artifact found for pipeline step "${i.name}"`);let f=e.subarray(a.offset,a.offset+a.length),h=await Ut(f);o.push([i.name,h])}let r=new s(o);return r.#e=!0,r}};Z.registerLoader();Yt.exports={Pipeline:Z}});var Gt=x((Qr,Jt)=>{var{normalizeX:Ct,normalizeY:Zr}=U(),{ValidationError:Wt}=k(),pt=class s{#t;#e=!1;#r=null;#n=null;#o=null;#s=null;#i=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=Ct(t),{data:o,rows:r,cols:i}=e;this.#r=new Array(i),this.#n=new Float64Array(i);let a=new Array(i);for(let h=0;h<i;h++){let c=[],l=!1,d=0,u=0;for(let b=0;b<r;b++){let g=o[b*i+h];Number.isNaN(g)?l=!0:(c.push(g),d+=g,u++)}let p=new Set(c),m=c.every(b=>b===Math.floor(b)),w=this.#t.encode!==!1&&m&&p.size<=this.#t.maxCategories&&p.size>=2;if(this.#r[h]=w?"categorical":"numeric",this.#t.impute!==!1&&l)if(w){let b=new Map;for(let F of c)b.set(F,(b.get(F)||0)+1);let g=c[0],y=0;for(let[F,E]of b)E>y&&(g=F,y=E);this.#n[h]=g}else this.#n[h]=u>0?d/u:0;a[h]={values:c,unique:p,sum:d,count:u}}this.#o=new Array(i).fill(null);let f=0;if(this.#t.encode!==!1)for(let h=0;h<i;h++)if(this.#r[h]==="categorical"){let c=[...a[h].unique].sort((l,d)=>l-d);if(this.#t.encode==="label"||this.#t.encode===!1){let l=new Map;c.forEach((d,u)=>l.set(d,u)),this.#o[h]={type:"label",mapping:l,startIdx:f},f++}else{let l=new Map;c.forEach((d,u)=>l.set(d,f+u)),this.#o[h]={type:"onehot",mapping:l,startIdx:f,size:c.length},f+=c.length}}else f++;else f=i;if(this.#i=f,this.#s=new Array(this.#i).fill(null),this.#t.scale){let h=0;for(let c=0;c<i;c++){if(this.#r[c]==="categorical"&&this.#t.encode!==!1){let d=this.#o[c];h+=d.type==="onehot"?d.size:1;continue}let l=a[c].values;if(this.#t.scale==="standard"){let d=a[c].sum/(a[c].count||1),u=0;for(let m of l)u+=(m-d)**2;u/=l.length||1;let p=Math.sqrt(u);this.#s[h]={mean:d,std:p||1}}else if(this.#t.scale==="minmax"){let d=1/0,u=-1/0;for(let m of l)m<d&&(d=m),m>u&&(u=m);let p=u-d||1;this.#s[h]={min:d,range:p}}h++}}return this.#e=!0,this}transform(t){if(!this.#e)throw new Wt("Preprocessor not fitted");let n=Ct(t),{data:e,rows:o,cols:r}=n,i=this.#i,a=new Float64Array(o*i);for(let f=0;f<o;f++){let h=0;for(let c=0;c<r;c++){let l=e[f*r+c];if(Number.isNaN(l)&&this.#t.impute!==!1&&(l=this.#n[c]),this.#r[c]==="categorical"&&this.#o[c]){let d=this.#o[c];if(d.type==="onehot"){let u=d.mapping.get(l);u!==void 0&&(a[f*i+u]=1),h=d.startIdx+d.size}else{let u=d.mapping.get(l);a[f*i+h]=u!==void 0?u:-1,h++}}else a[f*i+h]=l,h++}if(this.#t.scale)for(let c=0;c<i;c++){let l=this.#s[c];l&&(this.#t.scale==="standard"?a[f*i+c]=(a[f*i+c]-l.mean)/l.std:this.#t.scale==="minmax"&&(a[f*i+c]=(a[f*i+c]-l.min)/l.range))}}return{data:a,rows:o,cols:i}}fitTransform(t,n){return this.fit(t,n),this.transform(t)}getState(){if(!this.#e)throw new Wt("Preprocessor not fitted");return{config:this.#t,colTypes:this.#r,imputeValues:[...this.#n],encodings:this.#o.map(t=>t?{type:t.type,mapping:[...t.mapping.entries()],startIdx:t.startIdx,size:t.size}:null),scaleParams:this.#s,outputCols:this.#i}}static fromState(t){let n=new s(t.config);return n.#r=t.colTypes,n.#n=new Float64Array(t.imputeValues),n.#o=t.encodings.map(e=>e?{type:e.type,mapping:new Map(e.mapping),startIdx:e.startIdx,size:e.size}:null),n.#s=t.scaleParams,n.#i=t.outputCols,n.#e=!0,n}get isFitted(){return this.#e}get outputCols(){return this.#i}get capabilities(){return{transformer:!0}}dispose(){}};Jt.exports={Preprocessor:pt}});var oe=x((to,re)=>{var{NotFittedError:Kt,DisposedError:Ht,ValidationError:X}=k(),{normalizeX:Q}=U(),{encodeBundle:Zt,encodeJSON:Qt,decodeJSON:te}=C(),{register:ee}=K(),se="wlearn.preprocess.standard_scaler@1",ne="wlearn.preprocess.minmax_scaler@1",tt=class s{#t=null;#e=null;#r=!1;#n=!1;#o={};constructor(t={}){this.#o={...t}}fit(t){this.#s();let{rows:n,cols:e,data:o}=Q(t);if(n===0)throw new X("Cannot fit on empty data");let r=new Float64Array(e),i=new Float64Array(e);for(let f=0;f<n;f++){let h=f+1;for(let c=0;c<e;c++){let l=o[f*e+c],d=l-r[c];r[c]+=d/h;let u=l-r[c];i[c]+=d*u}}let a=new Float64Array(e);for(let f=0;f<e;f++)a[f]=n>1?Math.sqrt(i[f]/(n-1)):0;return this.#t=r,this.#e=a,this.#r=!0,this}transform(t){this.#i();let{rows:n,cols:e,data:o}=Q(t);if(e!==this.#t.length)throw new X(`Expected ${this.#t.length} columns, got ${e}`);let r=new Float64Array(n*e);for(let i=0;i<n;i++)for(let a=0;a<e;a++){let f=i*e+a,h=this.#e[a];r[f]=h>0?(o[f]-this.#t[a])/h:0}return{rows:n,cols:e,data:r}}fitTransform(t){return this.fit(t),this.transform(t)}save(){this.#i();let t={means:Array.from(this.#t),stds:Array.from(this.#e)};return Zt({typeId:se,params:this.getParams()},[{id:"params",data:Qt(t),mediaType:"application/json"}])}static _fromBundle(t,n,e){let o=n.find(a=>a.id==="params");if(!o)throw new X('Bundle missing "params" artifact');let r=te(e.subarray(o.offset,o.offset+o.length)),i=new s(t.params||{});return i.#t=new Float64Array(r.means),i.#e=new Float64Array(r.stds),i.#r=!0,i}dispose(){this.#n||(this.#n=!0,this.#t=null,this.#e=null,this.#r=!1)}getParams(){return{...this.#o}}setParams(t){return Object.assign(this.#o,t),this}get isFitted(){return this.#r&&!this.#n}#s(){if(this.#n)throw new Ht("StandardScaler has been disposed.")}#i(){if(this.#s(),!this.#r)throw new Kt("StandardScaler is not fitted.")}},et=class s{#t=null;#e=null;#r=!1;#n=!1;#o={};constructor(t={}){this.#o={...t}}fit(t){this.#s();let{rows:n,cols:e,data:o}=Q(t);if(n===0)throw new X("Cannot fit on empty data");let r=new Float64Array(e).fill(1/0),i=new Float64Array(e).fill(-1/0);for(let a=0;a<n;a++)for(let f=0;f<e;f++){let h=o[a*e+f];h<r[f]&&(r[f]=h),h>i[f]&&(i[f]=h)}return this.#t=r,this.#e=i,this.#r=!0,this}transform(t){this.#i();let{rows:n,cols:e,data:o}=Q(t);if(e!==this.#t.length)throw new X(`Expected ${this.#t.length} columns, got ${e}`);let r=new Float64Array(n*e);for(let i=0;i<n;i++)for(let a=0;a<e;a++){let f=i*e+a,h=this.#e[a]-this.#t[a];r[f]=h>0?(o[f]-this.#t[a])/h:0}return{rows:n,cols:e,data:r}}fitTransform(t){return this.fit(t),this.transform(t)}save(){this.#i();let t={mins:Array.from(this.#t),maxs:Array.from(this.#e)};return Zt({typeId:ne,params:this.getParams()},[{id:"params",data:Qt(t),mediaType:"application/json"}])}static _fromBundle(t,n,e){let o=n.find(a=>a.id==="params");if(!o)throw new X('Bundle missing "params" artifact');let r=te(e.subarray(o.offset,o.offset+o.length)),i=new s(t.params||{});return i.#t=new Float64Array(r.mins),i.#e=new Float64Array(r.maxs),i.#r=!0,i}dispose(){this.#n||(this.#n=!0,this.#t=null,this.#e=null,this.#r=!1)}getParams(){return{...this.#o}}setParams(t){return Object.assign(this.#o,t),this}get isFitted(){return this.#r&&!this.#n}#s(){if(this.#n)throw new Ht("MinMaxScaler has been disposed.")}#i(){if(this.#s(),!this.#r)throw new Kt("MinMaxScaler is not fitted.")}};ee(se,tt._fromBundle);ee(ne,et._fromBundle);re.exports={StandardScaler:tt,MinMaxScaler:et}});var mt=x((eo,ie)=>{function _s(s=42){let t=s|0;return()=>(t=t*1664525+1013904223&2147483647,t/2147483647)}function $s(s,t){for(let n=s.length-1;n>0;n--){let e=t()*(n+1)|0,o=s[n];s[n]=s[e],s[e]=o}return s}ie.exports={makeLCG:_s,shuffle:$s}});var bt=x((so,ae)=>{var{ValidationError:L}=k();function B(s,t,n){if(!s||!t||s.length===0||t.length===0)throw new L(`${n}: inputs must be non-empty`);if(s.length!==t.length)throw new L(`${n}: length mismatch (${s.length} vs ${t.length})`)}function Y(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,i)=>r-i)),o=new Map;for(let r=0;r<e.length;r++)o.set(e[r],r);return{labels:e,labelMap:o,nClasses:e.length}}function st(s,t,n,e){let o=new Int32Array(e*e);for(let r=0;r<s.length;r++){let i=n.get(s[r]),a=n.get(t[r]);o[i*e+a]++}return o}function wt(s,t){let n=new Float64Array(t),e=new Float64Array(t),o=new Float64Array(t);for(let r=0;r<t;r++){n[r]=s[r*t+r];for(let i=0;i<t;i++)i!==r&&(e[r]+=s[i*t+r],o[r]+=s[r*t+i])}return{tp:n,fp:e,fn:o}}function Os(s,t){B(s,t,"accuracy");let n=0;for(let e=0;e<s.length;e++)s[e]===t[e]&&n++;return n/s.length}function Ls(s,t){B(s,t,"r2Score");let n=s.length,e=0;for(let i=0;i<n;i++)e+=s[i];e/=n;let o=0,r=0;for(let i=0;i<n;i++){let a=s[i]-e;o+=a*a;let f=s[i]-t[i];r+=f*f}return o===0?0:1-r/o}function Bs(s,t){B(s,t,"meanSquaredError");let n=0;for(let e=0;e<s.length;e++){let o=s[e]-t[e];n+=o*o}return n/s.length}function Ds(s,t){B(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 zs(s,t){B(s,t,"confusionMatrix");let{labels:n,labelMap:e,nClasses:o}=Y(s,t);return{matrix:st(s,t,e,o),labels:n}}function gt(s,t,n){if(s==="binary"){if(t>2)throw new L('average="binary" requires exactly 2 classes');return"binary"}return s||"binary"}function Rs(s,t,{average:n="binary"}={}){B(s,t,"precisionScore");let{labels:e,labelMap:o,nClasses:r}=Y(s,t),i=st(s,t,o,r),{tp:a,fp:f}=wt(i,r),h=gt(n,r,e);if(h==="binary"){let l=r-1,d=a[l]+f[l];return d===0?0:a[l]/d}if(h==="micro"){let l=0,d=0;for(let u=0;u<r;u++)l+=a[u],d+=f[u];return l+d===0?0:l/(l+d)}let c=0;for(let l=0;l<r;l++){let d=a[l]+f[l];c+=d===0?0:a[l]/d}return c/r}function js(s,t,{average:n="binary"}={}){B(s,t,"recallScore");let{labels:e,labelMap:o,nClasses:r}=Y(s,t),i=st(s,t,o,r),{tp:a,fn:f}=wt(i,r),h=gt(n,r,e);if(h==="binary"){let l=r-1,d=a[l]+f[l];return d===0?0:a[l]/d}if(h==="micro"){let l=0,d=0;for(let u=0;u<r;u++)l+=a[u],d+=f[u];return l+d===0?0:l/(l+d)}let c=0;for(let l=0;l<r;l++){let d=a[l]+f[l];c+=d===0?0:a[l]/d}return c/r}function Us(s,t,{average:n="binary"}={}){B(s,t,"f1Score");let{labels:e,labelMap:o,nClasses:r}=Y(s,t),i=st(s,t,o,r),{tp:a,fp:f,fn:h}=wt(i,r),c=gt(n,r,e);function l(u,p,m){let w=u+p===0?0:u/(u+p),b=u+m===0?0:u/(u+m);return w+b===0?0:2*w*b/(w+b)}if(c==="binary"){let u=r-1;return l(a[u],f[u],h[u])}if(c==="micro"){let u=0,p=0,m=0;for(let w=0;w<r;w++)u+=a[w],p+=f[w],m+=h[w];return l(u,p,m)}let d=0;for(let u=0;u<r;u++)d+=l(a[u],f[u],h[u]);return d/r}function Vs(s,t,{nClasses:n,eps:e=1e-15}={}){if(!s||s.length===0)throw new L("logLoss: yTrue must be non-empty");let o=s.length;if(!n){let a=new Set;for(let f=0;f<o;f++)a.add(s[f]);n=a.size}if(t.length!==o*n)throw new L(`logLoss: yProba length (${t.length}) must be n * nClasses (${o*n})`);let{labelMap:r}=Y(s),i=0;for(let a=0;a<o;a++){let f=r.get(s[a]),h=t[a*n+f];h=Math.max(e,Math.min(1-e,h)),i-=Math.log(h)}return i/o}function Xs(s,t){if(!s||s.length===0)throw new L("rocAuc: yTrue must be non-empty");if(s.length!==t.length)throw new L("rocAuc: length mismatch");let{labels:n}=Y(s);if(n.length!==2)throw new L("rocAuc: requires exactly 2 classes");let e=n[n.length-1],o=s.length,r=Array.from({length:o},(u,p)=>p);r.sort((u,p)=>t[p]-t[u]);let i=0,a=0;for(let u=0;u<o;u++)s[u]===e?i++:a++;if(i===0||a===0)return 0;let f=0,h=0,c=0,l=0,d=0;for(let u=0;u<o;u++){let p=r[u];s[p]===e?f++:h++;let m=f/i,w=h/a;d+=(w-l)*(m+c)/2,c=m,l=w}return d}ae.exports={accuracy:Os,r2Score:Ls,meanSquaredError:Bs,meanAbsoluteError:Ds,confusionMatrix:zs,precisionScore:Rs,recallScore:js,f1Score:Us,logLoss:Vs,rocAuc:Xs}});var pe=x((no,de)=>{var{ValidationError:z}=k(),{makeLCG:yt,shuffle:xt}=mt(),{normalizeX:Ys,normalizeY:Ts}=U(),{accuracy:Cs,r2Score:Ws,meanSquaredError:Js,meanAbsoluteError:Gs}=bt(),ce={accuracy:(s,t)=>Cs(s,t),r2:(s,t)=>Ws(s,t),neg_mse:(s,t)=>-Js(s,t),neg_mae:(s,t)=>-Gs(s,t)};function he(s){if(typeof s=="function")return s;let t=ce[s];if(!t)throw new z(`Unknown scoring: "${s}". Available: ${Object.keys(ce).join(", ")}`);return t}function Ks(s,t=5,{shuffle:n=!0,seed:e=42}={}){if(s<t)throw new z(`kFold: n (${s}) must be >= k (${t})`);if(t<2)throw new z("kFold: k must be >= 2");let o=Int32Array.from({length:s},(h,c)=>c);if(n){let h=yt(e);xt(o,h)}let r=Math.floor(s/t),i=s%t,a=[],f=0;for(let h=0;h<t;h++){let c=r+(h<i?1:0),l=o.slice(f,f+c),d=[];f>0&&d.push(o.slice(0,f)),f+c<s&&d.push(o.slice(f+c));let u=Qs(d);a.push({train:u,test:l}),f+=c}return a}function ue(s,t=5,{shuffle:n=!0,seed:e=42}={}){let o=s.length;if(o<t)throw new z(`stratifiedKFold: n (${o}) must be >= k (${t})`);if(t<2)throw new z("stratifiedKFold: k must be >= 2");let r=new Map;for(let h=0;h<o;h++){let c=s[h];r.has(c)||r.set(c,[]),r.get(c).push(h)}if(n){let h=yt(e);for(let c of r.values())xt(c,h)}let i=Array.from({length:t},()=>[]);for(let h of r.values())for(let c=0;c<h.length;c++)i[c%t].push(h[c]);let a=Int32Array.from({length:o},(h,c)=>c),f=[];for(let h=0;h<t;h++){let c=new Set(i[h]),l=new Int32Array(i[h]),d=a.filter(u=>!c.has(u));f.push({train:d,test:l})}return f}function Hs(s,{testSize:t=.2,shuffle:n=!0,seed:e=42}={}){if(s<2)throw new z("trainTestSplit: n must be >= 2");let o=Math.max(1,Math.round(s*t)),r=s-o;if(r<1)throw new z("trainTestSplit: testSize too large");let i=Int32Array.from({length:s},(a,f)=>f);if(n){let a=yt(e);xt(i,a)}return{train:i.slice(0,r),test:i.slice(r)}}async function Zs(s,t,n,{cv:e=5,scoring:o="accuracy",seed:r=42,params:i={}}={}){let a=Ys(t),f=Ts(n),h=he(o),c;Array.isArray(e)?c=e:c=ue(f,e,{shuffle:!0,seed:r});let l=new Float64Array(c.length);for(let d=0;d<c.length;d++){let{train:u,test:p}=c[d],m=le(a,u),w=fe(f,u),b=le(a,p),g=fe(f,p),y=await s.create(i);try{y.fit(m,w);let F=await y.predict(b);l[d]=h(g,F)}finally{y.dispose()}}return l}function Qs(s){let t=0;for(let o of s)t+=o.length;let n=new Int32Array(t),e=0;for(let o of s)n.set(o,e),e+=o.length;return n}function le(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function fe(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}de.exports={kFold:Ks,stratifiedKFold:ue,trainTestSplit:Hs,crossValScore:Zs,getScorer:he}});var ge=x((ro,we)=>{function me(s){return s!=null&&typeof s.then=="function"}function tn(s,t){return me(s)?s.then(t):t(s)}we.exports={isPromiseLike:me,lift:tn}});var Ae=x((oo,xe)=>{var{normalizeY:en}=U(),{round:sn}=Math;function be(s){let t=en(s);if(t instanceof Int32Array)return"classification";let n=new Set;for(let e=0;e<t.length;e++){if(t[e]!==sn(t[e]))return"regression";n.add(t[e])}return n.size<=20?"classification":"regression"}var ye=new WeakMap;function P(s){let t=ye.get(s);if(!t)throw new Error("Model: invalid instance");return t}function W(s,t){let n=P(s);if(n.disposed)throw new Error(`${t} has been disposed.`);if(!n.inner)throw new Error(`${t}: not fitted`);return n.inner}function nn(s,t,n={}){let e=n.name||"Model",o=n.load||null,r=s===t;class i{constructor(c,l){ye.set(this,{inner:null,task:c,params:l,disposed:!1})}static async create(c={}){let l={...c},d=l.task||null;delete l.task,o&&await o();let u=new i(d,l),p=P(u);if(d){let m=d==="classification"?s:t;p.inner=await m.create({...l,task:d})}else r&&(p.inner=await s.create(l));return u}static async load(c){try{let l=await s.load(c),d=new i("classification",{}),u=P(d);return u.inner=l,typeof l.getParams=="function"&&(u.params=l.getParams(),u.params.task&&(u.task=u.params.task)),d}catch{let d=await t.load(c),u=new i("regression",{}),p=P(u);return p.inner=d,typeof d.getParams=="function"&&(p.params=d.getParams(),p.params.task&&(p.task=p.params.task)),u}}fit(c,l,d){let u=P(this);if(u.task||(u.task=be(l)),!u.inner){let p=u.task==="classification"?s:t;u.inner=new p({...u.params,task:u.task})}return u.inner.fit(c,l,d),this}predict(c,l){return W(this,e).predict(c,l)}predictProba(c,l){let d=W(this,e);if(typeof d.predictProba!="function")throw new Error(`${e}: predictProba not available`);return d.predictProba(c,l)}score(c,l,d){return W(this,e).score(c,l,d)}save(){return W(this,e).save()}dispose(){let c=P(this);c.inner&&typeof c.inner.dispose=="function"&&c.inner.dispose(),c.inner=null,c.disposed=!0}getParams(){let c=P(this),l=c.inner&&typeof c.inner.getParams=="function"?c.inner.getParams():{...c.params};return c.task&&(l.task=c.task),l}setParams(c){let l=P(this),d={...c};if(d.task){let u=d.task;delete d.task,u!==l.task&&l.inner&&this.dispose(),l.task=u}return l.params=d,l.inner&&typeof l.inner.setParams=="function"&&l.inner.setParams(d),this}get task(){return P(this).task}get isFitted(){let c=P(this);return c.inner?c.inner.isFitted!==void 0?c.inner.isFitted:!0:!1}get classes(){let c=P(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=P(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"]),f=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)||f.has(c)||c in i.prototype)continue;let l=Object.getOwnPropertyDescriptor(h.prototype,c);l&&(typeof l.value=="function"?i.prototype[c]=function(...d){return W(this,e)[c](...d)}:l.get&&Object.defineProperty(i.prototype,c,{get(){let d=P(this);if(d.inner)return d.inner[c]},configurable:!0}))}return(s.defaultSearchSpace||t.defaultSearchSpace)&&(i.defaultSearchSpace=()=>s.defaultSearchSpace?.()||t.defaultSearchSpace?.()||{}),(s.budgetSpec||t.budgetSpec)&&(i.budgetSpec=()=>s.budgetSpec?.()||t.budgetSpec?.()||void 0),Object.defineProperty(i,"name",{value:e,configurable:!0}),i}xe.exports={createModelClass:nn,detectTask:be}});var R=x((io,Fe)=>{var{WlearnError:rn,BundleError:on,RegistryError:an,ValidationError:cn,NotFittedError:ln,DisposedError:fn}=k(),{normalizeX:hn,normalizeY:un,makeDense:dn,validateMatrix:pn}=U(),{sha256Sync:mn}=lt(),{encodeBundle:wn,decodeBundle:gn,validateBundle:bn,encodeJSON:yn,decodeJSON:xn}=C(),{register:An,load:Fn,loadSync:Sn,getRegistry:En}=K(),{Pipeline:In}=Tt(),{Step:Pn}=dt(),{Preprocessor:vn}=Gt(),{StandardScaler:Nn,MinMaxScaler:kn}=oe(),{makeLCG:Mn,shuffle:qn}=mt(),{accuracy:_n,r2Score:$n,meanSquaredError:On,meanAbsoluteError:Ln,confusionMatrix:Bn,precisionScore:Dn,recallScore:zn,f1Score:Rn,logLoss:jn,rocAuc:Un}=bt(),{kFold:Vn,stratifiedKFold:Xn,trainTestSplit:Yn,crossValScore:Tn,getScorer:Cn}=pe(),{isPromiseLike:Wn,lift:Jn}=ge(),{createModelClass:Gn,detectTask:Kn}=Ae();Fe.exports={WlearnError:rn,BundleError:on,RegistryError:an,ValidationError:cn,NotFittedError:ln,DisposedError:fn,normalizeX:hn,normalizeY:un,makeDense:dn,validateMatrix:pn,sha256Sync:mn,encodeBundle:wn,decodeBundle:gn,validateBundle:bn,encodeJSON:yn,decodeJSON:xn,register:An,load:Fn,loadSync:Sn,getRegistry:En,Pipeline:In,Step:Pn,Preprocessor:vn,StandardScaler:Nn,MinMaxScaler:kn,makeLCG:Mn,shuffle:qn,accuracy:_n,r2Score:$n,meanSquaredError:On,meanAbsoluteError:Ln,confusionMatrix:Bn,precisionScore:Dn,recallScore:zn,f1Score:Rn,logLoss:jn,rocAuc:Un,kFold:Vn,stratifiedKFold:Xn,trainTestSplit:Yn,crossValScore:Tn,getScorer:Cn,isPromiseLike:Wn,lift:Jn,createModelClass:Gn,detectTask:Kn}});var qe=x((ao,Me)=>{var{encodeBundle:Hn,decodeBundle:Zn,register:Se,load:Ee,normalizeX:At,normalizeY:Ie,accuracy:Qn,r2Score:tr,ValidationError:nt,NotFittedError:er,DisposedError:sr,lift:Pe}=R(),ve="wlearn.ensemble.voting.classifier@1",Ne="wlearn.ensemble.voting.regressor@1",ke=!1,Ft=class s{#t;#e;#r;#n;#o;#s;#i=!1;#f=!1;constructor(t){this.#t=t.estimators||[],this.#r=t.weights||null,this.#n=t.voting||"soft",this.#o=t.task||"classification",this.#e=null,this.#s=null,s._register()}static async create(t={}){return new s(t)}#l(){if(this.#f)throw new sr("VotingEnsemble has been disposed.")}#a(){if(this.#l(),!this.#i)throw new er("VotingEnsemble is not fitted. Call fit() first.")}async fit(t,n){this.#l();let e=At(t),o=Ie(n);if(this.#o==="classification"){let r=new Set;for(let i=0;i<o.length;i++)r.add(o[i]);this.#s=new Int32Array([...r].sort((i,a)=>i-a))}this.#r||(this.#r=new Float64Array(this.#t.length).fill(1/this.#t.length)),this.#e=[];for(let[r,i,a]of this.#t){let f=await i.create(a||{});f.fit(e,o),this.#e.push(f)}return this.#i=!0,this}predict(t){this.#a();let n=At(t),e=n.rows;if(this.#o==="regression")return this.#c(n,e);if(this.#n==="soft"){let o=this.predictProba(n);return Pe(o,r=>{let i=this.#s.length,a=new Float64Array(e);for(let f=0;f<e;f++){let h=0,c=-1/0;for(let l=0;l<i;l++)r[f*i+l]>c&&(c=r[f*i+l],h=l);a[f]=this.#s[h]}return a})}return this.#h(n,e)}predictProba(t){if(this.#a(),this.#o!=="classification")throw new nt("predictProba is only available for classification");if(this.#n==="hard")throw new nt('predictProba requires voting="soft"');let n=At(t),e=n.rows,o=this.#s.length,r=[],i=!1;for(let f=0;f<this.#e.length;f++){let h=this.#e[f].predictProba(n);h!=null&&typeof h.then=="function"&&(i=!0),r.push(h)}let a=f=>{let h=new Float64Array(e*o);for(let c=0;c<f.length;c++){let l=f[c],d=this.#r[c];for(let u=0;u<e*o;u++)h[u]+=d*l[u]}return h};return i?Promise.all(r).then(a):a(r)}score(t,n){this.#a();let e=this.predict(t),o=Ie(n),r=this.#o==="classification"?Qn:tr;return Pe(e,i=>r(o,i))}save(){this.#a();let n={typeId:this.#o==="classification"?ve:Ne,params:{task:this.#o,voting:this.#n,weights:[...this.#r],estimatorNames:this.#t.map(o=>o[0]),classes:this.#s?[...this.#s]:null}},e=this.#e.map((o,r)=>({id:this.#t[r][0],data:o.save(),mediaType:"application/x-wlearn-bundle"}));return Hn(n,e)}static async load(t){let{manifest:n,toc:e,blobs:o}=Zn(t),r=n.params,i=new s({task:r.task,voting:r.voting,weights:new Float64Array(r.weights)});i.#s=r.classes?new Int32Array(r.classes):null,i.#t=r.estimatorNames.map(a=>[a,null,null]),i.#e=[];for(let a of r.estimatorNames){let f=e.find(l=>l.id===a);if(!f)throw new nt(`No artifact for estimator "${a}"`);let h=o.subarray(f.offset,f.offset+f.length),c=await Ee(h);i.#e.push(c)}return i.#i=!0,i}dispose(){if(!this.#f&&(this.#f=!0,this.#e))for(let t of this.#e)t.dispose()}getParams(){return{task:this.#o,voting:this.#n,weights:this.#r?[...this.#r]:null,estimatorNames:this.#t.map(t=>t[0])}}setParams(t){return this.#l(),t.voting!==void 0&&(this.#n=t.voting),t.weights!==void 0&&(this.#r=new Float64Array(t.weights)),this}get capabilities(){return{classifier:this.#o==="classification",regressor:this.#o==="regression",predictProba:this.#o==="classification"&&this.#n==="soft",decisionFunction:!1,sampleWeight:!1,csr:!1,earlyStopping:!1}}get isFitted(){return this.#i}get classes(){return this.#s}#c(t,n){let e=[],o=!1;for(let i=0;i<this.#e.length;i++){let a=this.#e[i].predict(t);a!=null&&typeof a.then=="function"&&(o=!0),e.push(a)}let r=i=>{let a=new Float64Array(n);for(let f=0;f<i.length;f++){let h=this.#r[f];for(let c=0;c<n;c++)a[c]+=h*i[f][c]}return a};return o?Promise.all(e).then(r):r(e)}#h(t,n){let e=[],o=!1;for(let i=0;i<this.#e.length;i++){let a=this.#e[i].predict(t);a!=null&&typeof a.then=="function"&&(o=!0),e.push(a)}let r=i=>{let a=this.#s.length,f=new Float64Array(n);for(let h=0;h<n;h++){let c=new Float64Array(a);for(let u=0;u<i.length;u++){let p=i[u][h],m=this.#s.indexOf(p);m>=0&&(c[m]+=this.#r[u])}let l=0,d=-1/0;for(let u=0;u<a;u++)c[u]>d&&(d=c[u],l=u);f[h]=this.#s[l]}return f};return o?Promise.all(e).then(r):r(e)}static _register(){if(ke)return;ke=!0;let t=(n,e,o)=>s._loadFromParts(n,e,o);Se(ve,t),Se(Ne,t)}static async _loadFromParts(t,n,e){let o=t.params,r=new s({task:o.task,voting:o.voting,weights:new Float64Array(o.weights)});r.#s=o.classes?new Int32Array(o.classes):null,r.#t=o.estimatorNames.map(i=>[i,null,null]),r.#e=[];for(let i of o.estimatorNames){let a=n.find(c=>c.id===i);if(!a)throw new nt(`No artifact for estimator "${i}"`);let f=e.subarray(a.offset,a.offset+a.length),h=await Ee(f);r.#e.push(h)}return r.#i=!0,r}};Me.exports={VotingEnsemble:Ft}});var Ue=x((co,je)=>{var{encodeBundle:nr,decodeBundle:rr,register:_e,load:$e,normalizeX:Oe,normalizeY:Le,accuracy:or,r2Score:ir,stratifiedKFold:ar,kFold:cr,ValidationError:J,NotFittedError:lr,DisposedError:fr,lift:St}=R(),Be="wlearn.ensemble.stacking.classifier@1",De="wlearn.ensemble.stacking.regressor@1",ze=!1,Et=class s{#t;#e;#r;#n;#o;#s;#i;#f;#l;#a;#c;#h=!1;#d=!1;constructor(t){this.#t=t.estimators||[],this.#e=t.finalEstimator||null,this.#o=t.cv||5,this.#s=t.task||"classification",this.#i=t.passthrough||!1,this.#f=t.seed??42,this.#r=null,this.#n=null,this.#l=null,this.#a=0,this.#c=0,s._register()}static async create(t={}){return new s(t)}#p(){if(this.#d)throw new fr("StackingEnsemble has been disposed.")}#u(){if(this.#p(),!this.#h)throw new lr("StackingEnsemble is not fitted. Call fit() first.")}async fit(t,n){if(this.#p(),!this.#e)throw new J("StackingEnsemble requires a finalEstimator");let e=Oe(t),o=Le(n),r=e.rows;if(this.#s==="classification"){let p=new Set;for(let m=0;m<o.length;m++)p.add(o[m]);this.#l=new Int32Array([...p].sort((m,w)=>m-w)),this.#a=this.#l.length}let i=this.#s==="classification"?ar(o,this.#o,{shuffle:!0,seed:this.#f}):cr(r,this.#o,{shuffle:!0,seed:this.#f}),a=this.#t.length,f=this.#s==="classification"?this.#a:1,h=a*f,c=new Float64Array(r*h);for(let p=0;p<a;p++){let[,m,w]=this.#t[p];for(let{train:b,test:g}of i){let y=Re(e,b),F=hr(o,b),E=Re(e,g),v=await m.create(w||{});try{if(v.fit(y,F),this.#s==="classification"){let S=await v.predictProba(E);for(let A=0;A<g.length;A++){let j=g[A];for(let _=0;_<this.#a;_++)c[j*h+p*f+_]=S[A*this.#a+_]}}else{let S=await v.predict(E);for(let A=0;A<g.length;A++)c[g[A]*h+p]=S[A]}}finally{v.dispose()}}}let l;if(this.#i){this.#c=h+e.cols;let p=new Float64Array(r*this.#c);for(let m=0;m<r;m++)p.set(c.subarray(m*h,(m+1)*h),m*this.#c),p.set(e.data.subarray(m*e.cols,(m+1)*e.cols),m*this.#c+h);l={data:p,rows:r,cols:this.#c}}else this.#c=h,l={data:c,rows:r,cols:h};this.#r=[];for(let[,p,m]of this.#t){let w=await p.create(m||{});w.fit(e,o),this.#r.push(w)}let[,d,u]=this.#e;return this.#n=await d.create(u||{}),this.#n.fit(l,o),this.#h=!0,this}predict(t){this.#u();let n=this.#m(t);return St(n,e=>this.#n.predict(e))}predictProba(t){if(this.#u(),this.#s!=="classification")throw new J("predictProba is only available for classification");if(typeof this.#n.predictProba!="function")throw new J("Meta-model does not support predictProba");let n=this.#m(t);return St(n,e=>this.#n.predictProba(e))}score(t,n){this.#u();let e=this.predict(t),o=Le(n),r=this.#s==="classification"?or:ir;return St(e,i=>r(o,i))}save(){this.#u();let n={typeId:this.#s==="classification"?Be:De,params:{task:this.#s,cv:this.#o,passthrough:this.#i,seed:this.#f,estimatorNames:this.#t.map(o=>o[0]),metaName:this.#e[0],classes:this.#l?[...this.#l]:null,nMetaCols:this.#c}},e=this.#r.map((o,r)=>({id:this.#t[r][0],data:o.save(),mediaType:"application/x-wlearn-bundle"}));return e.push({id:this.#e[0],data:this.#n.save(),mediaType:"application/x-wlearn-bundle"}),nr(n,e)}static async load(t){let{manifest:n,toc:e,blobs:o}=rr(t);return s._loadFromParts(n,e,o)}dispose(){if(!this.#d){if(this.#d=!0,this.#r)for(let t of this.#r)t.dispose();this.#n&&this.#n.dispose()}}getParams(){return{task:this.#s,cv:this.#o,passthrough:this.#i,seed:this.#f,estimatorNames:this.#t.map(t=>t[0]),metaName:this.#e?this.#e[0]:null}}setParams(t){return this.#p(),t.cv!==void 0&&(this.#o=t.cv),t.passthrough!==void 0&&(this.#i=t.passthrough),t.seed!==void 0&&(this.#f=t.seed),this}get capabilities(){return{classifier:this.#s==="classification",regressor:this.#s==="regression",predictProba:this.#s==="classification",decisionFunction:!1,sampleWeight:!1,csr:!1,earlyStopping:!1}}get isFitted(){return this.#h}get classes(){return this.#l}#m(t){let n=Oe(t),e=n.rows,o=this.#r.length,r=this.#s==="classification"?this.#a:1,i=o*r,a=[],f=!1;for(let c=0;c<o;c++){let l=this.#s==="classification"?this.#r[c].predictProba(n):this.#r[c].predict(n);l!=null&&typeof l.then=="function"&&(f=!0),a.push(l)}let h=c=>{let l=new Float64Array(e*this.#c);for(let d=0;d<o;d++)if(this.#s==="classification"){let u=c[d];for(let p=0;p<e;p++)for(let m=0;m<this.#a;m++)l[p*this.#c+d*r+m]=u[p*this.#a+m]}else{let u=c[d];for(let p=0;p<e;p++)l[p*this.#c+d]=u[p]}if(this.#i)for(let d=0;d<e;d++)l.set(n.data.subarray(d*n.cols,(d+1)*n.cols),d*this.#c+i);return{data:l,rows:e,cols:this.#c}};return f?Promise.all(a).then(h):h(a)}static _register(){if(ze)return;ze=!0;let t=(n,e,o)=>s._loadFromParts(n,e,o);_e(Be,t),_e(De,t)}static async _loadFromParts(t,n,e){let o=t.params,r=new s({task:o.task,cv:o.cv,passthrough:o.passthrough,seed:o.seed});r.#l=o.classes?new Int32Array(o.classes):null,r.#a=r.#l?r.#l.length:0,r.#c=o.nMetaCols,r.#t=o.estimatorNames.map(f=>[f,null,null]),r.#e=[o.metaName,null,null],r.#r=[];for(let f of o.estimatorNames){let h=n.find(l=>l.id===f);if(!h)throw new J(`No artifact for base estimator "${f}"`);let c=e.subarray(h.offset,h.offset+h.length);r.#r.push(await $e(c))}let i=n.find(f=>f.id===o.metaName);if(!i)throw new J(`No artifact for meta estimator "${o.metaName}"`);let a=e.subarray(i.offset,i.offset+i.length);return r.#n=await $e(a),r.#h=!0,r}};function Re(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function hr(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}je.exports={StackingEnsemble:Et}});var He=x((lo,Ke)=>{var{encodeBundle:ur,decodeBundle:dr,register:Ve,load:pr,normalizeX:It,normalizeY:Xe,accuracy:mr,r2Score:wr,stratifiedKFold:gr,kFold:br,ValidationError:Ye,NotFittedError:yr,DisposedError:xr,lift:Te}=R(),Ce="wlearn.ensemble.bagged.classifier@1",We="wlearn.ensemble.bagged.regressor@1",Je=!1,Pt=class s{#t;#e;#r;#n;#o;#s;#i;#f=0;#l=0;#a;#c;#h=!1;#d=!1;constructor(t={}){this.#t=t.estimator||null,this.#e=t.kFold||5,this.#r=t.nRepeats||1,this.#n=t.task||"classification",this.#o=t.seed??42,this.#s=null,this.#i=null,this.#a=null,this.#c=null,s._register()}static async create(t={}){return new s(t)}#p(){if(this.#d)throw new xr("BaggedEstimator has been disposed.")}#u(){if(this.#p(),!this.#h)throw new yr("BaggedEstimator is not fitted. Call fit() first.")}async fit(t,n){this.#p();let e=It(t),o=Xe(n),r=e.rows;if(this.#l=r,this.#n==="classification"){let f=new Set;for(let h=0;h<o.length;h++)f.add(o[h]);this.#i=new Int32Array([...f].sort((h,c)=>h-c)),this.#f=this.#i.length}this.#n==="classification"?this.#a=new Float64Array(r*this.#f):this.#a=new Float64Array(r),this.#c=new Uint8Array(r);let[,i,a]=this.#t;this.#s=[];for(let f=0;f<this.#r;f++){let h=this.#o+f,c=this.#n==="classification"?gr(o,this.#e,{shuffle:!0,seed:h}):br(r,this.#e,{shuffle:!0,seed:h});for(let{train:l,test:d}of c){let u=Ge(e,l),p=Ar(o,l),m=Ge(e,d),w=await i.create(a||{});if(w.fit(u,p),this.#n==="classification"){let b=await w.predictProba(m),g=this.#f;for(let y=0;y<d.length;y++){let F=d[y];for(let E=0;E<g;E++)this.#a[F*g+E]+=b[y*g+E]}}else{let b=await w.predict(m);for(let g=0;g<d.length;g++)this.#a[d[g]]+=b[g]}for(let b=0;b<d.length;b++)this.#c[d[b]]+=1;this.#s.push(w)}}return this.#h=!0,this}predict(t){this.#u();let n=It(t),e=n.rows;if(this.#n==="regression")return this.#m(n,e);let o=this.predictProba(n);return Te(o,r=>{let i=this.#f,a=new Float64Array(e);for(let f=0;f<e;f++){let h=0,c=-1/0;for(let l=0;l<i;l++)r[f*i+l]>c&&(c=r[f*i+l],h=l);a[f]=this.#i[h]}return a})}predictProba(t){if(this.#u(),this.#n!=="classification")throw new Ye("predictProba is only available for classification");let n=It(t),e=n.rows,o=this.#f,r=this.#s.length,i=[],a=!1;for(let h of this.#s){let c=h.predictProba(n);c!=null&&typeof c.then=="function"&&(a=!0),i.push(c)}let f=h=>{let c=new Float64Array(e*o);for(let l of h)for(let d=0;d<e*o;d++)c[d]+=l[d];for(let l=0;l<e*o;l++)c[l]/=r;return c};return a?Promise.all(i).then(f):f(i)}score(t,n){this.#u();let e=this.predict(t),o=Xe(n),r=this.#n==="classification"?mr:wr;return Te(e,i=>r(o,i))}#m(t,n){let e=this.#s.length,o=[],r=!1;for(let a of this.#s){let f=a.predict(t);f!=null&&typeof f.then=="function"&&(r=!0),o.push(f)}let i=a=>{let f=new Float64Array(n);for(let h of a)for(let c=0;c<n;c++)f[c]+=h[c];for(let h=0;h<n;h++)f[h]/=e;return f};return r?Promise.all(o).then(i):i(o)}get oofPredictions(){this.#u();let t=new Uint8Array(this.#c);for(let e=0;e<t.length;e++)t[e]===0&&(t[e]=1);if(this.#n==="classification"){let e=this.#f,o=new Float64Array(this.#a);for(let r=0;r<this.#l;r++){let i=t[r];for(let a=0;a<e;a++)o[r*e+a]/=i}return o}let n=new Float64Array(this.#a);for(let e=0;e<this.#l;e++)n[e]/=t[e];return n}save(){this.#u();let n={typeId:this.#n==="classification"?Ce:We,params:{task:this.#n,kFold:this.#e,nRepeats:this.#r,seed:this.#o,estimatorName:this.#t[0],classes:this.#i?[...this.#i]:null,nClasses:this.#f,nSamples:this.#l}},e=this.#s.map((i,a)=>({id:`fold_${a}`,data:i.save(),mediaType:"application/x-wlearn-bundle"})),o=this.oofPredictions,r=new Uint8Array(o.buffer,o.byteOffset,o.byteLength);return e.push({id:"oof",data:r,mediaType:"application/octet-stream"}),ur(n,e)}static async load(t){let{manifest:n,toc:e,blobs:o}=dr(t);return s._loadFromParts(n,e,o)}dispose(){if(!this.#d){if(this.#d=!0,this.#s)for(let t of this.#s)t.dispose();this.#s=null,this.#a=null,this.#c=null}}getParams(){return{task:this.#n,kFold:this.#e,nRepeats:this.#r,seed:this.#o,estimatorName:this.#t?this.#t[0]:null}}setParams(t){return this.#p(),t.kFold!==void 0&&(this.#e=t.kFold),t.nRepeats!==void 0&&(this.#r=t.nRepeats),t.seed!==void 0&&(this.#o=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.#i}static _register(){if(Je)return;Je=!0;let t=(n,e,o)=>s._loadFromParts(n,e,o);Ve(Ce,t),Ve(We,t)}static async _loadFromParts(t,n,e){let o=t.params,r=new s({task:o.task,kFold:o.kFold||5,nRepeats:o.nRepeats||1,seed:o.seed??42});r.#i=o.classes?new Int32Array(o.classes):null,r.#f=o.nClasses||0,r.#l=o.nSamples||0,r.#t=[o.estimatorName||"base",null,null];let i=r.#e*r.#r;r.#s=[];for(let f=0;f<i;f++){let h=`fold_${f}`,c=n.find(d=>d.id===h);if(!c)throw new Ye(`No artifact for "${h}"`);let l=e.subarray(c.offset,c.offset+c.length);r.#s.push(await pr(l))}let a=n.find(f=>f.id==="oof");if(a){let f=e.subarray(a.offset,a.offset+a.length),h=new Float64Array(f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength));r.#a=h,r.#c=new Uint8Array(r.#l).fill(1)}else r.#n==="classification"?r.#a=new Float64Array(r.#l*r.#f):r.#a=new Float64Array(r.#l),r.#c=new Uint8Array(r.#l);return r.#h=!0,r}};function Ge(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function Ar(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}Ke.exports={BaggedEstimator:Pt}});var Nt=x((fo,Qe)=>{var{ValidationError:Ze}=R();function vt(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 o=-1;for(let a=0;a<t;a++)n[a]*(a+1)>e[a]-1&&(o=a);if(o<0){let a=new Float64Array(t);return a.fill(1/t),a}let r=(e[o]-1)/(o+1),i=new Float64Array(t);for(let a=0;a<t;a++)i[a]=Math.max(s[a]-r,0);return i}function Fr(s,t,n,{task:e="classification",lr:o=.05,nIter:r=100}={}){let i=s.length,a=t.length;if(i===0)throw new Ze("optimizeWeights: need at least 1 model");if(i===1)return new Float64Array([1]);let f=new Float64Array(n),h=1e-15;if(e==="classification"){let l=s[0].length/a;if(l!==Math.floor(l))throw new Ze("optimizeWeights: prediction length must be divisible by n");for(let d=0;d<r;d++){let u=new Float64Array(i);for(let m=0;m<a;m++){let w=t[m]|0,b=0;for(let g=0;g<i;g++)b+=f[g]*s[g][m*l+w];b=Math.max(b,h);for(let g=0;g<i;g++)u[g]-=s[g][m*l+w]/b}for(let m=0;m<i;m++)u[m]/=a;for(let m=0;m<i;m++)f[m]-=o*u[m];let p=vt(f);for(let m=0;m<i;m++)f[m]=p[m]}}else for(let c=0;c<r;c++){let l=new Float64Array(i);for(let u=0;u<a;u++){let p=0;for(let w=0;w<i;w++)p+=f[w]*s[w][u];let m=t[u]-p;for(let w=0;w<i;w++)l[w]-=2*m*s[w][u]}for(let u=0;u<i;u++)l[u]/=a;for(let u=0;u<i;u++)f[u]-=o*l[u];let d=vt(f);for(let u=0;u<i;u++)f[u]=d[u]}return f}Qe.exports={optimizeWeights:Fr,projectSimplex:vt}});var ss=x((ho,es)=>{var{getScorer:Sr,normalizeY:Er,ValidationError:ts}=R(),{optimizeWeights:Ir}=Nt();function Pr(s,t,{maxSize:n=20,scoring:e="accuracy",task:o="classification",nClasses:r=0,refineWeights:i=!0}={}){let a=Er(t),f=a.length,h=s.length;if(h===0)throw new ts("caruanaSelect: need at least 1 candidate");let c=Sr(e),l=s[0].length/f;if(l!==Math.floor(l))throw new ts("caruanaSelect: oofPredictions[0].length must be divisible by n");o==="classification"&&r===0&&(r=l);let d=new Float64Array(s[0].length),u=[],p=[];for(let y=0;y<n;y++){let F=-1,E=-1/0;for(let S=0;S<h;S++){let A=vr(d,s[S],y,y+1),j=Nr(A,a,c,o,r,f);j>E&&(E=j,F=S)}u.push(F),p.push(E);let v=s[F];for(let S=0;S<d.length;S++)d[S]=(y*d[S]+v[S])/(y+1)}let m=new Map;for(let y of u)m.set(y,(m.get(y)||0)+1);let w=new Int32Array([...m.keys()].sort((y,F)=>y-F)),b=new Float64Array(w.length);for(let y=0;y<w.length;y++)b[y]=m.get(w[y])/n;let g={indices:w,weights:b,scores:new Float64Array(p)};if(i&&w.length>1){let y=Array.from(w,F=>s[F]);g.weights=Ir(y,a,b,{task:o})}return g}function vr(s,t,n,e){let o=new Float64Array(s.length);for(let r=0;r<s.length;r++)o[r]=(n*s[r]+t[r])/e;return o}function Nr(s,t,n,e,o,r){if(e==="regression")return n(t,s);let i=new Float64Array(r);for(let a=0;a<r;a++){let f=0,h=-1/0;for(let c=0;c<o;c++)s[a*o+c]>h&&(h=s[a*o+c],f=c);i[a]=f}return n(t,i)}es.exports={caruanaSelect:Pr}});var os=x((po,rs)=>{var{stratifiedKFold:kr,kFold:Mr,normalizeX:qr,normalizeY:_r,ValidationError:uo}=R();async function $r(s,t,n,{cv:e=5,seed:o=42,task:r="classification"}={}){let i=qr(t),a=_r(n),f=i.rows,h=r==="classification"?kr(a,e,{shuffle:!0,seed:o}):Mr(f,e,{shuffle:!0,seed:o}),c=null,l=0;if(r==="classification"){let u=new Set;for(let p=0;p<a.length;p++)u.add(a[p]);c=new Int32Array([...u].sort((p,m)=>p-m)),l=c.length}let d=[];for(let[u,p,m]of s){let w;r==="classification"?w=new Float64Array(f*l):w=new Float64Array(f);for(let{train:b,test:g}of h){let y=ns(i,b),F=Or(a,b),E=ns(i,g),v=await p.create(m||{});try{if(v.fit(y,F),r==="classification"){let S=await v.predictProba(E);for(let A=0;A<g.length;A++){let j=g[A];for(let _=0;_<l;_++)w[j*l+_]=S[A*l+_]}}else{let S=await v.predict(E);for(let A=0;A<g.length;A++)w[g[A]]=S[A]}}finally{v.dispose()}}d.push(w)}return{oofPreds:d,classes:c}}function ns(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function Or(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}rs.exports={getOofPredictions:$r}});var Vr=x((mo,is)=>{var{VotingEnsemble:Lr}=qe(),{StackingEnsemble:Br}=Ue(),{BaggedEstimator:Dr}=He(),{caruanaSelect:zr}=ss(),{getOofPredictions:Rr}=os(),{optimizeWeights:jr,projectSimplex:Ur}=Nt();is.exports={VotingEnsemble:Lr,StackingEnsemble:Br,BaggedEstimator:Dr,caruanaSelect:zr,getOofPredictions:Rr,optimizeWeights:jr,projectSimplex:Ur}});return Vr();})();
@@ -0,0 +1,2 @@
1
+ var __ensemble=(()=>{var x=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var k=x((Yr,kt)=>{var O=class extends Error{constructor(t,n){super(t),this.name="WlearnError",this.code=n||"ERR_WLEARN"}},rt=class extends O{constructor(t){super(t,"ERR_BUNDLE"),this.name="BundleError"}},ot=class extends O{constructor(t){super(t,"ERR_REGISTRY"),this.name="RegistryError"}},it=class extends O{constructor(t){super(t,"ERR_VALIDATION"),this.name="ValidationError"}},at=class extends O{constructor(t="Model is not fitted. Call fit() first."){super(t,"ERR_NOT_FITTED"),this.name="NotFittedError"}},ct=class extends O{constructor(t="Model has been disposed."){super(t,"ERR_DISPOSED"),this.name="DisposedError"}};kt.exports={WlearnError:O,BundleError:rt,RegistryError:ot,ValidationError:it,NotFittedError:at,DisposedError:ct}});var U=x((Tr,Mt)=>{var{ValidationError:M}=k();function as(s,t="auto"){if(s&&typeof s=="object"&&!Array.isArray(s)&&s.data){let{data:n,rows:e,cols:o}=s;if(!(n instanceof Float64Array)){if(t==="error")throw new M("Expected Float64Array in typed matrix");return{data:new Float64Array(n),rows:e,cols:o}}return{data:n,rows:e,cols:o}}if(Array.isArray(s)&&Array.isArray(s[0])){if(t==="error")throw new M('Input coercion disabled (coerce: "error"). Pass { data: Float64Array, rows, cols } instead of number[][].');let n=s.length,e=s[0].length,o=new Float64Array(n*e);for(let r=0;r<n;r++)for(let i=0;i<e;i++)o[r*e+i]=s[r][i];if(t==="warn"){let r=o.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:o,rows:n,cols:e}}throw new M("X must be number[][] or { data: Float64Array, rows, cols }")}function cs(s){return s instanceof Int32Array||s instanceof Float32Array||s instanceof Float64Array?s:new Float64Array(s)}function ls(s,t,n){if(!t||!n||t<1||n<1)throw new M(`Invalid dimensions: rows=${t}, cols=${n}`);if(!(s instanceof Float32Array)&&!(s instanceof Float64Array))throw new M("data must be Float32Array or Float64Array");if(s.length!==t*n)throw new M(`data.length (${s.length}) !== rows * cols (${t*n})`);return{data:s,rows:t,cols:n}}function fs(s){if(!s||typeof s!="object")throw new M("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 M(`Invalid dimensions: rows=${n}, cols=${e}`);if(!(t instanceof Float32Array)&&!(t instanceof Float64Array))throw new M("data must be Float32Array or Float64Array");if(t.length!==n*e)throw new M(`data.length (${t.length}) !== rows * cols (${n*e})`);return s}Mt.exports={normalizeX:as,normalizeY:cs,makeDense:ls,validateMatrix:fs}});var lt=x((Cr,qt)=>{var hs=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]),N=new Uint32Array(64);function q(s,t){return s>>>t|s<<32-t}function us(s,t,n){for(let l=0;l<16;l++)N[l]=(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0,n+=4;for(let l=16;l<64;l++){let d=q(N[l-15],7)^q(N[l-15],18)^N[l-15]>>>3,u=q(N[l-2],17)^q(N[l-2],19)^N[l-2]>>>10;N[l]=N[l-16]+d+N[l-7]+u>>>0}let e=s[0],o=s[1],r=s[2],i=s[3],a=s[4],f=s[5],h=s[6],c=s[7];for(let l=0;l<64;l++){let d=q(a,6)^q(a,11)^q(a,25),u=a&f^~a&h,p=c+d+u+hs[l]+N[l]>>>0,m=q(e,2)^q(e,13)^q(e,22),w=e&o^e&r^o&r,b=m+w>>>0;c=h,h=f,f=a,a=i+p>>>0,i=r,r=o,o=e,e=p+b>>>0}s[0]=s[0]+e>>>0,s[1]=s[1]+o>>>0,s[2]=s[2]+r>>>0,s[3]=s[3]+i>>>0,s[4]=s[4]+a>>>0,s[5]=s[5]+f>>>0,s[6]=s[6]+h>>>0,s[7]=s[7]+c>>>0}function ds(s){let t=s instanceof Uint8Array?s:new Uint8Array(s),n=t.length,e=n*8,o=n+9+63&-64,r=new Uint8Array(o);r.set(t),r[n]=128;let i=new DataView(r.buffer);i.setUint32(o-4,e>>>0,!1),e>4294967295&&i.setUint32(o-8,e/4294967296>>>0,!1);let a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);for(let h=0;h<o;h+=64)us(a,r,h);let f="";for(let h=0;h<8;h++)f+=a[h].toString(16).padStart(8,"0");return f}qt.exports={sha256Sync:ds}});var $t=x((Wr,_t)=>{var ps=new Uint8Array([87,76,82,78]),ms=1,ws=16,gs={FLOAT32:"float32",FLOAT64:"float64",INT32:"int32"};_t.exports={BUNDLE_MAGIC:ps,BUNDLE_VERSION:ms,HEADER_SIZE:ws,DTYPE:gs}});var C=x((Jr,Dt)=>{var{BUNDLE_MAGIC:Ot,BUNDLE_VERSION:G,HEADER_SIZE:I}=$t(),{BundleError:$}=k(),{sha256Sync:Lt}=lt();function T(s){return s==null||typeof s!="object"?JSON.stringify(s):Array.isArray(s)?"["+s.map(n=>T(n)).join(",")+"]":"{"+Object.keys(s).sort().map(n=>JSON.stringify(n)+":"+T(s[n])).join(",")+"}"}var ft=new TextEncoder,ht=new TextDecoder;function bs(s,t){let n=[...t].sort((u,p)=>u.id<p.id?-1:u.id>p.id?1:0),e=0,o=[],r=[];for(let u of n){let p=u.data instanceof Uint8Array?u.data:new Uint8Array(u.data),m=Lt(p),w={id:u.id,offset:e,length:p.length,sha256:m};u.mediaType&&(w.mediaType=u.mediaType),o.push(w),r.push(p),e+=p.length}let i={...s,bundleVersion:G},a=ft.encode(T(i)),f=ft.encode(T(o)),h=I+a.length+f.length+e,c=new Uint8Array(h),l=new DataView(c.buffer);c.set(Ot,0),l.setUint32(4,G,!0),l.setUint32(8,a.length,!0),l.setUint32(12,f.length,!0),c.set(a,I),c.set(f,I+a.length);let d=I+a.length+f.length;for(let u of r)c.set(u,d),d+=u.length;return c}function Bt(s){let t=s instanceof Uint8Array?s:new Uint8Array(s);if(t.length<I)throw new $(`Bundle too small: ${t.length} bytes (minimum ${I})`);for(let l=0;l<4;l++)if(t[l]!==Ot[l])throw new $("Invalid bundle magic (expected WLRN)");let n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=n.getUint32(4,!0);if(e!==G)throw new $(`Unsupported bundle version: ${e} (expected ${G})`);let o=n.getUint32(8,!0),r=n.getUint32(12,!0);if(I+o+r>t.length)throw new $(`Bundle truncated: header declares ${I+o+r} bytes but got ${t.length}`);let i,a;try{i=JSON.parse(ht.decode(t.subarray(I,I+o)))}catch(l){throw new $(`Invalid manifest JSON: ${l.message}`)}try{a=JSON.parse(ht.decode(t.subarray(I+o,I+o+r)))}catch(l){throw new $(`Invalid TOC JSON: ${l.message}`)}let f=I+o+r,h=t.length-f;for(let l=0;l<a.length;l++){let d=a[l];if(d.offset<0||d.length<0||d.offset+d.length>h)throw new $(`TOC entry "${d.id}" out of bounds: offset=${d.offset}, length=${d.length}, blobRegion=${h}`);for(let u=l+1;u<a.length;u++){let p=a[u],m=d.offset,w=d.offset+d.length,b=p.offset,g=p.offset+p.length;if(m<g&&b<w&&d.length>0&&p.length>0)throw new $(`TOC entries "${d.id}" and "${p.id}" overlap`)}}let c=t.subarray(f);return{manifest:i,toc:a,blobs:c}}function ys(s){return ft.encode(T(s))}function xs(s){let t=s instanceof Uint8Array?s:new Uint8Array(s);return JSON.parse(ht.decode(t))}function As(s){let{manifest:t,toc:n,blobs:e}=Bt(s);for(let o of n){let r=e.subarray(o.offset,o.offset+o.length),i=Lt(r);if(i!==o.sha256)throw new $(`SHA-256 mismatch for "${o.id}": expected ${o.sha256}, got ${i}`)}return{manifest:t,toc:n,blobs:e}}Dt.exports={encodeBundle:bs,decodeBundle:Bt,encodeJSON:ys,decodeJSON:xs,validateBundle:As}});var K=x((Gr,Rt)=>{var{RegistryError:D}=k(),{decodeBundle:zt}=C(),V=new Map;function Fs(s,t){if(typeof s!="string"||!s.includes("@"))throw new D(`Invalid typeId "${s}": must contain "@" (e.g. "wlearn.liblinear.classifier@1")`);if(typeof t!="function")throw new D("loaderFn must be a function");V.set(s,t)}async function Ss(s){let{manifest:t,toc:n,blobs:e}=zt(s),{typeId:o}=t;if(!o)throw new D("Bundle manifest missing typeId");let r=V.get(o);if(!r){let i=[...V.keys()],a=i.length>0?`Registered loaders: ${i.join(", ")}`:"No loaders registered";throw new D(`No loader registered for typeId "${o}". ${a}. Install the corresponding @wlearn/* package and import it to register the loader.`)}return await r(t,n,e)}function Es(s){let{manifest:t,toc:n,blobs:e}=zt(s),{typeId:o}=t;if(!o)throw new D("Bundle manifest missing typeId");let r=V.get(o);if(!r){let a=[...V.keys()],f=a.length>0?`Registered loaders: ${a.join(", ")}`:"No loaders registered";throw new D(`No loader registered for typeId "${o}". ${f}. Install the corresponding @wlearn/* package and import it to register the loader.`)}let i=r(t,n,e);if(i&&typeof i.then=="function")throw new D(`Loader for "${o}" returned a Promise. Use async load() instead of loadSync().`);return i}function Is(){return new Map(V)}Rt.exports={register:Fs,load:Ss,loadSync:Es,getRegistry:Is}});var dt=x((Kr,jt)=>{var ut=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"}};jt.exports={Step:ut}});var Tt=x((Hr,Yt)=>{var{Step:Ps}=dt(),{DisposedError:vs,NotFittedError:Ns,ValidationError:H}=k(),{encodeBundle:ks,decodeBundle:Ms}=C(),{register:qs,load:Ut}=K(),Vt="wlearn.pipeline@1",Xt=!1,Z=class s{#t;#e=!1;#r=!1;constructor(t){if(this.#t=t.map(([n,e])=>new Ps(n,e)),this.#t.length===0)throw new H("Pipeline requires at least one step")}#n(){if(this.#r)throw new vs("Pipeline has been disposed.")}#o(){if(this.#n(),!this.#e)throw new Ns("Pipeline is not fitted. Call fit() first.")}#s(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 i=this.#t[r].estimator;typeof i.fitTransform=="function"?e=i.fitTransform(e,n):(i.fit(e,n),e=i.transform(e))}return this.#t[this.#t.length-1].estimator.fit(e,n),this.#e=!0,this}predict(t){this.#o();let n=this.#s(t);return this.#t[this.#t.length-1].estimator.predict(n)}predictProba(t){this.#o();let n=this.#t[this.#t.length-1].estimator;if(typeof n.predictProba!="function")throw new H("Last step does not support predictProba");let e=this.#s(t);return n.predictProba(e)}score(t,n){this.#o();let e=this.#s(t);return this.#t[this.#t.length-1].estimator.score(e,n)}save(){this.#o();let t={typeId:Vt,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 ks(t,n)}static async load(t){let{manifest:n,toc:e,blobs:o}=Ms(t),r=[];for(let a of n.steps){let f=e.find(l=>l.id===a.name);if(!f)throw new H(`No artifact found for pipeline step "${a.name}"`);let h=o.subarray(f.offset,f.offset+f.length),c=await Ut(h);r.push([a.name,c])}let i=new s(r);return i.#e=!0,i}dispose(){if(!this.#r){this.#r=!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(){Xt||(Xt=!0,qs(Vt,(t,n,e)=>s._loadFromParts(t,n,e)))}static async _loadFromParts(t,n,e){let o=[];for(let i of t.steps){let a=n.find(c=>c.id===i.name);if(!a)throw new H(`No artifact found for pipeline step "${i.name}"`);let f=e.subarray(a.offset,a.offset+a.length),h=await Ut(f);o.push([i.name,h])}let r=new s(o);return r.#e=!0,r}};Z.registerLoader();Yt.exports={Pipeline:Z}});var Gt=x((Qr,Jt)=>{var{normalizeX:Ct,normalizeY:Zr}=U(),{ValidationError:Wt}=k(),pt=class s{#t;#e=!1;#r=null;#n=null;#o=null;#s=null;#i=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=Ct(t),{data:o,rows:r,cols:i}=e;this.#r=new Array(i),this.#n=new Float64Array(i);let a=new Array(i);for(let h=0;h<i;h++){let c=[],l=!1,d=0,u=0;for(let b=0;b<r;b++){let g=o[b*i+h];Number.isNaN(g)?l=!0:(c.push(g),d+=g,u++)}let p=new Set(c),m=c.every(b=>b===Math.floor(b)),w=this.#t.encode!==!1&&m&&p.size<=this.#t.maxCategories&&p.size>=2;if(this.#r[h]=w?"categorical":"numeric",this.#t.impute!==!1&&l)if(w){let b=new Map;for(let F of c)b.set(F,(b.get(F)||0)+1);let g=c[0],y=0;for(let[F,E]of b)E>y&&(g=F,y=E);this.#n[h]=g}else this.#n[h]=u>0?d/u:0;a[h]={values:c,unique:p,sum:d,count:u}}this.#o=new Array(i).fill(null);let f=0;if(this.#t.encode!==!1)for(let h=0;h<i;h++)if(this.#r[h]==="categorical"){let c=[...a[h].unique].sort((l,d)=>l-d);if(this.#t.encode==="label"||this.#t.encode===!1){let l=new Map;c.forEach((d,u)=>l.set(d,u)),this.#o[h]={type:"label",mapping:l,startIdx:f},f++}else{let l=new Map;c.forEach((d,u)=>l.set(d,f+u)),this.#o[h]={type:"onehot",mapping:l,startIdx:f,size:c.length},f+=c.length}}else f++;else f=i;if(this.#i=f,this.#s=new Array(this.#i).fill(null),this.#t.scale){let h=0;for(let c=0;c<i;c++){if(this.#r[c]==="categorical"&&this.#t.encode!==!1){let d=this.#o[c];h+=d.type==="onehot"?d.size:1;continue}let l=a[c].values;if(this.#t.scale==="standard"){let d=a[c].sum/(a[c].count||1),u=0;for(let m of l)u+=(m-d)**2;u/=l.length||1;let p=Math.sqrt(u);this.#s[h]={mean:d,std:p||1}}else if(this.#t.scale==="minmax"){let d=1/0,u=-1/0;for(let m of l)m<d&&(d=m),m>u&&(u=m);let p=u-d||1;this.#s[h]={min:d,range:p}}h++}}return this.#e=!0,this}transform(t){if(!this.#e)throw new Wt("Preprocessor not fitted");let n=Ct(t),{data:e,rows:o,cols:r}=n,i=this.#i,a=new Float64Array(o*i);for(let f=0;f<o;f++){let h=0;for(let c=0;c<r;c++){let l=e[f*r+c];if(Number.isNaN(l)&&this.#t.impute!==!1&&(l=this.#n[c]),this.#r[c]==="categorical"&&this.#o[c]){let d=this.#o[c];if(d.type==="onehot"){let u=d.mapping.get(l);u!==void 0&&(a[f*i+u]=1),h=d.startIdx+d.size}else{let u=d.mapping.get(l);a[f*i+h]=u!==void 0?u:-1,h++}}else a[f*i+h]=l,h++}if(this.#t.scale)for(let c=0;c<i;c++){let l=this.#s[c];l&&(this.#t.scale==="standard"?a[f*i+c]=(a[f*i+c]-l.mean)/l.std:this.#t.scale==="minmax"&&(a[f*i+c]=(a[f*i+c]-l.min)/l.range))}}return{data:a,rows:o,cols:i}}fitTransform(t,n){return this.fit(t,n),this.transform(t)}getState(){if(!this.#e)throw new Wt("Preprocessor not fitted");return{config:this.#t,colTypes:this.#r,imputeValues:[...this.#n],encodings:this.#o.map(t=>t?{type:t.type,mapping:[...t.mapping.entries()],startIdx:t.startIdx,size:t.size}:null),scaleParams:this.#s,outputCols:this.#i}}static fromState(t){let n=new s(t.config);return n.#r=t.colTypes,n.#n=new Float64Array(t.imputeValues),n.#o=t.encodings.map(e=>e?{type:e.type,mapping:new Map(e.mapping),startIdx:e.startIdx,size:e.size}:null),n.#s=t.scaleParams,n.#i=t.outputCols,n.#e=!0,n}get isFitted(){return this.#e}get outputCols(){return this.#i}get capabilities(){return{transformer:!0}}dispose(){}};Jt.exports={Preprocessor:pt}});var oe=x((to,re)=>{var{NotFittedError:Kt,DisposedError:Ht,ValidationError:X}=k(),{normalizeX:Q}=U(),{encodeBundle:Zt,encodeJSON:Qt,decodeJSON:te}=C(),{register:ee}=K(),se="wlearn.preprocess.standard_scaler@1",ne="wlearn.preprocess.minmax_scaler@1",tt=class s{#t=null;#e=null;#r=!1;#n=!1;#o={};constructor(t={}){this.#o={...t}}fit(t){this.#s();let{rows:n,cols:e,data:o}=Q(t);if(n===0)throw new X("Cannot fit on empty data");let r=new Float64Array(e),i=new Float64Array(e);for(let f=0;f<n;f++){let h=f+1;for(let c=0;c<e;c++){let l=o[f*e+c],d=l-r[c];r[c]+=d/h;let u=l-r[c];i[c]+=d*u}}let a=new Float64Array(e);for(let f=0;f<e;f++)a[f]=n>1?Math.sqrt(i[f]/(n-1)):0;return this.#t=r,this.#e=a,this.#r=!0,this}transform(t){this.#i();let{rows:n,cols:e,data:o}=Q(t);if(e!==this.#t.length)throw new X(`Expected ${this.#t.length} columns, got ${e}`);let r=new Float64Array(n*e);for(let i=0;i<n;i++)for(let a=0;a<e;a++){let f=i*e+a,h=this.#e[a];r[f]=h>0?(o[f]-this.#t[a])/h:0}return{rows:n,cols:e,data:r}}fitTransform(t){return this.fit(t),this.transform(t)}save(){this.#i();let t={means:Array.from(this.#t),stds:Array.from(this.#e)};return Zt({typeId:se,params:this.getParams()},[{id:"params",data:Qt(t),mediaType:"application/json"}])}static _fromBundle(t,n,e){let o=n.find(a=>a.id==="params");if(!o)throw new X('Bundle missing "params" artifact');let r=te(e.subarray(o.offset,o.offset+o.length)),i=new s(t.params||{});return i.#t=new Float64Array(r.means),i.#e=new Float64Array(r.stds),i.#r=!0,i}dispose(){this.#n||(this.#n=!0,this.#t=null,this.#e=null,this.#r=!1)}getParams(){return{...this.#o}}setParams(t){return Object.assign(this.#o,t),this}get isFitted(){return this.#r&&!this.#n}#s(){if(this.#n)throw new Ht("StandardScaler has been disposed.")}#i(){if(this.#s(),!this.#r)throw new Kt("StandardScaler is not fitted.")}},et=class s{#t=null;#e=null;#r=!1;#n=!1;#o={};constructor(t={}){this.#o={...t}}fit(t){this.#s();let{rows:n,cols:e,data:o}=Q(t);if(n===0)throw new X("Cannot fit on empty data");let r=new Float64Array(e).fill(1/0),i=new Float64Array(e).fill(-1/0);for(let a=0;a<n;a++)for(let f=0;f<e;f++){let h=o[a*e+f];h<r[f]&&(r[f]=h),h>i[f]&&(i[f]=h)}return this.#t=r,this.#e=i,this.#r=!0,this}transform(t){this.#i();let{rows:n,cols:e,data:o}=Q(t);if(e!==this.#t.length)throw new X(`Expected ${this.#t.length} columns, got ${e}`);let r=new Float64Array(n*e);for(let i=0;i<n;i++)for(let a=0;a<e;a++){let f=i*e+a,h=this.#e[a]-this.#t[a];r[f]=h>0?(o[f]-this.#t[a])/h:0}return{rows:n,cols:e,data:r}}fitTransform(t){return this.fit(t),this.transform(t)}save(){this.#i();let t={mins:Array.from(this.#t),maxs:Array.from(this.#e)};return Zt({typeId:ne,params:this.getParams()},[{id:"params",data:Qt(t),mediaType:"application/json"}])}static _fromBundle(t,n,e){let o=n.find(a=>a.id==="params");if(!o)throw new X('Bundle missing "params" artifact');let r=te(e.subarray(o.offset,o.offset+o.length)),i=new s(t.params||{});return i.#t=new Float64Array(r.mins),i.#e=new Float64Array(r.maxs),i.#r=!0,i}dispose(){this.#n||(this.#n=!0,this.#t=null,this.#e=null,this.#r=!1)}getParams(){return{...this.#o}}setParams(t){return Object.assign(this.#o,t),this}get isFitted(){return this.#r&&!this.#n}#s(){if(this.#n)throw new Ht("MinMaxScaler has been disposed.")}#i(){if(this.#s(),!this.#r)throw new Kt("MinMaxScaler is not fitted.")}};ee(se,tt._fromBundle);ee(ne,et._fromBundle);re.exports={StandardScaler:tt,MinMaxScaler:et}});var mt=x((eo,ie)=>{function _s(s=42){let t=s|0;return()=>(t=t*1664525+1013904223&2147483647,t/2147483647)}function $s(s,t){for(let n=s.length-1;n>0;n--){let e=t()*(n+1)|0,o=s[n];s[n]=s[e],s[e]=o}return s}ie.exports={makeLCG:_s,shuffle:$s}});var bt=x((so,ae)=>{var{ValidationError:L}=k();function B(s,t,n){if(!s||!t||s.length===0||t.length===0)throw new L(`${n}: inputs must be non-empty`);if(s.length!==t.length)throw new L(`${n}: length mismatch (${s.length} vs ${t.length})`)}function Y(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,i)=>r-i)),o=new Map;for(let r=0;r<e.length;r++)o.set(e[r],r);return{labels:e,labelMap:o,nClasses:e.length}}function st(s,t,n,e){let o=new Int32Array(e*e);for(let r=0;r<s.length;r++){let i=n.get(s[r]),a=n.get(t[r]);o[i*e+a]++}return o}function wt(s,t){let n=new Float64Array(t),e=new Float64Array(t),o=new Float64Array(t);for(let r=0;r<t;r++){n[r]=s[r*t+r];for(let i=0;i<t;i++)i!==r&&(e[r]+=s[i*t+r],o[r]+=s[r*t+i])}return{tp:n,fp:e,fn:o}}function Os(s,t){B(s,t,"accuracy");let n=0;for(let e=0;e<s.length;e++)s[e]===t[e]&&n++;return n/s.length}function Ls(s,t){B(s,t,"r2Score");let n=s.length,e=0;for(let i=0;i<n;i++)e+=s[i];e/=n;let o=0,r=0;for(let i=0;i<n;i++){let a=s[i]-e;o+=a*a;let f=s[i]-t[i];r+=f*f}return o===0?0:1-r/o}function Bs(s,t){B(s,t,"meanSquaredError");let n=0;for(let e=0;e<s.length;e++){let o=s[e]-t[e];n+=o*o}return n/s.length}function Ds(s,t){B(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 zs(s,t){B(s,t,"confusionMatrix");let{labels:n,labelMap:e,nClasses:o}=Y(s,t);return{matrix:st(s,t,e,o),labels:n}}function gt(s,t,n){if(s==="binary"){if(t>2)throw new L('average="binary" requires exactly 2 classes');return"binary"}return s||"binary"}function Rs(s,t,{average:n="binary"}={}){B(s,t,"precisionScore");let{labels:e,labelMap:o,nClasses:r}=Y(s,t),i=st(s,t,o,r),{tp:a,fp:f}=wt(i,r),h=gt(n,r,e);if(h==="binary"){let l=r-1,d=a[l]+f[l];return d===0?0:a[l]/d}if(h==="micro"){let l=0,d=0;for(let u=0;u<r;u++)l+=a[u],d+=f[u];return l+d===0?0:l/(l+d)}let c=0;for(let l=0;l<r;l++){let d=a[l]+f[l];c+=d===0?0:a[l]/d}return c/r}function js(s,t,{average:n="binary"}={}){B(s,t,"recallScore");let{labels:e,labelMap:o,nClasses:r}=Y(s,t),i=st(s,t,o,r),{tp:a,fn:f}=wt(i,r),h=gt(n,r,e);if(h==="binary"){let l=r-1,d=a[l]+f[l];return d===0?0:a[l]/d}if(h==="micro"){let l=0,d=0;for(let u=0;u<r;u++)l+=a[u],d+=f[u];return l+d===0?0:l/(l+d)}let c=0;for(let l=0;l<r;l++){let d=a[l]+f[l];c+=d===0?0:a[l]/d}return c/r}function Us(s,t,{average:n="binary"}={}){B(s,t,"f1Score");let{labels:e,labelMap:o,nClasses:r}=Y(s,t),i=st(s,t,o,r),{tp:a,fp:f,fn:h}=wt(i,r),c=gt(n,r,e);function l(u,p,m){let w=u+p===0?0:u/(u+p),b=u+m===0?0:u/(u+m);return w+b===0?0:2*w*b/(w+b)}if(c==="binary"){let u=r-1;return l(a[u],f[u],h[u])}if(c==="micro"){let u=0,p=0,m=0;for(let w=0;w<r;w++)u+=a[w],p+=f[w],m+=h[w];return l(u,p,m)}let d=0;for(let u=0;u<r;u++)d+=l(a[u],f[u],h[u]);return d/r}function Vs(s,t,{nClasses:n,eps:e=1e-15}={}){if(!s||s.length===0)throw new L("logLoss: yTrue must be non-empty");let o=s.length;if(!n){let a=new Set;for(let f=0;f<o;f++)a.add(s[f]);n=a.size}if(t.length!==o*n)throw new L(`logLoss: yProba length (${t.length}) must be n * nClasses (${o*n})`);let{labelMap:r}=Y(s),i=0;for(let a=0;a<o;a++){let f=r.get(s[a]),h=t[a*n+f];h=Math.max(e,Math.min(1-e,h)),i-=Math.log(h)}return i/o}function Xs(s,t){if(!s||s.length===0)throw new L("rocAuc: yTrue must be non-empty");if(s.length!==t.length)throw new L("rocAuc: length mismatch");let{labels:n}=Y(s);if(n.length!==2)throw new L("rocAuc: requires exactly 2 classes");let e=n[n.length-1],o=s.length,r=Array.from({length:o},(u,p)=>p);r.sort((u,p)=>t[p]-t[u]);let i=0,a=0;for(let u=0;u<o;u++)s[u]===e?i++:a++;if(i===0||a===0)return 0;let f=0,h=0,c=0,l=0,d=0;for(let u=0;u<o;u++){let p=r[u];s[p]===e?f++:h++;let m=f/i,w=h/a;d+=(w-l)*(m+c)/2,c=m,l=w}return d}ae.exports={accuracy:Os,r2Score:Ls,meanSquaredError:Bs,meanAbsoluteError:Ds,confusionMatrix:zs,precisionScore:Rs,recallScore:js,f1Score:Us,logLoss:Vs,rocAuc:Xs}});var pe=x((no,de)=>{var{ValidationError:z}=k(),{makeLCG:yt,shuffle:xt}=mt(),{normalizeX:Ys,normalizeY:Ts}=U(),{accuracy:Cs,r2Score:Ws,meanSquaredError:Js,meanAbsoluteError:Gs}=bt(),ce={accuracy:(s,t)=>Cs(s,t),r2:(s,t)=>Ws(s,t),neg_mse:(s,t)=>-Js(s,t),neg_mae:(s,t)=>-Gs(s,t)};function he(s){if(typeof s=="function")return s;let t=ce[s];if(!t)throw new z(`Unknown scoring: "${s}". Available: ${Object.keys(ce).join(", ")}`);return t}function Ks(s,t=5,{shuffle:n=!0,seed:e=42}={}){if(s<t)throw new z(`kFold: n (${s}) must be >= k (${t})`);if(t<2)throw new z("kFold: k must be >= 2");let o=Int32Array.from({length:s},(h,c)=>c);if(n){let h=yt(e);xt(o,h)}let r=Math.floor(s/t),i=s%t,a=[],f=0;for(let h=0;h<t;h++){let c=r+(h<i?1:0),l=o.slice(f,f+c),d=[];f>0&&d.push(o.slice(0,f)),f+c<s&&d.push(o.slice(f+c));let u=Qs(d);a.push({train:u,test:l}),f+=c}return a}function ue(s,t=5,{shuffle:n=!0,seed:e=42}={}){let o=s.length;if(o<t)throw new z(`stratifiedKFold: n (${o}) must be >= k (${t})`);if(t<2)throw new z("stratifiedKFold: k must be >= 2");let r=new Map;for(let h=0;h<o;h++){let c=s[h];r.has(c)||r.set(c,[]),r.get(c).push(h)}if(n){let h=yt(e);for(let c of r.values())xt(c,h)}let i=Array.from({length:t},()=>[]);for(let h of r.values())for(let c=0;c<h.length;c++)i[c%t].push(h[c]);let a=Int32Array.from({length:o},(h,c)=>c),f=[];for(let h=0;h<t;h++){let c=new Set(i[h]),l=new Int32Array(i[h]),d=a.filter(u=>!c.has(u));f.push({train:d,test:l})}return f}function Hs(s,{testSize:t=.2,shuffle:n=!0,seed:e=42}={}){if(s<2)throw new z("trainTestSplit: n must be >= 2");let o=Math.max(1,Math.round(s*t)),r=s-o;if(r<1)throw new z("trainTestSplit: testSize too large");let i=Int32Array.from({length:s},(a,f)=>f);if(n){let a=yt(e);xt(i,a)}return{train:i.slice(0,r),test:i.slice(r)}}async function Zs(s,t,n,{cv:e=5,scoring:o="accuracy",seed:r=42,params:i={}}={}){let a=Ys(t),f=Ts(n),h=he(o),c;Array.isArray(e)?c=e:c=ue(f,e,{shuffle:!0,seed:r});let l=new Float64Array(c.length);for(let d=0;d<c.length;d++){let{train:u,test:p}=c[d],m=le(a,u),w=fe(f,u),b=le(a,p),g=fe(f,p),y=await s.create(i);try{y.fit(m,w);let F=await y.predict(b);l[d]=h(g,F)}finally{y.dispose()}}return l}function Qs(s){let t=0;for(let o of s)t+=o.length;let n=new Int32Array(t),e=0;for(let o of s)n.set(o,e),e+=o.length;return n}function le(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function fe(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}de.exports={kFold:Ks,stratifiedKFold:ue,trainTestSplit:Hs,crossValScore:Zs,getScorer:he}});var ge=x((ro,we)=>{function me(s){return s!=null&&typeof s.then=="function"}function tn(s,t){return me(s)?s.then(t):t(s)}we.exports={isPromiseLike:me,lift:tn}});var Ae=x((oo,xe)=>{var{normalizeY:en}=U(),{round:sn}=Math;function be(s){let t=en(s);if(t instanceof Int32Array)return"classification";let n=new Set;for(let e=0;e<t.length;e++){if(t[e]!==sn(t[e]))return"regression";n.add(t[e])}return n.size<=20?"classification":"regression"}var ye=new WeakMap;function P(s){let t=ye.get(s);if(!t)throw new Error("Model: invalid instance");return t}function W(s,t){let n=P(s);if(n.disposed)throw new Error(`${t} has been disposed.`);if(!n.inner)throw new Error(`${t}: not fitted`);return n.inner}function nn(s,t,n={}){let e=n.name||"Model",o=n.load||null,r=s===t;class i{constructor(c,l){ye.set(this,{inner:null,task:c,params:l,disposed:!1})}static async create(c={}){let l={...c},d=l.task||null;delete l.task,o&&await o();let u=new i(d,l),p=P(u);if(d){let m=d==="classification"?s:t;p.inner=await m.create({...l,task:d})}else r&&(p.inner=await s.create(l));return u}static async load(c){try{let l=await s.load(c),d=new i("classification",{}),u=P(d);return u.inner=l,typeof l.getParams=="function"&&(u.params=l.getParams(),u.params.task&&(u.task=u.params.task)),d}catch{let d=await t.load(c),u=new i("regression",{}),p=P(u);return p.inner=d,typeof d.getParams=="function"&&(p.params=d.getParams(),p.params.task&&(p.task=p.params.task)),u}}fit(c,l,d){let u=P(this);if(u.task||(u.task=be(l)),!u.inner){let p=u.task==="classification"?s:t;u.inner=new p({...u.params,task:u.task})}return u.inner.fit(c,l,d),this}predict(c,l){return W(this,e).predict(c,l)}predictProba(c,l){let d=W(this,e);if(typeof d.predictProba!="function")throw new Error(`${e}: predictProba not available`);return d.predictProba(c,l)}score(c,l,d){return W(this,e).score(c,l,d)}save(){return W(this,e).save()}dispose(){let c=P(this);c.inner&&typeof c.inner.dispose=="function"&&c.inner.dispose(),c.inner=null,c.disposed=!0}getParams(){let c=P(this),l=c.inner&&typeof c.inner.getParams=="function"?c.inner.getParams():{...c.params};return c.task&&(l.task=c.task),l}setParams(c){let l=P(this),d={...c};if(d.task){let u=d.task;delete d.task,u!==l.task&&l.inner&&this.dispose(),l.task=u}return l.params=d,l.inner&&typeof l.inner.setParams=="function"&&l.inner.setParams(d),this}get task(){return P(this).task}get isFitted(){let c=P(this);return c.inner?c.inner.isFitted!==void 0?c.inner.isFitted:!0:!1}get classes(){let c=P(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=P(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"]),f=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)||f.has(c)||c in i.prototype)continue;let l=Object.getOwnPropertyDescriptor(h.prototype,c);l&&(typeof l.value=="function"?i.prototype[c]=function(...d){return W(this,e)[c](...d)}:l.get&&Object.defineProperty(i.prototype,c,{get(){let d=P(this);if(d.inner)return d.inner[c]},configurable:!0}))}return(s.defaultSearchSpace||t.defaultSearchSpace)&&(i.defaultSearchSpace=()=>s.defaultSearchSpace?.()||t.defaultSearchSpace?.()||{}),(s.budgetSpec||t.budgetSpec)&&(i.budgetSpec=()=>s.budgetSpec?.()||t.budgetSpec?.()||void 0),Object.defineProperty(i,"name",{value:e,configurable:!0}),i}xe.exports={createModelClass:nn,detectTask:be}});var R=x((io,Fe)=>{var{WlearnError:rn,BundleError:on,RegistryError:an,ValidationError:cn,NotFittedError:ln,DisposedError:fn}=k(),{normalizeX:hn,normalizeY:un,makeDense:dn,validateMatrix:pn}=U(),{sha256Sync:mn}=lt(),{encodeBundle:wn,decodeBundle:gn,validateBundle:bn,encodeJSON:yn,decodeJSON:xn}=C(),{register:An,load:Fn,loadSync:Sn,getRegistry:En}=K(),{Pipeline:In}=Tt(),{Step:Pn}=dt(),{Preprocessor:vn}=Gt(),{StandardScaler:Nn,MinMaxScaler:kn}=oe(),{makeLCG:Mn,shuffle:qn}=mt(),{accuracy:_n,r2Score:$n,meanSquaredError:On,meanAbsoluteError:Ln,confusionMatrix:Bn,precisionScore:Dn,recallScore:zn,f1Score:Rn,logLoss:jn,rocAuc:Un}=bt(),{kFold:Vn,stratifiedKFold:Xn,trainTestSplit:Yn,crossValScore:Tn,getScorer:Cn}=pe(),{isPromiseLike:Wn,lift:Jn}=ge(),{createModelClass:Gn,detectTask:Kn}=Ae();Fe.exports={WlearnError:rn,BundleError:on,RegistryError:an,ValidationError:cn,NotFittedError:ln,DisposedError:fn,normalizeX:hn,normalizeY:un,makeDense:dn,validateMatrix:pn,sha256Sync:mn,encodeBundle:wn,decodeBundle:gn,validateBundle:bn,encodeJSON:yn,decodeJSON:xn,register:An,load:Fn,loadSync:Sn,getRegistry:En,Pipeline:In,Step:Pn,Preprocessor:vn,StandardScaler:Nn,MinMaxScaler:kn,makeLCG:Mn,shuffle:qn,accuracy:_n,r2Score:$n,meanSquaredError:On,meanAbsoluteError:Ln,confusionMatrix:Bn,precisionScore:Dn,recallScore:zn,f1Score:Rn,logLoss:jn,rocAuc:Un,kFold:Vn,stratifiedKFold:Xn,trainTestSplit:Yn,crossValScore:Tn,getScorer:Cn,isPromiseLike:Wn,lift:Jn,createModelClass:Gn,detectTask:Kn}});var qe=x((ao,Me)=>{var{encodeBundle:Hn,decodeBundle:Zn,register:Se,load:Ee,normalizeX:At,normalizeY:Ie,accuracy:Qn,r2Score:tr,ValidationError:nt,NotFittedError:er,DisposedError:sr,lift:Pe}=R(),ve="wlearn.ensemble.voting.classifier@1",Ne="wlearn.ensemble.voting.regressor@1",ke=!1,Ft=class s{#t;#e;#r;#n;#o;#s;#i=!1;#f=!1;constructor(t){this.#t=t.estimators||[],this.#r=t.weights||null,this.#n=t.voting||"soft",this.#o=t.task||"classification",this.#e=null,this.#s=null,s._register()}static async create(t={}){return new s(t)}#l(){if(this.#f)throw new sr("VotingEnsemble has been disposed.")}#a(){if(this.#l(),!this.#i)throw new er("VotingEnsemble is not fitted. Call fit() first.")}async fit(t,n){this.#l();let e=At(t),o=Ie(n);if(this.#o==="classification"){let r=new Set;for(let i=0;i<o.length;i++)r.add(o[i]);this.#s=new Int32Array([...r].sort((i,a)=>i-a))}this.#r||(this.#r=new Float64Array(this.#t.length).fill(1/this.#t.length)),this.#e=[];for(let[r,i,a]of this.#t){let f=await i.create(a||{});f.fit(e,o),this.#e.push(f)}return this.#i=!0,this}predict(t){this.#a();let n=At(t),e=n.rows;if(this.#o==="regression")return this.#c(n,e);if(this.#n==="soft"){let o=this.predictProba(n);return Pe(o,r=>{let i=this.#s.length,a=new Float64Array(e);for(let f=0;f<e;f++){let h=0,c=-1/0;for(let l=0;l<i;l++)r[f*i+l]>c&&(c=r[f*i+l],h=l);a[f]=this.#s[h]}return a})}return this.#h(n,e)}predictProba(t){if(this.#a(),this.#o!=="classification")throw new nt("predictProba is only available for classification");if(this.#n==="hard")throw new nt('predictProba requires voting="soft"');let n=At(t),e=n.rows,o=this.#s.length,r=[],i=!1;for(let f=0;f<this.#e.length;f++){let h=this.#e[f].predictProba(n);h!=null&&typeof h.then=="function"&&(i=!0),r.push(h)}let a=f=>{let h=new Float64Array(e*o);for(let c=0;c<f.length;c++){let l=f[c],d=this.#r[c];for(let u=0;u<e*o;u++)h[u]+=d*l[u]}return h};return i?Promise.all(r).then(a):a(r)}score(t,n){this.#a();let e=this.predict(t),o=Ie(n),r=this.#o==="classification"?Qn:tr;return Pe(e,i=>r(o,i))}save(){this.#a();let n={typeId:this.#o==="classification"?ve:Ne,params:{task:this.#o,voting:this.#n,weights:[...this.#r],estimatorNames:this.#t.map(o=>o[0]),classes:this.#s?[...this.#s]:null}},e=this.#e.map((o,r)=>({id:this.#t[r][0],data:o.save(),mediaType:"application/x-wlearn-bundle"}));return Hn(n,e)}static async load(t){let{manifest:n,toc:e,blobs:o}=Zn(t),r=n.params,i=new s({task:r.task,voting:r.voting,weights:new Float64Array(r.weights)});i.#s=r.classes?new Int32Array(r.classes):null,i.#t=r.estimatorNames.map(a=>[a,null,null]),i.#e=[];for(let a of r.estimatorNames){let f=e.find(l=>l.id===a);if(!f)throw new nt(`No artifact for estimator "${a}"`);let h=o.subarray(f.offset,f.offset+f.length),c=await Ee(h);i.#e.push(c)}return i.#i=!0,i}dispose(){if(!this.#f&&(this.#f=!0,this.#e))for(let t of this.#e)t.dispose()}getParams(){return{task:this.#o,voting:this.#n,weights:this.#r?[...this.#r]:null,estimatorNames:this.#t.map(t=>t[0])}}setParams(t){return this.#l(),t.voting!==void 0&&(this.#n=t.voting),t.weights!==void 0&&(this.#r=new Float64Array(t.weights)),this}get capabilities(){return{classifier:this.#o==="classification",regressor:this.#o==="regression",predictProba:this.#o==="classification"&&this.#n==="soft",decisionFunction:!1,sampleWeight:!1,csr:!1,earlyStopping:!1}}get isFitted(){return this.#i}get classes(){return this.#s}#c(t,n){let e=[],o=!1;for(let i=0;i<this.#e.length;i++){let a=this.#e[i].predict(t);a!=null&&typeof a.then=="function"&&(o=!0),e.push(a)}let r=i=>{let a=new Float64Array(n);for(let f=0;f<i.length;f++){let h=this.#r[f];for(let c=0;c<n;c++)a[c]+=h*i[f][c]}return a};return o?Promise.all(e).then(r):r(e)}#h(t,n){let e=[],o=!1;for(let i=0;i<this.#e.length;i++){let a=this.#e[i].predict(t);a!=null&&typeof a.then=="function"&&(o=!0),e.push(a)}let r=i=>{let a=this.#s.length,f=new Float64Array(n);for(let h=0;h<n;h++){let c=new Float64Array(a);for(let u=0;u<i.length;u++){let p=i[u][h],m=this.#s.indexOf(p);m>=0&&(c[m]+=this.#r[u])}let l=0,d=-1/0;for(let u=0;u<a;u++)c[u]>d&&(d=c[u],l=u);f[h]=this.#s[l]}return f};return o?Promise.all(e).then(r):r(e)}static _register(){if(ke)return;ke=!0;let t=(n,e,o)=>s._loadFromParts(n,e,o);Se(ve,t),Se(Ne,t)}static async _loadFromParts(t,n,e){let o=t.params,r=new s({task:o.task,voting:o.voting,weights:new Float64Array(o.weights)});r.#s=o.classes?new Int32Array(o.classes):null,r.#t=o.estimatorNames.map(i=>[i,null,null]),r.#e=[];for(let i of o.estimatorNames){let a=n.find(c=>c.id===i);if(!a)throw new nt(`No artifact for estimator "${i}"`);let f=e.subarray(a.offset,a.offset+a.length),h=await Ee(f);r.#e.push(h)}return r.#i=!0,r}};Me.exports={VotingEnsemble:Ft}});var Ue=x((co,je)=>{var{encodeBundle:nr,decodeBundle:rr,register:_e,load:$e,normalizeX:Oe,normalizeY:Le,accuracy:or,r2Score:ir,stratifiedKFold:ar,kFold:cr,ValidationError:J,NotFittedError:lr,DisposedError:fr,lift:St}=R(),Be="wlearn.ensemble.stacking.classifier@1",De="wlearn.ensemble.stacking.regressor@1",ze=!1,Et=class s{#t;#e;#r;#n;#o;#s;#i;#f;#l;#a;#c;#h=!1;#d=!1;constructor(t){this.#t=t.estimators||[],this.#e=t.finalEstimator||null,this.#o=t.cv||5,this.#s=t.task||"classification",this.#i=t.passthrough||!1,this.#f=t.seed??42,this.#r=null,this.#n=null,this.#l=null,this.#a=0,this.#c=0,s._register()}static async create(t={}){return new s(t)}#p(){if(this.#d)throw new fr("StackingEnsemble has been disposed.")}#u(){if(this.#p(),!this.#h)throw new lr("StackingEnsemble is not fitted. Call fit() first.")}async fit(t,n){if(this.#p(),!this.#e)throw new J("StackingEnsemble requires a finalEstimator");let e=Oe(t),o=Le(n),r=e.rows;if(this.#s==="classification"){let p=new Set;for(let m=0;m<o.length;m++)p.add(o[m]);this.#l=new Int32Array([...p].sort((m,w)=>m-w)),this.#a=this.#l.length}let i=this.#s==="classification"?ar(o,this.#o,{shuffle:!0,seed:this.#f}):cr(r,this.#o,{shuffle:!0,seed:this.#f}),a=this.#t.length,f=this.#s==="classification"?this.#a:1,h=a*f,c=new Float64Array(r*h);for(let p=0;p<a;p++){let[,m,w]=this.#t[p];for(let{train:b,test:g}of i){let y=Re(e,b),F=hr(o,b),E=Re(e,g),v=await m.create(w||{});try{if(v.fit(y,F),this.#s==="classification"){let S=await v.predictProba(E);for(let A=0;A<g.length;A++){let j=g[A];for(let _=0;_<this.#a;_++)c[j*h+p*f+_]=S[A*this.#a+_]}}else{let S=await v.predict(E);for(let A=0;A<g.length;A++)c[g[A]*h+p]=S[A]}}finally{v.dispose()}}}let l;if(this.#i){this.#c=h+e.cols;let p=new Float64Array(r*this.#c);for(let m=0;m<r;m++)p.set(c.subarray(m*h,(m+1)*h),m*this.#c),p.set(e.data.subarray(m*e.cols,(m+1)*e.cols),m*this.#c+h);l={data:p,rows:r,cols:this.#c}}else this.#c=h,l={data:c,rows:r,cols:h};this.#r=[];for(let[,p,m]of this.#t){let w=await p.create(m||{});w.fit(e,o),this.#r.push(w)}let[,d,u]=this.#e;return this.#n=await d.create(u||{}),this.#n.fit(l,o),this.#h=!0,this}predict(t){this.#u();let n=this.#m(t);return St(n,e=>this.#n.predict(e))}predictProba(t){if(this.#u(),this.#s!=="classification")throw new J("predictProba is only available for classification");if(typeof this.#n.predictProba!="function")throw new J("Meta-model does not support predictProba");let n=this.#m(t);return St(n,e=>this.#n.predictProba(e))}score(t,n){this.#u();let e=this.predict(t),o=Le(n),r=this.#s==="classification"?or:ir;return St(e,i=>r(o,i))}save(){this.#u();let n={typeId:this.#s==="classification"?Be:De,params:{task:this.#s,cv:this.#o,passthrough:this.#i,seed:this.#f,estimatorNames:this.#t.map(o=>o[0]),metaName:this.#e[0],classes:this.#l?[...this.#l]:null,nMetaCols:this.#c}},e=this.#r.map((o,r)=>({id:this.#t[r][0],data:o.save(),mediaType:"application/x-wlearn-bundle"}));return e.push({id:this.#e[0],data:this.#n.save(),mediaType:"application/x-wlearn-bundle"}),nr(n,e)}static async load(t){let{manifest:n,toc:e,blobs:o}=rr(t);return s._loadFromParts(n,e,o)}dispose(){if(!this.#d){if(this.#d=!0,this.#r)for(let t of this.#r)t.dispose();this.#n&&this.#n.dispose()}}getParams(){return{task:this.#s,cv:this.#o,passthrough:this.#i,seed:this.#f,estimatorNames:this.#t.map(t=>t[0]),metaName:this.#e?this.#e[0]:null}}setParams(t){return this.#p(),t.cv!==void 0&&(this.#o=t.cv),t.passthrough!==void 0&&(this.#i=t.passthrough),t.seed!==void 0&&(this.#f=t.seed),this}get capabilities(){return{classifier:this.#s==="classification",regressor:this.#s==="regression",predictProba:this.#s==="classification",decisionFunction:!1,sampleWeight:!1,csr:!1,earlyStopping:!1}}get isFitted(){return this.#h}get classes(){return this.#l}#m(t){let n=Oe(t),e=n.rows,o=this.#r.length,r=this.#s==="classification"?this.#a:1,i=o*r,a=[],f=!1;for(let c=0;c<o;c++){let l=this.#s==="classification"?this.#r[c].predictProba(n):this.#r[c].predict(n);l!=null&&typeof l.then=="function"&&(f=!0),a.push(l)}let h=c=>{let l=new Float64Array(e*this.#c);for(let d=0;d<o;d++)if(this.#s==="classification"){let u=c[d];for(let p=0;p<e;p++)for(let m=0;m<this.#a;m++)l[p*this.#c+d*r+m]=u[p*this.#a+m]}else{let u=c[d];for(let p=0;p<e;p++)l[p*this.#c+d]=u[p]}if(this.#i)for(let d=0;d<e;d++)l.set(n.data.subarray(d*n.cols,(d+1)*n.cols),d*this.#c+i);return{data:l,rows:e,cols:this.#c}};return f?Promise.all(a).then(h):h(a)}static _register(){if(ze)return;ze=!0;let t=(n,e,o)=>s._loadFromParts(n,e,o);_e(Be,t),_e(De,t)}static async _loadFromParts(t,n,e){let o=t.params,r=new s({task:o.task,cv:o.cv,passthrough:o.passthrough,seed:o.seed});r.#l=o.classes?new Int32Array(o.classes):null,r.#a=r.#l?r.#l.length:0,r.#c=o.nMetaCols,r.#t=o.estimatorNames.map(f=>[f,null,null]),r.#e=[o.metaName,null,null],r.#r=[];for(let f of o.estimatorNames){let h=n.find(l=>l.id===f);if(!h)throw new J(`No artifact for base estimator "${f}"`);let c=e.subarray(h.offset,h.offset+h.length);r.#r.push(await $e(c))}let i=n.find(f=>f.id===o.metaName);if(!i)throw new J(`No artifact for meta estimator "${o.metaName}"`);let a=e.subarray(i.offset,i.offset+i.length);return r.#n=await $e(a),r.#h=!0,r}};function Re(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function hr(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}je.exports={StackingEnsemble:Et}});var He=x((lo,Ke)=>{var{encodeBundle:ur,decodeBundle:dr,register:Ve,load:pr,normalizeX:It,normalizeY:Xe,accuracy:mr,r2Score:wr,stratifiedKFold:gr,kFold:br,ValidationError:Ye,NotFittedError:yr,DisposedError:xr,lift:Te}=R(),Ce="wlearn.ensemble.bagged.classifier@1",We="wlearn.ensemble.bagged.regressor@1",Je=!1,Pt=class s{#t;#e;#r;#n;#o;#s;#i;#f=0;#l=0;#a;#c;#h=!1;#d=!1;constructor(t={}){this.#t=t.estimator||null,this.#e=t.kFold||5,this.#r=t.nRepeats||1,this.#n=t.task||"classification",this.#o=t.seed??42,this.#s=null,this.#i=null,this.#a=null,this.#c=null,s._register()}static async create(t={}){return new s(t)}#p(){if(this.#d)throw new xr("BaggedEstimator has been disposed.")}#u(){if(this.#p(),!this.#h)throw new yr("BaggedEstimator is not fitted. Call fit() first.")}async fit(t,n){this.#p();let e=It(t),o=Xe(n),r=e.rows;if(this.#l=r,this.#n==="classification"){let f=new Set;for(let h=0;h<o.length;h++)f.add(o[h]);this.#i=new Int32Array([...f].sort((h,c)=>h-c)),this.#f=this.#i.length}this.#n==="classification"?this.#a=new Float64Array(r*this.#f):this.#a=new Float64Array(r),this.#c=new Uint8Array(r);let[,i,a]=this.#t;this.#s=[];for(let f=0;f<this.#r;f++){let h=this.#o+f,c=this.#n==="classification"?gr(o,this.#e,{shuffle:!0,seed:h}):br(r,this.#e,{shuffle:!0,seed:h});for(let{train:l,test:d}of c){let u=Ge(e,l),p=Ar(o,l),m=Ge(e,d),w=await i.create(a||{});if(w.fit(u,p),this.#n==="classification"){let b=await w.predictProba(m),g=this.#f;for(let y=0;y<d.length;y++){let F=d[y];for(let E=0;E<g;E++)this.#a[F*g+E]+=b[y*g+E]}}else{let b=await w.predict(m);for(let g=0;g<d.length;g++)this.#a[d[g]]+=b[g]}for(let b=0;b<d.length;b++)this.#c[d[b]]+=1;this.#s.push(w)}}return this.#h=!0,this}predict(t){this.#u();let n=It(t),e=n.rows;if(this.#n==="regression")return this.#m(n,e);let o=this.predictProba(n);return Te(o,r=>{let i=this.#f,a=new Float64Array(e);for(let f=0;f<e;f++){let h=0,c=-1/0;for(let l=0;l<i;l++)r[f*i+l]>c&&(c=r[f*i+l],h=l);a[f]=this.#i[h]}return a})}predictProba(t){if(this.#u(),this.#n!=="classification")throw new Ye("predictProba is only available for classification");let n=It(t),e=n.rows,o=this.#f,r=this.#s.length,i=[],a=!1;for(let h of this.#s){let c=h.predictProba(n);c!=null&&typeof c.then=="function"&&(a=!0),i.push(c)}let f=h=>{let c=new Float64Array(e*o);for(let l of h)for(let d=0;d<e*o;d++)c[d]+=l[d];for(let l=0;l<e*o;l++)c[l]/=r;return c};return a?Promise.all(i).then(f):f(i)}score(t,n){this.#u();let e=this.predict(t),o=Xe(n),r=this.#n==="classification"?mr:wr;return Te(e,i=>r(o,i))}#m(t,n){let e=this.#s.length,o=[],r=!1;for(let a of this.#s){let f=a.predict(t);f!=null&&typeof f.then=="function"&&(r=!0),o.push(f)}let i=a=>{let f=new Float64Array(n);for(let h of a)for(let c=0;c<n;c++)f[c]+=h[c];for(let h=0;h<n;h++)f[h]/=e;return f};return r?Promise.all(o).then(i):i(o)}get oofPredictions(){this.#u();let t=new Uint8Array(this.#c);for(let e=0;e<t.length;e++)t[e]===0&&(t[e]=1);if(this.#n==="classification"){let e=this.#f,o=new Float64Array(this.#a);for(let r=0;r<this.#l;r++){let i=t[r];for(let a=0;a<e;a++)o[r*e+a]/=i}return o}let n=new Float64Array(this.#a);for(let e=0;e<this.#l;e++)n[e]/=t[e];return n}save(){this.#u();let n={typeId:this.#n==="classification"?Ce:We,params:{task:this.#n,kFold:this.#e,nRepeats:this.#r,seed:this.#o,estimatorName:this.#t[0],classes:this.#i?[...this.#i]:null,nClasses:this.#f,nSamples:this.#l}},e=this.#s.map((i,a)=>({id:`fold_${a}`,data:i.save(),mediaType:"application/x-wlearn-bundle"})),o=this.oofPredictions,r=new Uint8Array(o.buffer,o.byteOffset,o.byteLength);return e.push({id:"oof",data:r,mediaType:"application/octet-stream"}),ur(n,e)}static async load(t){let{manifest:n,toc:e,blobs:o}=dr(t);return s._loadFromParts(n,e,o)}dispose(){if(!this.#d){if(this.#d=!0,this.#s)for(let t of this.#s)t.dispose();this.#s=null,this.#a=null,this.#c=null}}getParams(){return{task:this.#n,kFold:this.#e,nRepeats:this.#r,seed:this.#o,estimatorName:this.#t?this.#t[0]:null}}setParams(t){return this.#p(),t.kFold!==void 0&&(this.#e=t.kFold),t.nRepeats!==void 0&&(this.#r=t.nRepeats),t.seed!==void 0&&(this.#o=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.#i}static _register(){if(Je)return;Je=!0;let t=(n,e,o)=>s._loadFromParts(n,e,o);Ve(Ce,t),Ve(We,t)}static async _loadFromParts(t,n,e){let o=t.params,r=new s({task:o.task,kFold:o.kFold||5,nRepeats:o.nRepeats||1,seed:o.seed??42});r.#i=o.classes?new Int32Array(o.classes):null,r.#f=o.nClasses||0,r.#l=o.nSamples||0,r.#t=[o.estimatorName||"base",null,null];let i=r.#e*r.#r;r.#s=[];for(let f=0;f<i;f++){let h=`fold_${f}`,c=n.find(d=>d.id===h);if(!c)throw new Ye(`No artifact for "${h}"`);let l=e.subarray(c.offset,c.offset+c.length);r.#s.push(await pr(l))}let a=n.find(f=>f.id==="oof");if(a){let f=e.subarray(a.offset,a.offset+a.length),h=new Float64Array(f.buffer.slice(f.byteOffset,f.byteOffset+f.byteLength));r.#a=h,r.#c=new Uint8Array(r.#l).fill(1)}else r.#n==="classification"?r.#a=new Float64Array(r.#l*r.#f):r.#a=new Float64Array(r.#l),r.#c=new Uint8Array(r.#l);return r.#h=!0,r}};function Ge(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function Ar(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}Ke.exports={BaggedEstimator:Pt}});var Nt=x((fo,Qe)=>{var{ValidationError:Ze}=R();function vt(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 o=-1;for(let a=0;a<t;a++)n[a]*(a+1)>e[a]-1&&(o=a);if(o<0){let a=new Float64Array(t);return a.fill(1/t),a}let r=(e[o]-1)/(o+1),i=new Float64Array(t);for(let a=0;a<t;a++)i[a]=Math.max(s[a]-r,0);return i}function Fr(s,t,n,{task:e="classification",lr:o=.05,nIter:r=100}={}){let i=s.length,a=t.length;if(i===0)throw new Ze("optimizeWeights: need at least 1 model");if(i===1)return new Float64Array([1]);let f=new Float64Array(n),h=1e-15;if(e==="classification"){let l=s[0].length/a;if(l!==Math.floor(l))throw new Ze("optimizeWeights: prediction length must be divisible by n");for(let d=0;d<r;d++){let u=new Float64Array(i);for(let m=0;m<a;m++){let w=t[m]|0,b=0;for(let g=0;g<i;g++)b+=f[g]*s[g][m*l+w];b=Math.max(b,h);for(let g=0;g<i;g++)u[g]-=s[g][m*l+w]/b}for(let m=0;m<i;m++)u[m]/=a;for(let m=0;m<i;m++)f[m]-=o*u[m];let p=vt(f);for(let m=0;m<i;m++)f[m]=p[m]}}else for(let c=0;c<r;c++){let l=new Float64Array(i);for(let u=0;u<a;u++){let p=0;for(let w=0;w<i;w++)p+=f[w]*s[w][u];let m=t[u]-p;for(let w=0;w<i;w++)l[w]-=2*m*s[w][u]}for(let u=0;u<i;u++)l[u]/=a;for(let u=0;u<i;u++)f[u]-=o*l[u];let d=vt(f);for(let u=0;u<i;u++)f[u]=d[u]}return f}Qe.exports={optimizeWeights:Fr,projectSimplex:vt}});var ss=x((ho,es)=>{var{getScorer:Sr,normalizeY:Er,ValidationError:ts}=R(),{optimizeWeights:Ir}=Nt();function Pr(s,t,{maxSize:n=20,scoring:e="accuracy",task:o="classification",nClasses:r=0,refineWeights:i=!0}={}){let a=Er(t),f=a.length,h=s.length;if(h===0)throw new ts("caruanaSelect: need at least 1 candidate");let c=Sr(e),l=s[0].length/f;if(l!==Math.floor(l))throw new ts("caruanaSelect: oofPredictions[0].length must be divisible by n");o==="classification"&&r===0&&(r=l);let d=new Float64Array(s[0].length),u=[],p=[];for(let y=0;y<n;y++){let F=-1,E=-1/0;for(let S=0;S<h;S++){let A=vr(d,s[S],y,y+1),j=Nr(A,a,c,o,r,f);j>E&&(E=j,F=S)}u.push(F),p.push(E);let v=s[F];for(let S=0;S<d.length;S++)d[S]=(y*d[S]+v[S])/(y+1)}let m=new Map;for(let y of u)m.set(y,(m.get(y)||0)+1);let w=new Int32Array([...m.keys()].sort((y,F)=>y-F)),b=new Float64Array(w.length);for(let y=0;y<w.length;y++)b[y]=m.get(w[y])/n;let g={indices:w,weights:b,scores:new Float64Array(p)};if(i&&w.length>1){let y=Array.from(w,F=>s[F]);g.weights=Ir(y,a,b,{task:o})}return g}function vr(s,t,n,e){let o=new Float64Array(s.length);for(let r=0;r<s.length;r++)o[r]=(n*s[r]+t[r])/e;return o}function Nr(s,t,n,e,o,r){if(e==="regression")return n(t,s);let i=new Float64Array(r);for(let a=0;a<r;a++){let f=0,h=-1/0;for(let c=0;c<o;c++)s[a*o+c]>h&&(h=s[a*o+c],f=c);i[a]=f}return n(t,i)}es.exports={caruanaSelect:Pr}});var os=x((po,rs)=>{var{stratifiedKFold:kr,kFold:Mr,normalizeX:qr,normalizeY:_r,ValidationError:uo}=R();async function $r(s,t,n,{cv:e=5,seed:o=42,task:r="classification"}={}){let i=qr(t),a=_r(n),f=i.rows,h=r==="classification"?kr(a,e,{shuffle:!0,seed:o}):Mr(f,e,{shuffle:!0,seed:o}),c=null,l=0;if(r==="classification"){let u=new Set;for(let p=0;p<a.length;p++)u.add(a[p]);c=new Int32Array([...u].sort((p,m)=>p-m)),l=c.length}let d=[];for(let[u,p,m]of s){let w;r==="classification"?w=new Float64Array(f*l):w=new Float64Array(f);for(let{train:b,test:g}of h){let y=ns(i,b),F=Or(a,b),E=ns(i,g),v=await p.create(m||{});try{if(v.fit(y,F),r==="classification"){let S=await v.predictProba(E);for(let A=0;A<g.length;A++){let j=g[A];for(let _=0;_<l;_++)w[j*l+_]=S[A*l+_]}}else{let S=await v.predict(E);for(let A=0;A<g.length;A++)w[g[A]]=S[A]}}finally{v.dispose()}}d.push(w)}return{oofPreds:d,classes:c}}function ns(s,t){let{data:n,cols:e}=s,o=t.length,r=new Float64Array(o*e);for(let i=0;i<o;i++){let a=t[i]*e;r.set(n.subarray(a,a+e),i*e)}return{data:r,rows:o,cols:e}}function Or(s,t){let n=new s.constructor(t.length);for(let e=0;e<t.length;e++)n[e]=s[t[e]];return n}rs.exports={getOofPredictions:$r}});var Vr=x((mo,is)=>{var{VotingEnsemble:Lr}=qe(),{StackingEnsemble:Br}=Ue(),{BaggedEstimator:Dr}=He(),{caruanaSelect:zr}=ss(),{getOofPredictions:Rr}=os(),{optimizeWeights:jr,projectSimplex:Ur}=Nt();is.exports={VotingEnsemble:Lr,StackingEnsemble:Br,BaggedEstimator:Dr,caruanaSelect:zr,getOofPredictions:Rr,optimizeWeights:jr,projectSimplex:Ur}});return Vr();})();
2
+ var {VotingEnsemble,StackingEnsemble,BaggedEstimator,caruanaSelect,getOofPredictions,optimizeWeights,projectSimplex}=__ensemble;export{VotingEnsemble,StackingEnsemble,BaggedEstimator,caruanaSelect,getOofPredictions,optimizeWeights,projectSimplex};
package/package.json CHANGED
@@ -1,26 +1,55 @@
1
1
  {
2
2
  "name": "@wlearn/ensemble",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Ensemble methods for wlearn: voting, stacking, Caruana selection",
5
- "type": "module",
5
+ "type": "commonjs",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
- ".": "./src/index.js"
8
+ ".": {
9
+ "require": "./src/index.js",
10
+ "default": "./src/index.js"
11
+ }
9
12
  },
10
13
  "files": [
11
- "src/"
14
+ "src/",
15
+ "dist/",
16
+ "LICENSE",
17
+ "NOTICE",
18
+ "README.md",
19
+ "CHANGELOG.md"
12
20
  ],
13
21
  "sideEffects": false,
14
22
  "dependencies": {
15
- "@wlearn/core": "0.1.0",
16
- "@wlearn/types": "0.1.0"
23
+ "@wlearn/core": "0.2.0"
17
24
  },
18
25
  "scripts": {
19
- "test": "node --test test/*.js"
26
+ "test": "node --test test/*.js",
27
+ "build:browser": "bash scripts/build-browser.sh",
28
+ "prepack": "node scripts/prepack.js"
20
29
  },
21
30
  "publishConfig": {
22
31
  "access": "public"
23
32
  },
33
+ "keywords": [
34
+ "wlearn",
35
+ "ensemble",
36
+ "machine-learning",
37
+ "stacking",
38
+ "voting"
39
+ ],
24
40
  "author": "Anton Zemlyansky",
25
- "license": "MIT"
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/wlearn-org/wlearn.git",
44
+ "directory": "packages/ensemble"
45
+ },
46
+ "license": "Apache-2.0",
47
+ "devDependencies": {
48
+ "esbuild": "^0.27.3",
49
+ "playwright": "^1.58.2"
50
+ },
51
+ "bugs": {
52
+ "url": "https://github.com/wlearn-org/wlearn/issues"
53
+ },
54
+ "homepage": "https://wlearn.org"
26
55
  }
package/src/bagging.js CHANGED
@@ -1,10 +1,10 @@
1
- import {
2
- encodeBundle, decodeBundle, register, load as registryLoad,
1
+ const {
2
+ encodeBundle, decodeBundle, register, load: registryLoad,
3
3
  normalizeX, normalizeY, accuracy, r2Score,
4
4
  stratifiedKFold, kFold,
5
5
  ValidationError, NotFittedError, DisposedError,
6
6
  lift
7
- } from '@wlearn/core'
7
+ } = require('@wlearn/core')
8
8
 
9
9
  const TYPE_ID_CLS = 'wlearn.ensemble.bagged.classifier@1'
10
10
  const TYPE_ID_REG = 'wlearn.ensemble.bagged.regressor@1'
@@ -17,7 +17,7 @@ let _registered = false
17
17
  * seed for fold assignment. OOF predictions are accumulated (sum + count)
18
18
  * and averaged, matching AutoGluon's BaggedEnsembleModel pattern.
19
19
  */
20
- export class BaggedEstimator {
20
+ class BaggedEstimator {
21
21
  #spec // [name, Class, params]
22
22
  #kFold
23
23
  #nRepeats
@@ -408,3 +408,5 @@ function _subsetY(y, indices) {
408
408
  }
409
409
  return out
410
410
  }
411
+
412
+ module.exports = { BaggedEstimator }
package/src/index.js CHANGED
@@ -1,6 +1,16 @@
1
- export { VotingEnsemble } from './voting.js'
2
- export { StackingEnsemble } from './stacking.js'
3
- export { BaggedEstimator } from './bagging.js'
4
- export { caruanaSelect } from './selection.js'
5
- export { getOofPredictions } from './oof.js'
6
- export { optimizeWeights, projectSimplex } from './weights.js'
1
+ const { VotingEnsemble } = require('./voting.js')
2
+ const { StackingEnsemble } = require('./stacking.js')
3
+ const { BaggedEstimator } = require('./bagging.js')
4
+ const { caruanaSelect } = require('./selection.js')
5
+ const { getOofPredictions } = require('./oof.js')
6
+ const { optimizeWeights, projectSimplex } = require('./weights.js')
7
+
8
+ module.exports = {
9
+ VotingEnsemble,
10
+ StackingEnsemble,
11
+ BaggedEstimator,
12
+ caruanaSelect,
13
+ getOofPredictions,
14
+ optimizeWeights,
15
+ projectSimplex,
16
+ }
package/src/oof.js CHANGED
@@ -1,15 +1,9 @@
1
- import { stratifiedKFold, kFold, normalizeX, normalizeY, ValidationError } from '@wlearn/core'
1
+ const { stratifiedKFold, kFold, normalizeX, normalizeY, ValidationError } = require('@wlearn/core')
2
2
 
3
3
  /**
4
4
  * Generate out-of-fold predictions for a list of estimator specs.
5
- *
6
- * @param {Array<[string, Function, Object]>} estimatorSpecs - [name, EstimatorClass, params]
7
- * @param {Object|number[][]} X - feature matrix
8
- * @param {TypedArray|number[]} y - labels
9
- * @param {Object} opts
10
- * @returns {{ oofPreds: Float64Array[], classes: Int32Array|null }}
11
5
  */
12
- export async function getOofPredictions(estimatorSpecs, X, y, {
6
+ async function getOofPredictions(estimatorSpecs, X, y, {
13
7
  cv = 5,
14
8
  seed = 42,
15
9
  task = 'classification',
@@ -94,3 +88,5 @@ function _subsetY(y, indices) {
94
88
  }
95
89
  return out
96
90
  }
91
+
92
+ module.exports = { getOofPredictions }
package/src/selection.js CHANGED
@@ -1,22 +1,10 @@
1
- import { getScorer, normalizeY, ValidationError } from '@wlearn/core'
2
- import { optimizeWeights } from './weights.js'
1
+ const { getScorer, normalizeY, ValidationError } = require('@wlearn/core')
2
+ const { optimizeWeights } = require('./weights.js')
3
3
 
4
4
  /**
5
5
  * Caruana greedy ensemble selection (Caruana et al., 2004).
6
- *
7
- * Selects a weighted subset from a pool of OOF predictions by greedily
8
- * adding the candidate that most improves the ensemble score at each step.
9
- * Candidates can be selected multiple times (with replacement).
10
- *
11
- * @param {Float64Array[]} oofPredictions - per-candidate OOF predictions
12
- * Classification: each is n_samples * n_classes (flat row-major proba)
13
- * Regression: each is n_samples
14
- * @param {TypedArray|number[]} yTrue - true labels
15
- * @param {Object} opts
16
- * @param {boolean} opts.refineWeights - if true, optimize weights after selection
17
- * @returns {{ indices: Int32Array, weights: Float64Array, scores: Float64Array }}
18
6
  */
19
- export function caruanaSelect(oofPredictions, yTrue, {
7
+ function caruanaSelect(oofPredictions, yTrue, {
20
8
  maxSize = 20,
21
9
  scoring = 'accuracy',
22
10
  task = 'classification',
@@ -125,3 +113,5 @@ function _score(preds, yTrue, scorerFn, task, nClasses, n) {
125
113
  }
126
114
  return scorerFn(yTrue, hardPreds)
127
115
  }
116
+
117
+ module.exports = { caruanaSelect }
package/src/stacking.js CHANGED
@@ -1,16 +1,16 @@
1
- import {
2
- encodeBundle, decodeBundle, register, load as registryLoad,
1
+ const {
2
+ encodeBundle, decodeBundle, register, load: registryLoad,
3
3
  normalizeX, normalizeY, accuracy, r2Score,
4
4
  stratifiedKFold, kFold,
5
5
  ValidationError, NotFittedError, DisposedError,
6
6
  lift
7
- } from '@wlearn/core'
7
+ } = require('@wlearn/core')
8
8
 
9
9
  const TYPE_ID_CLS = 'wlearn.ensemble.stacking.classifier@1'
10
10
  const TYPE_ID_REG = 'wlearn.ensemble.stacking.regressor@1'
11
11
  let _registered = false
12
12
 
13
- export class StackingEnsemble {
13
+ class StackingEnsemble {
14
14
  #baseSpecs // [name, Class, params][]
15
15
  #metaSpec // [name, Class, params]
16
16
  #baseModels // fitted base model instances (on full data)
@@ -370,3 +370,5 @@ function _subsetY(y, indices) {
370
370
  }
371
371
  return out
372
372
  }
373
+
374
+ module.exports = { StackingEnsemble }
package/src/voting.js CHANGED
@@ -1,15 +1,15 @@
1
- import {
2
- encodeBundle, decodeBundle, register, load as registryLoad,
1
+ const {
2
+ encodeBundle, decodeBundle, register, load: registryLoad,
3
3
  normalizeX, normalizeY, accuracy, r2Score,
4
4
  ValidationError, NotFittedError, DisposedError,
5
5
  lift
6
- } from '@wlearn/core'
6
+ } = require('@wlearn/core')
7
7
 
8
8
  const TYPE_ID_CLS = 'wlearn.ensemble.voting.classifier@1'
9
9
  const TYPE_ID_REG = 'wlearn.ensemble.voting.regressor@1'
10
10
  let _registered = false
11
11
 
12
- export class VotingEnsemble {
12
+ class VotingEnsemble {
13
13
  #specs // [name, Class, params][]
14
14
  #models // fitted instances
15
15
  #weights
@@ -309,3 +309,5 @@ export class VotingEnsemble {
309
309
  return ens
310
310
  }
311
311
  }
312
+
313
+ module.exports = { VotingEnsemble }
package/src/weights.js CHANGED
@@ -1,13 +1,10 @@
1
- import { ValidationError } from '@wlearn/core'
1
+ const { ValidationError } = require('@wlearn/core')
2
2
 
3
3
  /**
4
4
  * Project vector onto the probability simplex {w: w >= 0, sum(w) = 1}.
5
5
  * O(n log n) algorithm from Duchi et al. 2008.
6
- *
7
- * @param {Float64Array} v - input vector
8
- * @returns {Float64Array} - projected vector
9
6
  */
10
- export function projectSimplex(v) {
7
+ function projectSimplex(v) {
11
8
  const n = v.length
12
9
  if (n === 0) return new Float64Array(0)
13
10
  if (n === 1) return new Float64Array([1.0])
@@ -47,17 +44,8 @@ export function projectSimplex(v) {
47
44
 
48
45
  /**
49
46
  * Optimize ensemble weights via projected gradient descent on the simplex.
50
- *
51
- * Classification: minimizes negative log-loss.
52
- * Regression: minimizes MSE.
53
- *
54
- * @param {Float64Array[]} oofPredictions - per-model OOF predictions
55
- * @param {TypedArray} yTrue - true labels
56
- * @param {Float64Array} initWeights - initial weights (e.g. from Caruana)
57
- * @param {object} opts
58
- * @returns {Float64Array} - optimized weights (>= 0, sum = 1)
59
47
  */
60
- export function optimizeWeights(oofPredictions, yTrue, initWeights, {
48
+ function optimizeWeights(oofPredictions, yTrue, initWeights, {
61
49
  task = 'classification',
62
50
  lr = 0.05,
63
51
  nIter = 100,
@@ -141,3 +129,5 @@ export function optimizeWeights(oofPredictions, yTrue, initWeights, {
141
129
 
142
130
  return w
143
131
  }
132
+
133
+ module.exports = { optimizeWeights, projectSimplex }