@reicek/neataptic-ts 0.1.13 → 0.1.14
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.
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
} else {
|
|
23
23
|
set = multi.deserializeDataSet(new Float64Array(e.data.set));
|
|
24
24
|
}
|
|
25
|
-
};`}}});var ae,mn=H(()=>{"use strict";ae=class{static async getNodeTestWorker(){return(await Promise.resolve().then(()=>(Ie(),Me))).TestWorker}static async getBrowserTestWorker(){return(await Promise.resolve().then(()=>(Te(),Ce))).TestWorker}}});var mt,Jt=H(()=>{"use strict";mn();pt();mt=class e{static workers=ae;static activations=[t=>1/(1+Math.exp(-t)),t=>Math.tanh(t),t=>t,t=>t>0?1:0,t=>t>0?t:0,t=>t/(1+Math.abs(t)),t=>Math.sin(t),t=>Math.exp(-Math.pow(t,2)),t=>(Math.sqrt(Math.pow(t,2)+1)-1)/2+t,t=>t>0?1:-1,t=>2/(1+Math.exp(-t))-1,t=>Math.max(-1,Math.min(1,t)),t=>Math.abs(t),t=>1-t,t=>{let n=1.6732632423543772;return(t>0?t:n*Math.exp(t)-n)*1.0507009873554805},t=>Math.log(1+Math.exp(t))];static serializeDataSet(t){let n=[t[0].input.length,t[0].output.length];for(let s=0;s<t.length;s++){for(let o=0;o<n[0];o++)n.push(t[s].input[o]);for(let o=0;o<n[1];o++)n.push(t[s].output[o])}return n}static activateSerializedNetwork(t,n,s,o,i){for(let r=0;r<o[0];r++)n[r]=t[r];for(let r=2;r<o.length;r++){let c=o[r++],l=o[r++],u=o[r++],p=o[r++],h=o[r++];for(s[c]=(h===-1?1:n[h])*p*s[c]+l;o[r]!==-2;)s[c]+=n[o[r++]]*o[r++]*(o[r++]===-1?1:n[o[r-1]]);n[c]=i[u](s[c])}let a=[];for(let r=n.length-o[1];r<n.length;r++)a.push(n[r]);return a}static deserializeDataSet(t){let n=[],s=t[0]+t[1];for(let o=0;o<(t.length-2)/s;o++){let i=[];for(let r=2+o*s;r<2+o*s+t[0];r++)i.push(t[r]);let a=[];for(let r=2+o*s+t[0];r<2+o*s+s;r++)a.push(t[r]);n.push({input:i,output:a})}return n}static logistic(t){return 1/(1+Math.exp(-t))}static tanh(t){return Math.tanh(t)}static identity(t){return t}static step(t){return t>0?1:0}static relu(t){return t>0?t:0}static softsign(t){return t/(1+Math.abs(t))}static sinusoid(t){return Math.sin(t)}static gaussian(t){return Math.exp(-Math.pow(t,2))}static bentIdentity(t){return(Math.sqrt(Math.pow(t,2)+1)-1)/2+t}static bipolar(t){return t>0?1:-1}static bipolarSigmoid(t){return 2/(1+Math.exp(-t))-1}static hardTanh(t){return Math.max(-1,Math.min(1,t))}static absolute(t){return Math.abs(t)}static inverse(t){return 1-t}static selu(t){let n=1.6732632423543772;return(t>0?t:n*Math.exp(t)-n)*1.0507009873554805}static softplus(t){return Math.log(1+Math.exp(t))}static testSerializedSet(t,n,s,o,i,a){let r=0;for(let c=0;c<t.length;c++){let l=e.activateSerializedNetwork(t[c].input,s,o,i,a);r+=n(t[c].output,l)}return r/t.length}static async getBrowserTestWorker(){let{TestWorker:t}=await Promise.resolve().then(()=>(Te(),Ce));return t}static async getNodeTestWorker(){let{TestWorker:t}=await Promise.resolve().then(()=>(Ie(),Me));return t}}});var Oe,yt,Kt=H(()=>{"use strict";At();Oe=class{buckets=new Map;created=0;reused=0;maxPerBucket=Number.POSITIVE_INFINITY;acquire(t){let n=this.buckets.get(t);if(n&&n.length>0){this.reused++;let s=n.pop();return s.fill(0),s}return this.created++,j.float32Mode?new Float32Array(t):new Array(t).fill(0)}release(t){let n=t.length>>>0;this.buckets.has(n)||this.buckets.set(n,[]);let s=this.buckets.get(n);s.length<this.maxPerBucket&&s.push(t)}clear(){this.buckets.clear(),this.created=0,this.reused=0}stats(){return{created:this.created,reused:this.reused,bucketCount:this.buckets.size}}setMaxPerBucket(t){typeof t=="number"&&t>=0&&(this.maxPerBucket=t)}prewarm(t,n){let s=Math.max(0,Math.floor(n));this.buckets.has(t)||this.buckets.set(t,[]);let o=this.buckets.get(t);for(let i=0;i<s&&o.length<this.maxPerBucket;i++){let a=j.float32Mode?new Float32Array(t):new Array(t).fill(0);o.push(a),this.created++}}bucketSize(t){return this.buckets.get(t)?.length??0}},yt=new Oe});var yn=No((lr,Uo)=>{Uo.exports={name:"@reicek/neataptic-ts",version:"0.1.12",description:"Architecture-free neural network library with genetic algorithm implementations",main:"./dist/neataptic.js",module:"./dist/neataptic.js",types:"./dist/neataptic.d.ts",type:"module",scripts:{test:"jest --config=jest.config.mjs --no-cache --coverage --collect-coverage --runInBand --testPathIgnorePatterns=.e2e.test.ts --verbose",pretest:"npm run build","test:bench":"jest --no-cache --runInBand --verbose --testPathPattern=benchmark","bench:asciiMaze":"node -r ts-node/register test/benchmarks/asciiMaze.micro.bench.ts","test:silent":"jest --no-cache --coverage --collect-coverage --runInBand --testPathIgnorePatterns=.e2e.test.ts --silent",deploy:"npm run build && npm run test:dist && npm publish",build:"npm run build:webpack && npm run build:ts","build:ts":"tsc","build:webpack":"webpack --config webpack.config.js","build:ascii-maze":"npx esbuild test/examples/asciiMaze/browser-entry.ts --bundle --outfile=docs/assets/ascii-maze.bundle.js --platform=browser --format=iife --minify --sourcemap --external:fs --external:child_process --external:path","start:ts":"ts-node src/neataptic.ts","test:e2e":"cross-env FORCE_COLOR=true jest e2e.test.ts --no-cache --runInBand","test:e2e:logs":"npx jest e2e.test.ts --verbose --runInBand --no-cache","test:dist":"npm run build:ts && jest --no-cache --coverage --collect-coverage --runInBand --testPathIgnorePatterns=.e2e.test.ts","docs:build-scripts":"tsc -p tsconfig.docs.json && node scripts/write-dist-docs-pkg.mjs","docs:folders":"npm run docs:build-scripts && node ./dist-docs/scripts/generate-docs.js","docs:html":"npm run docs:build-scripts && node ./dist-docs/scripts/render-docs-html.js","docs:examples":"node scripts/copy-examples.mjs",prettier:"npm run prettier:tests && npm run prettier:src","prettier:tests":"npx prettier --write test/**/*.ts","prettier:src":"npx prettier --write src/**/*.ts",docs:"npm run build:ascii-maze && npm run docs:examples && npm run docs:build-scripts && node ./dist-docs/scripts/generate-docs.js && node ./dist-docs/scripts/render-docs-html.js","onnx:export":"node scripts/export-onnx.mjs"},exports:{".":{types:"./dist/neataptic.d.ts",import:"./dist/neataptic.js"}},devDependencies:{"@types/chai":"^5.2.2","@types/fs-extra":"^11.0.4","@types/jest":"^30.0.0","@types/node":"^24.3.0","@types/seedrandom":"^3.0.8","@types/webpack":"^5.28.5","@types/webpack-dev-server":"^4.7.2",chai:"^6.0.1","copy-webpack-plugin":"^13.0.1","cross-env":"^10.0.0",esbuild:"^0.25.9","fast-glob":"^3.3.3","fs-extra":"^11.3.1",husky:"^9.1.7",jest:"^30.0.5","jest-environment-jsdom":"^30.0.5","jsdoc-to-markdown":"^9.1.2",marked:"^16.2.0",mkdocs:"^0.0.1",puppeteer:"^24.17.0","ts-jest":"^29.4.1","ts-loader":"^9.5.2","ts-morph":"^26.0.0","ts-node":"^10.9.2",typescript:"^5.9.2","undici-types":"^7.15.0",webpack:"^5.101.3","webpack-cli":"^6.0.1"},repository:{type:"git",url:"https://github.com/reicek/NeatapticTS.git"},keywords:["neural network","machine learning","genetic algorithm","mutation","neat"],author:{name:"Cesar Anton",email:"reicek@gmail.com"},license:"MIT",publishConfig:{access:"public",registry:"https://registry.npmjs.org/"},bugs:{url:"https://github.com/reicek/NeatapticTS/issues",email:"reicek@gmail.com"},homepage:"https://reicek.github.io/NeatapticTS/",engines:{node:">=22.0.0"},prettier:{singleQuote:!0},dependencies:{seedrandom:"^3.0.5",undici:"^7.15.0"}}});function zo(e){let t=new Set;e.nodes.forEach(n=>n.connections?.out.forEach(s=>t.add(s))),e.connections=Array.from(t)}function Zt(e){let t=(e?.name||"").toUpperCase();return t.includes("TANH")?"Tanh":t.includes("LOGISTIC")||t.includes("SIGMOID")?"Sigmoid":t.includes("RELU")?"Relu":(e&&console.warn(`Unsupported activation function ${e.name} for ONNX export, defaulting to Identity.`),"Identity")}function qo(e){let t=e.nodes.filter(r=>r.type==="input"),n=e.nodes.filter(r=>r.type==="output"),s=e.nodes.filter(r=>r.type==="hidden");if(s.length===0)return[t,n];let o=[...s],i=t,a=[];for(;o.length;){let r=o.filter(c=>c.connections.in.every(l=>i.includes(l.from)));if(!r.length)throw new Error("Invalid network structure for ONNX export: cannot resolve layered ordering.");a.push(i),i=r,o=o.filter(c=>!r.includes(c))}return a.push(i),a.push(n),a}function Vo(e,t,n){for(let s=1;s<e.length;s++){let o=e[s-1],i=e[s],a=new Set(i.map(r=>r.squash&&r.squash.name));if(a.size>1&&!n.allowMixedActivations)throw new Error(`ONNX export error: Mixed activation functions detected in layer ${s}. (enable allowMixedActivations to decompose layer)`);a.size>1&&n.allowMixedActivations&&console.warn(`Warning: Mixed activations in layer ${s}; exporting per-neuron Gemm + Activation (+Concat) baseline.`);for(let r of i)for(let c of o)if(!r.connections.in.some(u=>u.from===c)&&!n.allowPartialConnectivity)throw new Error(`ONNX export error: Missing connection from node ${c.index} to node ${r.index} in layer ${s}. (enable allowPartialConnectivity)`)}}function Yo(e,t,n={}){let{includeMetadata:s=!1,opset:o=18,batchDimension:i=!1,legacyNodeOrdering:a=!1,producerName:r="neataptic-ts",producerVersion:c,docString:l}=n,u=t[0],p=t[t.length-1],h=i?[{dim_param:"N"},{dim_value:u.length}]:[{dim_value:u.length}],d=i?[{dim_param:"N"},{dim_value:p.length}]:[{dim_value:p.length}],f={graph:{inputs:[{name:"input",type:{tensor_type:{elem_type:1,shape:{dim:h}}}}],outputs:[{name:"output",type:{tensor_type:{elem_type:1,shape:{dim:d}}}}],initializer:[],node:[]}};if(s){let y=(()=>{try{return yn().version}catch{return"0.0.0"}})();f.ir_version=9,f.opset_import=[{version:o,domain:""}],f.producer_name=r,f.producer_version=c||y,f.doc_string=l||"Exported from NeatapticTS ONNX exporter (phases 1-2 baseline)"}let m="input",b=[];if(n.allowRecurrent&&n.recurrentSingleStep)for(let y=1;y<t.length-1;y++){let A=t[y];if(A.some(N=>N.connections.self.length>0)){b.push(y);let N=y===1?"hidden_prev":`hidden_prev_l${y}`;f.graph.inputs.push({name:N,type:{tensor_type:{elem_type:1,shape:{dim:i?[{dim_param:"N"},{dim_value:A.length}]:[{dim_value:A.length}]}}}})}}let g=[];for(let y=1;y<t.length;y++){let A=t[y-1],N=t[y],v=y===t.length-1;v||g.push(N.length);let w=n.conv2dMappings?.find(_=>_.layerIndex===y);if(w){let _=w.inHeight*w.inWidth*w.inChannels,I=A.length,L=w.outChannels*w.outHeight*w.outWidth,$=N.length,k=[w.padTop||0,w.padLeft||0,w.padBottom||0,w.padRight||0];if(!(_===I&&L===$))console.warn(`Conv2D mapping for layer ${y} skipped: dimension mismatch (expected prev=${_} got ${I}; expected this=${L} got ${$}).`);else{let M=[],T=[];for(let V=0;V<w.outChannels;V++){let rt=V*w.outHeight*w.outWidth,it=N[rt];T.push(it.bias);for(let G=0;G<w.inChannels;G++)for(let X=0;X<w.kernelHeight;X++)for(let Z=0;Z<w.kernelWidth;Z++){let at=G*(w.inHeight*w.inWidth)+X*w.inWidth+Z,et=A[at],J=it.connections.in.find(ot=>ot.from===et);M.push(J?J.weight:0)}}let D=`ConvW${y-1}`,E=`ConvB${y-1}`;f.graph.initializer.push({name:D,data_type:1,dims:[w.outChannels,w.inChannels,w.kernelHeight,w.kernelWidth],float_data:M}),f.graph.initializer.push({name:E,data_type:1,dims:[w.outChannels],float_data:T});let R=`Conv_${y}`;f.graph.node.push({op_type:"Conv",input:[m,D,E],output:[R],name:`conv_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:[w.kernelHeight,w.kernelWidth]},{name:"strides",type:"INTS",ints:[w.strideHeight,w.strideWidth]},{name:"pads",type:"INTS",ints:k}]});let O=w.activation||Zt(N[0].squash),P=`Layer_${y}`;f.graph.node.push({op_type:O,input:[R],output:[P],name:`act_conv_l${y}`}),m=P;let C=n.pool2dMappings?.find(V=>V.afterLayerIndex===y);if(C){let V=[C.kernelHeight,C.kernelWidth],rt=[C.strideHeight,C.strideWidth],it=[C.padTop||0,C.padLeft||0,C.padBottom||0,C.padRight||0],G=`Pool_${y}`;if(f.graph.node.push({op_type:C.type,input:[m],output:[G],name:`pool_after_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:V},{name:"strides",type:"INTS",ints:rt},{name:"pads",type:"INTS",ints:it}]}),m=G,n.flattenAfterPooling){let at=`PoolFlat_${y}`;f.graph.node.push({op_type:"Flatten",input:[m],output:[at],name:`flatten_after_l${y}`,attributes:[{name:"axis",type:"INT",i:1}]}),m=at,f.metadata_props=f.metadata_props||[];let et=f.metadata_props.find(J=>J.key==="flatten_layers");if(et)try{let J=JSON.parse(et.value);Array.isArray(J)&&!J.includes(y)&&(J.push(y),et.value=JSON.stringify(J))}catch{et.value=JSON.stringify([y])}else f.metadata_props.push({key:"flatten_layers",value:JSON.stringify([y])})}f.metadata_props=f.metadata_props||[];let X=f.metadata_props.find(at=>at.key==="pool2d_layers");if(X)try{let at=JSON.parse(X.value);Array.isArray(at)&&!at.includes(y)&&(at.push(y),X.value=JSON.stringify(at))}catch{X.value=JSON.stringify([y])}else f.metadata_props.push({key:"pool2d_layers",value:JSON.stringify([y])});let Z=f.metadata_props.find(at=>at.key==="pool2d_specs");if(Z)try{let at=JSON.parse(Z.value);Array.isArray(at)&&(at.push({...C}),Z.value=JSON.stringify(at))}catch{Z.value=JSON.stringify([C])}else f.metadata_props.push({key:"pool2d_specs",value:JSON.stringify([C])})}f.metadata_props=f.metadata_props||[];let B=f.metadata_props.find(V=>V.key==="conv2d_layers");if(B)try{let V=JSON.parse(B.value);Array.isArray(V)&&!V.includes(y)&&(V.push(y),B.value=JSON.stringify(V))}catch{B.value=JSON.stringify([y])}else f.metadata_props.push({key:"conv2d_layers",value:JSON.stringify([y])});let Y=f.metadata_props.find(V=>V.key==="conv2d_specs");if(Y)try{let V=JSON.parse(Y.value);Array.isArray(V)&&(V.push({...w}),Y.value=JSON.stringify(V))}catch{Y.value=JSON.stringify([w])}else f.metadata_props.push({key:"conv2d_specs",value:JSON.stringify([w])});continue}}let x=n.allowMixedActivations&&new Set(N.map(_=>_.squash&&_.squash.name)).size>1;if(b.includes(y)&&!v){if(x)throw new Error(`Recurrent export does not yet support mixed activations in hidden layer ${y}.`);let _=[],I=new Array(N.length).fill(0);for(let T=0;T<N.length;T++){let D=N[T];I[T]=D.bias;for(let E=0;E<A.length;E++){let R=A[E],O=D.connections.in.find(P=>P.from===R);_.push(O?O.weight:0)}}let L=`W${y-1}`,$=`B${y-1}`;f.graph.initializer.push({name:L,data_type:1,dims:[N.length,A.length],float_data:_}),f.graph.initializer.push({name:$,data_type:1,dims:[N.length],float_data:I});let k=[];for(let T=0;T<N.length;T++)for(let D=0;D<N.length;D++)if(T===D){let E=N[T].connections.self[0];k.push(E?E.weight:0)}else k.push(0);let F=`R${y-1}`;f.graph.initializer.push({name:F,data_type:1,dims:[N.length,N.length],float_data:k}),f.graph.node.push({op_type:"Gemm",input:[m,L,$],output:[`Gemm_in_${y}`],name:`gemm_in_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]});let M=y===1?"hidden_prev":`hidden_prev_l${y}`;f.graph.node.push({op_type:"Gemm",input:[M,F],output:[`Gemm_rec_${y}`],name:`gemm_rec_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]}),f.graph.node.push({op_type:"Add",input:[`Gemm_in_${y}`,`Gemm_rec_${y}`],output:[`RecurrentSum_${y}`],name:`add_recurrent_l${y}`}),f.graph.node.push({op_type:Zt(N[0].squash),input:[`RecurrentSum_${y}`],output:[`Layer_${y}`],name:`act_l${y}`}),m=`Layer_${y}`}else if(x){let _=[];N.forEach(($,k)=>{let F=[];for(let R=0;R<A.length;R++){let O=A[R],P=$.connections.in.find(C=>C.from===O);F.push(P?P.weight:0)}let M=`W${y-1}_n${k}`,T=`B${y-1}_n${k}`,D=`Gemm_${y}_n${k}`,E=`Layer_${y}_n${k}`;f.graph.initializer.push({name:M,data_type:1,dims:[1,A.length],float_data:F}),f.graph.initializer.push({name:T,data_type:1,dims:[1],float_data:[$.bias]}),f.graph.node.push({op_type:"Gemm",input:[m,M,T],output:[D],name:`gemm_l${y}_n${k}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]}),f.graph.node.push({op_type:Zt($.squash),input:[D],output:[E],name:`act_l${y}_n${k}`}),_.push(E)});let I=`Layer_${y}`;f.graph.node.push({op_type:"Concat",input:_,output:[I],name:`concat_l${y}`,attributes:[{name:"axis",type:"INT",i:i?1:0}]}),m=I;let L=n.pool2dMappings?.find($=>$.afterLayerIndex===y);if(L){let $=[L.kernelHeight,L.kernelWidth],k=[L.strideHeight,L.strideWidth],F=[L.padTop||0,L.padLeft||0,L.padBottom||0,L.padRight||0],M=`Pool_${y}`;if(f.graph.node.push({op_type:L.type,input:[m],output:[M],name:`pool_after_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:$},{name:"strides",type:"INTS",ints:k},{name:"pads",type:"INTS",ints:F}]}),m=M,n.flattenAfterPooling){let E=`PoolFlat_${y}`;f.graph.node.push({op_type:"Flatten",input:[m],output:[E],name:`flatten_after_l${y}`,attributes:[{name:"axis",type:"INT",i:1}]}),m=E,f.metadata_props=f.metadata_props||[];let R=f.metadata_props.find(O=>O.key==="flatten_layers");if(R)try{let O=JSON.parse(R.value);Array.isArray(O)&&!O.includes(y)&&(O.push(y),R.value=JSON.stringify(O))}catch{R.value=JSON.stringify([y])}else f.metadata_props.push({key:"flatten_layers",value:JSON.stringify([y])})}f.metadata_props=f.metadata_props||[];let T=f.metadata_props.find(E=>E.key==="pool2d_layers");if(T)try{let E=JSON.parse(T.value);Array.isArray(E)&&!E.includes(y)&&(E.push(y),T.value=JSON.stringify(E))}catch{T.value=JSON.stringify([y])}else f.metadata_props.push({key:"pool2d_layers",value:JSON.stringify([y])});let D=f.metadata_props.find(E=>E.key==="pool2d_specs");if(D)try{let E=JSON.parse(D.value);Array.isArray(E)&&(E.push({...L}),D.value=JSON.stringify(E))}catch{D.value=JSON.stringify([L])}else f.metadata_props.push({key:"pool2d_specs",value:JSON.stringify([L])})}}else{let _=[],I=new Array(N.length).fill(0);for(let T=0;T<N.length;T++){let D=N[T];I[T]=D.bias;for(let E=0;E<A.length;E++){let R=A[E],O=D.connections.in.find(P=>P.from===R);_.push(O?O.weight:0)}}let L=`W${y-1}`,$=`B${y-1}`,k=`Gemm_${y}`,F=`Layer_${y}`;f.graph.initializer.push({name:L,data_type:1,dims:[N.length,A.length],float_data:_}),f.graph.initializer.push({name:$,data_type:1,dims:[N.length],float_data:I}),a?(f.graph.node.push({op_type:Zt(N[0].squash),input:[k],output:[F],name:`act_l${y}`}),f.graph.node.push({op_type:"Gemm",input:[m,L,$],output:[k],name:`gemm_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]})):(f.graph.node.push({op_type:"Gemm",input:[m,L,$],output:[k],name:`gemm_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]}),f.graph.node.push({op_type:Zt(N[0].squash),input:[k],output:[F],name:`act_l${y}`})),m=F;let M=n.pool2dMappings?.find(T=>T.afterLayerIndex===y);if(M){let T=[M.kernelHeight,M.kernelWidth],D=[M.strideHeight,M.strideWidth],E=[M.padTop||0,M.padLeft||0,M.padBottom||0,M.padRight||0],R=`Pool_${y}`;if(f.graph.node.push({op_type:M.type,input:[m],output:[R],name:`pool_after_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:T},{name:"strides",type:"INTS",ints:D},{name:"pads",type:"INTS",ints:E}]}),m=R,n.flattenAfterPooling){let C=`PoolFlat_${y}`;f.graph.node.push({op_type:"Flatten",input:[m],output:[C],name:`flatten_after_l${y}`,attributes:[{name:"axis",type:"INT",i:1}]}),m=C,f.metadata_props=f.metadata_props||[];let B=f.metadata_props.find(Y=>Y.key==="flatten_layers");if(B)try{let Y=JSON.parse(B.value);Array.isArray(Y)&&!Y.includes(y)&&(Y.push(y),B.value=JSON.stringify(Y))}catch{B.value=JSON.stringify([y])}else f.metadata_props.push({key:"flatten_layers",value:JSON.stringify([y])})}f.metadata_props=f.metadata_props||[];let O=f.metadata_props.find(C=>C.key==="pool2d_layers");if(O)try{let C=JSON.parse(O.value);Array.isArray(C)&&!C.includes(y)&&(C.push(y),O.value=JSON.stringify(C))}catch{O.value=JSON.stringify([y])}else f.metadata_props.push({key:"pool2d_layers",value:JSON.stringify([y])});let P=f.metadata_props.find(C=>C.key==="pool2d_specs");if(P)try{let C=JSON.parse(P.value);Array.isArray(C)&&(C.push({...M}),P.value=JSON.stringify(C))}catch{P.value=JSON.stringify([M])}else f.metadata_props.push({key:"pool2d_specs",value:JSON.stringify([M])})}}}if(n.allowRecurrent)for(let y=1;y<t.length-1;y++){let A=t[y],N=A.length;if(f.metadata_props||(f.metadata_props=[]),N>=8&&N<10&&f.metadata_props.push({key:"rnn_pattern_fallback",value:JSON.stringify({layer:y,reason:"size_between_gru_lstm_thresholds"})}),N>=10&&N%5===0){let v=N/5,w=t[y-1],x=A.slice(0,v),_=A.slice(v,v*2),I=A.slice(v*2,v*3),L=A.slice(v*3,v*4),$=A.slice(v*4,v*5),k=[x,_,I,L],F=k.length,M=w.length,T=[],D=[],E=[];for(let O=0;O<F;O++){let P=k[O];for(let C=0;C<v;C++){let B=P[C];for(let Y=0;Y<M;Y++){let V=w[Y],rt=B.connections.in.find(it=>it.from===V);T.push(rt?rt.weight:0)}for(let Y=0;Y<v;Y++)if(P===I&&Y===C){let V=B.connections.self[0];D.push(V?V.weight:0)}else D.push(0);E.push(B.bias)}}f.graph.initializer.push({name:`LSTM_W${y-1}`,data_type:1,dims:[F*v,M],float_data:T}),f.graph.initializer.push({name:`LSTM_R${y-1}`,data_type:1,dims:[F*v,v],float_data:D}),f.graph.initializer.push({name:`LSTM_B${y-1}`,data_type:1,dims:[F*v],float_data:E}),f.graph.node.push({op_type:"LSTM",input:[m,`LSTM_W${y-1}`,`LSTM_R${y-1}`,`LSTM_B${y-1}`],output:[`Layer_${y}_lstm_hidden`],name:`lstm_l${y}`,attributes:[{name:"hidden_size",type:"INT",i:v},{name:"layout",type:"INT",i:0}]}),f.metadata_props=f.metadata_props||[];let R=f.metadata_props.findIndex(O=>O.key==="lstm_emitted_layers");if(R>=0)try{let O=JSON.parse(f.metadata_props[R].value);Array.isArray(O)&&!O.includes(y)&&(O.push(y),f.metadata_props[R].value=JSON.stringify(O))}catch{f.metadata_props[R].value=JSON.stringify([y])}else f.metadata_props.push({key:"lstm_emitted_layers",value:JSON.stringify([y])})}if(N>=8&&N%4===0){let v=N/4,w=t[y-1],x=A.slice(0,v),_=A.slice(v,v*2),I=A.slice(v*2,v*3),L=A.slice(v*3,v*4),$=[x,_,I],k=$.length,F=w.length,M=[],T=[],D=[];for(let O=0;O<k;O++){let P=$[O];for(let C=0;C<v;C++){let B=P[C];for(let Y=0;Y<F;Y++){let V=w[Y],rt=B.connections.in.find(it=>it.from===V);M.push(rt?rt.weight:0)}for(let Y=0;Y<v;Y++)if(P===I&&Y===C){let V=B.connections.self[0];T.push(V?V.weight:0)}else T.push(0);D.push(B.bias)}}f.graph.initializer.push({name:`GRU_W${y-1}`,data_type:1,dims:[k*v,F],float_data:M}),f.graph.initializer.push({name:`GRU_R${y-1}`,data_type:1,dims:[k*v,v],float_data:T}),f.graph.initializer.push({name:`GRU_B${y-1}`,data_type:1,dims:[k*v],float_data:D});let E=y===1?"input":`Layer_${y-1}`;f.graph.node.push({op_type:"GRU",input:[E,`GRU_W${y-1}`,`GRU_R${y-1}`,`GRU_B${y-1}`],output:[`Layer_${y}_gru_hidden`],name:`gru_l${y}`,attributes:[{name:"hidden_size",type:"INT",i:v},{name:"layout",type:"INT",i:0}]}),f.metadata_props=f.metadata_props||[];let R=f.metadata_props.findIndex(O=>O.key==="gru_emitted_layers");if(R>=0)try{let O=JSON.parse(f.metadata_props[R].value);Array.isArray(O)&&!O.includes(y)&&(O.push(y),f.metadata_props[R].value=JSON.stringify(O))}catch{f.metadata_props[R].value=JSON.stringify([y])}else f.metadata_props.push({key:"gru_emitted_layers",value:JSON.stringify([y])})}}if(s&&(f.metadata_props=f.metadata_props||[],f.metadata_props.push({key:"layer_sizes",value:JSON.stringify(g)}),b.length&&f.metadata_props.push({key:"recurrent_single_step",value:JSON.stringify(b)}),n.validateConvSharing&&n.conv2dMappings&&n.conv2dMappings.length)){let y=[],A=[];for(let N of n.conv2dMappings){let v=N.layerIndex,w=t[v-1],x=t[v];if(!x||!w)continue;let _=[],I=!0;for(let $=0;$<N.outChannels;$++){let k=$*(N.outHeight*N.outWidth),F=x[k],M=[];for(let T=0;T<N.inChannels;T++)for(let D=0;D<N.kernelHeight;D++)for(let E=0;E<N.kernelWidth;E++){let R=T*(N.inHeight*N.inWidth)+D*N.inWidth+E,O=w[R],P=F.connections.in.find(C=>C.from===O);M.push(P?P.weight:0)}_.push(M)}let L=1e-9;for(let $=0;$<N.outChannels&&I;$++)for(let k=0;k<N.outHeight&&I;k++)for(let F=0;F<N.outWidth&&I;F++){let M=$*(N.outHeight*N.outWidth)+k*N.outWidth+F,T=x[M];if(!T)continue;let D=0;for(let E=0;E<N.inChannels&&I;E++){let R=k*N.strideHeight-(N.padTop||0),O=F*N.strideWidth-(N.padLeft||0);for(let P=0;P<N.kernelHeight&&I;P++)for(let C=0;C<N.kernelWidth&&I;C++){let B=R+P,Y=O+C;if(B<0||B>=N.inHeight||Y<0||Y>=N.inWidth){D++;continue}let V=E*(N.inHeight*N.inWidth)+B*N.inWidth+Y,rt=w[V],it=T.connections.in.find(X=>X.from===rt),G=it?it.weight:0;Math.abs(G-_[$][D])>L&&(I=!1),D++}}if(!I)break}I?y.push(v):(A.push(v),console.warn(`Conv2D weight sharing mismatch detected in layer ${v}`))}y.length&&f.metadata_props.push({key:"conv2d_sharing_verified",value:JSON.stringify(y)}),A.length&&f.metadata_props.push({key:"conv2d_sharing_mismatch",value:JSON.stringify(A)})}return f}function gn(e,t={}){if(zo(e),e.nodes.forEach((i,a)=>i.index=a),!e.connections||e.connections.length===0)throw new Error("ONNX export currently only supports simple MLPs");let n=qo(e),s=[];if(t.allowRecurrent)try{for(let i=1;i<n.length-1;i++){let a=n[i],r=a.length;if(r>=10&&r%5===0){let c=r/5;a.slice(c*2,c*3).every(p=>p.connections.self.length===1)&&s.push({layerIndex:i,unitSize:c})}}}catch{}Vo(n,e,t);let o=Yo(e,n,t);if(t.includeMetadata){let i=[],a=[];for(let r=1;r<n.length-1;r++){let c=n[r-1].length,l=n[r].length,u=Math.sqrt(c);if(Math.abs(u-Math.round(u))>1e-9)continue;let p=Math.round(u);for(let h of[3,2]){if(h>=p)continue;let d=p-h+1;if(d*d===l){if(t.conv2dMappings?.some(m=>m.layerIndex===r))break;a.push(r),i.push({layerIndex:r,inHeight:p,inWidth:p,inChannels:1,kernelHeight:h,kernelWidth:h,strideHeight:1,strideWidth:1,outHeight:d,outWidth:d,outChannels:1,note:"heuristic_inferred_no_export_applied"});break}}}a.length&&(o.metadata_props=o.metadata_props||[],o.metadata_props.push({key:"conv2d_inferred_layers",value:JSON.stringify(a)}),o.metadata_props.push({key:"conv2d_inferred_specs",value:JSON.stringify(i)}))}return s.length&&(o.metadata_props=o.metadata_props||[],o.metadata_props.push({key:"lstm_groups_stub",value:JSON.stringify(s)})),o}var Re=H(()=>{"use strict";ft();Nt()});var bn=H(()=>{"use strict";Re();Re()});function Sn(e){if(!e.nodes.some(d=>d.type==="output"))throw new Error("Cannot create standalone function: network has no output nodes.");let t={},n=[],s={},o=0,i=[],a=[],r=[],c={logistic:"function logistic(x){ return 1 / (1 + Math.exp(-x)); }",tanh:"function tanh(x){ return Math.tanh(x); }",relu:"function relu(x){ return x > 0 ? x : 0; }",identity:"function identity(x){ return x; }",step:"function step(x){ return x > 0 ? 1 : 0; }",softsign:"function softsign(x){ return x / (1 + Math.abs(x)); }",sinusoid:"function sinusoid(x){ return Math.sin(x); }",gaussian:"function gaussian(x){ return Math.exp(-Math.pow(x, 2)); }",bentIdentity:"function bentIdentity(x){ return (Math.sqrt(Math.pow(x, 2) + 1) - 1) / 2 + x; }",bipolar:"function bipolar(x){ return x > 0 ? 1 : -1; }",bipolarSigmoid:"function bipolarSigmoid(x){ return 2 / (1 + Math.exp(-x)) - 1; }",hardTanh:"function hardTanh(x){ return Math.max(-1, Math.min(1, x)); }",absolute:"function absolute(x){ return Math.abs(x); }",inverse:"function inverse(x){ return 1 - x; }",selu:"function selu(x){ var a=1.6732632423543772,s=1.0507009873554805; var fx=x>0?x:a*Math.exp(x)-a; return fx*s; }",softplus:"function softplus(x){ if(x>30)return x; if(x<-30)return Math.exp(x); return Math.max(0,x)+Math.log(1+Math.exp(-Math.abs(x))); }",swish:"function swish(x){ var s=1/(1+Math.exp(-x)); return x*s; }",gelu:"function gelu(x){ var cdf=0.5*(1.0+Math.tanh(Math.sqrt(2.0/Math.PI)*(x+0.044715*Math.pow(x,3)))); return x*cdf; }",mish:"function mish(x){ var sp_x; if(x>30){sp_x=x;}else if(x<-30){sp_x=Math.exp(x);}else{sp_x=Math.log(1+Math.exp(x));} var tanh_sp_x=Math.tanh(sp_x); return x*tanh_sp_x; }"};e.nodes.forEach((d,f)=>{d.index=f,i.push(d.activation),a.push(d.state)}),r.push("for(var i = 0; i < input.length; i++) A[i] = input[i];");for(let d=e.input;d<e.nodes.length;d++){let f=e.nodes[d],m=f.squash,b=m.name||`anonymous_squash_${d}`;if(!(b in t)){let v;c[b]?(v=c[b],v.startsWith(`function ${b}`)||(v=`function ${b}${v.substring(v.indexOf("("))}`),v=An(v)):(v=m.toString(),v=An(v),v.startsWith("function")?v=`function ${b}${v.substring(v.indexOf("("))}`:v.includes("=>")?v=`function ${b}${v.substring(v.indexOf("("))}`:v=`function ${b}(x){ return x; }`),t[b]=v,n.push(v),s[b]=o++}let g=s[b],y=[];for(let v of f.connections.in){if(typeof v.from.index>"u")continue;let w=`A[${v.from.index}] * ${v.weight}`;v.gater&&typeof v.gater.index<"u"&&(w+=` * A[${v.gater.index}]`),y.push(w)}if(f.connections.self.length>0){let v=f.connections.self[0],w=`S[${d}] * ${v.weight}`;v.gater&&typeof v.gater.index<"u"&&(w+=` * A[${v.gater.index}]`),y.push(w)}let A=y.length>0?y.join(" + "):"0";r.push(`S[${d}] = ${A} + ${f.bias};`);let N=typeof f.mask=="number"&&f.mask!==1?f.mask:1;r.push(`A[${d}] = F[${g}](S[${d}])${N!==1?` * ${N}`:""};`)}let l=[];for(let d=e.nodes.length-e.output;d<e.nodes.length;d++)typeof e.nodes[d]?.index<"u"&&l.push(e.nodes[d].index);r.push(`return [${l.map(d=>`A[${d}]`).join(",")}];`);let u=Object.entries(s).sort(([,d],[,f])=>d-f).map(([d])=>d).join(","),p=e._activationPrecision==="f32"?"Float32Array":"Float64Array",h="";return h+=`(function(){
|
|
25
|
+
};`}}});var ae,mn=H(()=>{"use strict";ae=class{static async getNodeTestWorker(){return(await Promise.resolve().then(()=>(Ie(),Me))).TestWorker}static async getBrowserTestWorker(){return(await Promise.resolve().then(()=>(Te(),Ce))).TestWorker}}});var mt,Jt=H(()=>{"use strict";mn();pt();mt=class e{static workers=ae;static activations=[t=>1/(1+Math.exp(-t)),t=>Math.tanh(t),t=>t,t=>t>0?1:0,t=>t>0?t:0,t=>t/(1+Math.abs(t)),t=>Math.sin(t),t=>Math.exp(-Math.pow(t,2)),t=>(Math.sqrt(Math.pow(t,2)+1)-1)/2+t,t=>t>0?1:-1,t=>2/(1+Math.exp(-t))-1,t=>Math.max(-1,Math.min(1,t)),t=>Math.abs(t),t=>1-t,t=>{let n=1.6732632423543772;return(t>0?t:n*Math.exp(t)-n)*1.0507009873554805},t=>Math.log(1+Math.exp(t))];static serializeDataSet(t){let n=[t[0].input.length,t[0].output.length];for(let s=0;s<t.length;s++){for(let o=0;o<n[0];o++)n.push(t[s].input[o]);for(let o=0;o<n[1];o++)n.push(t[s].output[o])}return n}static activateSerializedNetwork(t,n,s,o,i){for(let r=0;r<o[0];r++)n[r]=t[r];for(let r=2;r<o.length;r++){let c=o[r++],l=o[r++],u=o[r++],p=o[r++],h=o[r++];for(s[c]=(h===-1?1:n[h])*p*s[c]+l;o[r]!==-2;)s[c]+=n[o[r++]]*o[r++]*(o[r++]===-1?1:n[o[r-1]]);n[c]=i[u](s[c])}let a=[];for(let r=n.length-o[1];r<n.length;r++)a.push(n[r]);return a}static deserializeDataSet(t){let n=[],s=t[0]+t[1];for(let o=0;o<(t.length-2)/s;o++){let i=[];for(let r=2+o*s;r<2+o*s+t[0];r++)i.push(t[r]);let a=[];for(let r=2+o*s+t[0];r<2+o*s+s;r++)a.push(t[r]);n.push({input:i,output:a})}return n}static logistic(t){return 1/(1+Math.exp(-t))}static tanh(t){return Math.tanh(t)}static identity(t){return t}static step(t){return t>0?1:0}static relu(t){return t>0?t:0}static softsign(t){return t/(1+Math.abs(t))}static sinusoid(t){return Math.sin(t)}static gaussian(t){return Math.exp(-Math.pow(t,2))}static bentIdentity(t){return(Math.sqrt(Math.pow(t,2)+1)-1)/2+t}static bipolar(t){return t>0?1:-1}static bipolarSigmoid(t){return 2/(1+Math.exp(-t))-1}static hardTanh(t){return Math.max(-1,Math.min(1,t))}static absolute(t){return Math.abs(t)}static inverse(t){return 1-t}static selu(t){let n=1.6732632423543772;return(t>0?t:n*Math.exp(t)-n)*1.0507009873554805}static softplus(t){return Math.log(1+Math.exp(t))}static testSerializedSet(t,n,s,o,i,a){let r=0;for(let c=0;c<t.length;c++){let l=e.activateSerializedNetwork(t[c].input,s,o,i,a);r+=n(t[c].output,l)}return r/t.length}static async getBrowserTestWorker(){let{TestWorker:t}=await Promise.resolve().then(()=>(Te(),Ce));return t}static async getNodeTestWorker(){let{TestWorker:t}=await Promise.resolve().then(()=>(Ie(),Me));return t}}});var Oe,yt,Kt=H(()=>{"use strict";At();Oe=class{buckets=new Map;created=0;reused=0;maxPerBucket=Number.POSITIVE_INFINITY;acquire(t){let n=this.buckets.get(t);if(n&&n.length>0){this.reused++;let s=n.pop();return s.fill(0),s}return this.created++,j.float32Mode?new Float32Array(t):new Array(t).fill(0)}release(t){let n=t.length>>>0;this.buckets.has(n)||this.buckets.set(n,[]);let s=this.buckets.get(n);s.length<this.maxPerBucket&&s.push(t)}clear(){this.buckets.clear(),this.created=0,this.reused=0}stats(){return{created:this.created,reused:this.reused,bucketCount:this.buckets.size}}setMaxPerBucket(t){typeof t=="number"&&t>=0&&(this.maxPerBucket=t)}prewarm(t,n){let s=Math.max(0,Math.floor(n));this.buckets.has(t)||this.buckets.set(t,[]);let o=this.buckets.get(t);for(let i=0;i<s&&o.length<this.maxPerBucket;i++){let a=j.float32Mode?new Float32Array(t):new Array(t).fill(0);o.push(a),this.created++}}bucketSize(t){return this.buckets.get(t)?.length??0}},yt=new Oe});var yn=No((lr,Uo)=>{Uo.exports={name:"@reicek/neataptic-ts",version:"0.1.13",description:"Architecture-free neural network library with genetic algorithm implementations",main:"./dist/neataptic.js",module:"./dist/neataptic.js",types:"./dist/neataptic.d.ts",type:"module",scripts:{test:"jest --config=jest.config.mjs --no-cache --coverage --collect-coverage --runInBand --testPathIgnorePatterns=.e2e.test.ts --verbose",pretest:"npm run build","test:bench":"jest --no-cache --runInBand --verbose --testPathPattern=benchmark","bench:asciiMaze":"node -r ts-node/register test/benchmarks/asciiMaze.micro.bench.ts","test:silent":"jest --no-cache --coverage --collect-coverage --runInBand --testPathIgnorePatterns=.e2e.test.ts --silent",deploy:"npm run build && npm run test:dist && npm publish",build:"npm run build:webpack && npm run build:ts","build:ts":"tsc","build:webpack":"webpack --config webpack.config.js","build:ascii-maze":"npx esbuild test/examples/asciiMaze/browser-entry.ts --bundle --outfile=docs/assets/ascii-maze.bundle.js --platform=browser --format=iife --minify --sourcemap --external:fs --external:child_process --external:path","start:ts":"ts-node src/neataptic.ts","test:e2e":"cross-env FORCE_COLOR=true jest e2e.test.ts --no-cache --runInBand","test:e2e:logs":"npx jest e2e.test.ts --verbose --runInBand --no-cache","test:dist":"npm run build:ts && jest --no-cache --coverage --collect-coverage --runInBand --testPathIgnorePatterns=.e2e.test.ts","docs:build-scripts":"tsc -p tsconfig.docs.json && node scripts/write-dist-docs-pkg.mjs","docs:folders":"npm run docs:build-scripts && node ./dist-docs/scripts/generate-docs.js","docs:html":"npm run docs:build-scripts && node ./dist-docs/scripts/render-docs-html.js","docs:examples":"node scripts/copy-examples.mjs",prettier:"npm run prettier:tests && npm run prettier:src","prettier:tests":"npx prettier --write test/**/*.ts","prettier:src":"npx prettier --write src/**/*.ts",docs:"npm run build:ascii-maze && npm run docs:examples && npm run docs:build-scripts && node ./dist-docs/scripts/generate-docs.js && node ./dist-docs/scripts/render-docs-html.js","onnx:export":"node scripts/export-onnx.mjs"},exports:{".":{types:"./dist/neataptic.d.ts",import:"./dist/neataptic.js"}},devDependencies:{"@types/chai":"^5.2.2","@types/fs-extra":"^11.0.4","@types/jest":"^30.0.0","@types/node":"^24.3.0","@types/seedrandom":"^3.0.8","@types/webpack":"^5.28.5","@types/webpack-dev-server":"^4.7.2",chai:"^6.0.1","copy-webpack-plugin":"^13.0.1","cross-env":"^10.0.0",esbuild:"^0.25.9","fast-glob":"^3.3.3","fs-extra":"^11.3.1",husky:"^9.1.7",jest:"^30.0.5","jest-environment-jsdom":"^30.0.5","jsdoc-to-markdown":"^9.1.2",marked:"^16.2.0",mkdocs:"^0.0.1",puppeteer:"^24.17.0","ts-jest":"^29.4.1","ts-loader":"^9.5.2","ts-morph":"^26.0.0","ts-node":"^10.9.2",typescript:"^5.9.2","undici-types":"^7.15.0",webpack:"^5.101.3","webpack-cli":"^6.0.1"},repository:{type:"git",url:"https://github.com/reicek/NeatapticTS.git"},keywords:["neural network","machine learning","genetic algorithm","mutation","neat"],author:{name:"Cesar Anton",email:"reicek@gmail.com"},license:"MIT",publishConfig:{access:"public",registry:"https://registry.npmjs.org/"},bugs:{url:"https://github.com/reicek/NeatapticTS/issues",email:"reicek@gmail.com"},homepage:"https://reicek.github.io/NeatapticTS/",engines:{node:">=22.0.0"},prettier:{singleQuote:!0},dependencies:{seedrandom:"^3.0.5",undici:"^7.15.0"}}});function zo(e){let t=new Set;e.nodes.forEach(n=>n.connections?.out.forEach(s=>t.add(s))),e.connections=Array.from(t)}function Zt(e){let t=(e?.name||"").toUpperCase();return t.includes("TANH")?"Tanh":t.includes("LOGISTIC")||t.includes("SIGMOID")?"Sigmoid":t.includes("RELU")?"Relu":(e&&console.warn(`Unsupported activation function ${e.name} for ONNX export, defaulting to Identity.`),"Identity")}function qo(e){let t=e.nodes.filter(r=>r.type==="input"),n=e.nodes.filter(r=>r.type==="output"),s=e.nodes.filter(r=>r.type==="hidden");if(s.length===0)return[t,n];let o=[...s],i=t,a=[];for(;o.length;){let r=o.filter(c=>c.connections.in.every(l=>i.includes(l.from)));if(!r.length)throw new Error("Invalid network structure for ONNX export: cannot resolve layered ordering.");a.push(i),i=r,o=o.filter(c=>!r.includes(c))}return a.push(i),a.push(n),a}function Vo(e,t,n){for(let s=1;s<e.length;s++){let o=e[s-1],i=e[s],a=new Set(i.map(r=>r.squash&&r.squash.name));if(a.size>1&&!n.allowMixedActivations)throw new Error(`ONNX export error: Mixed activation functions detected in layer ${s}. (enable allowMixedActivations to decompose layer)`);a.size>1&&n.allowMixedActivations&&console.warn(`Warning: Mixed activations in layer ${s}; exporting per-neuron Gemm + Activation (+Concat) baseline.`);for(let r of i)for(let c of o)if(!r.connections.in.some(u=>u.from===c)&&!n.allowPartialConnectivity)throw new Error(`ONNX export error: Missing connection from node ${c.index} to node ${r.index} in layer ${s}. (enable allowPartialConnectivity)`)}}function Yo(e,t,n={}){let{includeMetadata:s=!1,opset:o=18,batchDimension:i=!1,legacyNodeOrdering:a=!1,producerName:r="neataptic-ts",producerVersion:c,docString:l}=n,u=t[0],p=t[t.length-1],h=i?[{dim_param:"N"},{dim_value:u.length}]:[{dim_value:u.length}],d=i?[{dim_param:"N"},{dim_value:p.length}]:[{dim_value:p.length}],f={graph:{inputs:[{name:"input",type:{tensor_type:{elem_type:1,shape:{dim:h}}}}],outputs:[{name:"output",type:{tensor_type:{elem_type:1,shape:{dim:d}}}}],initializer:[],node:[]}};if(s){let y=(()=>{try{return yn().version}catch{return"0.0.0"}})();f.ir_version=9,f.opset_import=[{version:o,domain:""}],f.producer_name=r,f.producer_version=c||y,f.doc_string=l||"Exported from NeatapticTS ONNX exporter (phases 1-2 baseline)"}let m="input",b=[];if(n.allowRecurrent&&n.recurrentSingleStep)for(let y=1;y<t.length-1;y++){let A=t[y];if(A.some(N=>N.connections.self.length>0)){b.push(y);let N=y===1?"hidden_prev":`hidden_prev_l${y}`;f.graph.inputs.push({name:N,type:{tensor_type:{elem_type:1,shape:{dim:i?[{dim_param:"N"},{dim_value:A.length}]:[{dim_value:A.length}]}}}})}}let g=[];for(let y=1;y<t.length;y++){let A=t[y-1],N=t[y],v=y===t.length-1;v||g.push(N.length);let w=n.conv2dMappings?.find(_=>_.layerIndex===y);if(w){let _=w.inHeight*w.inWidth*w.inChannels,I=A.length,L=w.outChannels*w.outHeight*w.outWidth,$=N.length,k=[w.padTop||0,w.padLeft||0,w.padBottom||0,w.padRight||0];if(!(_===I&&L===$))console.warn(`Conv2D mapping for layer ${y} skipped: dimension mismatch (expected prev=${_} got ${I}; expected this=${L} got ${$}).`);else{let M=[],T=[];for(let V=0;V<w.outChannels;V++){let rt=V*w.outHeight*w.outWidth,it=N[rt];T.push(it.bias);for(let G=0;G<w.inChannels;G++)for(let X=0;X<w.kernelHeight;X++)for(let Z=0;Z<w.kernelWidth;Z++){let at=G*(w.inHeight*w.inWidth)+X*w.inWidth+Z,et=A[at],J=it.connections.in.find(ot=>ot.from===et);M.push(J?J.weight:0)}}let D=`ConvW${y-1}`,E=`ConvB${y-1}`;f.graph.initializer.push({name:D,data_type:1,dims:[w.outChannels,w.inChannels,w.kernelHeight,w.kernelWidth],float_data:M}),f.graph.initializer.push({name:E,data_type:1,dims:[w.outChannels],float_data:T});let R=`Conv_${y}`;f.graph.node.push({op_type:"Conv",input:[m,D,E],output:[R],name:`conv_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:[w.kernelHeight,w.kernelWidth]},{name:"strides",type:"INTS",ints:[w.strideHeight,w.strideWidth]},{name:"pads",type:"INTS",ints:k}]});let O=w.activation||Zt(N[0].squash),P=`Layer_${y}`;f.graph.node.push({op_type:O,input:[R],output:[P],name:`act_conv_l${y}`}),m=P;let C=n.pool2dMappings?.find(V=>V.afterLayerIndex===y);if(C){let V=[C.kernelHeight,C.kernelWidth],rt=[C.strideHeight,C.strideWidth],it=[C.padTop||0,C.padLeft||0,C.padBottom||0,C.padRight||0],G=`Pool_${y}`;if(f.graph.node.push({op_type:C.type,input:[m],output:[G],name:`pool_after_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:V},{name:"strides",type:"INTS",ints:rt},{name:"pads",type:"INTS",ints:it}]}),m=G,n.flattenAfterPooling){let at=`PoolFlat_${y}`;f.graph.node.push({op_type:"Flatten",input:[m],output:[at],name:`flatten_after_l${y}`,attributes:[{name:"axis",type:"INT",i:1}]}),m=at,f.metadata_props=f.metadata_props||[];let et=f.metadata_props.find(J=>J.key==="flatten_layers");if(et)try{let J=JSON.parse(et.value);Array.isArray(J)&&!J.includes(y)&&(J.push(y),et.value=JSON.stringify(J))}catch{et.value=JSON.stringify([y])}else f.metadata_props.push({key:"flatten_layers",value:JSON.stringify([y])})}f.metadata_props=f.metadata_props||[];let X=f.metadata_props.find(at=>at.key==="pool2d_layers");if(X)try{let at=JSON.parse(X.value);Array.isArray(at)&&!at.includes(y)&&(at.push(y),X.value=JSON.stringify(at))}catch{X.value=JSON.stringify([y])}else f.metadata_props.push({key:"pool2d_layers",value:JSON.stringify([y])});let Z=f.metadata_props.find(at=>at.key==="pool2d_specs");if(Z)try{let at=JSON.parse(Z.value);Array.isArray(at)&&(at.push({...C}),Z.value=JSON.stringify(at))}catch{Z.value=JSON.stringify([C])}else f.metadata_props.push({key:"pool2d_specs",value:JSON.stringify([C])})}f.metadata_props=f.metadata_props||[];let B=f.metadata_props.find(V=>V.key==="conv2d_layers");if(B)try{let V=JSON.parse(B.value);Array.isArray(V)&&!V.includes(y)&&(V.push(y),B.value=JSON.stringify(V))}catch{B.value=JSON.stringify([y])}else f.metadata_props.push({key:"conv2d_layers",value:JSON.stringify([y])});let Y=f.metadata_props.find(V=>V.key==="conv2d_specs");if(Y)try{let V=JSON.parse(Y.value);Array.isArray(V)&&(V.push({...w}),Y.value=JSON.stringify(V))}catch{Y.value=JSON.stringify([w])}else f.metadata_props.push({key:"conv2d_specs",value:JSON.stringify([w])});continue}}let x=n.allowMixedActivations&&new Set(N.map(_=>_.squash&&_.squash.name)).size>1;if(b.includes(y)&&!v){if(x)throw new Error(`Recurrent export does not yet support mixed activations in hidden layer ${y}.`);let _=[],I=new Array(N.length).fill(0);for(let T=0;T<N.length;T++){let D=N[T];I[T]=D.bias;for(let E=0;E<A.length;E++){let R=A[E],O=D.connections.in.find(P=>P.from===R);_.push(O?O.weight:0)}}let L=`W${y-1}`,$=`B${y-1}`;f.graph.initializer.push({name:L,data_type:1,dims:[N.length,A.length],float_data:_}),f.graph.initializer.push({name:$,data_type:1,dims:[N.length],float_data:I});let k=[];for(let T=0;T<N.length;T++)for(let D=0;D<N.length;D++)if(T===D){let E=N[T].connections.self[0];k.push(E?E.weight:0)}else k.push(0);let F=`R${y-1}`;f.graph.initializer.push({name:F,data_type:1,dims:[N.length,N.length],float_data:k}),f.graph.node.push({op_type:"Gemm",input:[m,L,$],output:[`Gemm_in_${y}`],name:`gemm_in_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]});let M=y===1?"hidden_prev":`hidden_prev_l${y}`;f.graph.node.push({op_type:"Gemm",input:[M,F],output:[`Gemm_rec_${y}`],name:`gemm_rec_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]}),f.graph.node.push({op_type:"Add",input:[`Gemm_in_${y}`,`Gemm_rec_${y}`],output:[`RecurrentSum_${y}`],name:`add_recurrent_l${y}`}),f.graph.node.push({op_type:Zt(N[0].squash),input:[`RecurrentSum_${y}`],output:[`Layer_${y}`],name:`act_l${y}`}),m=`Layer_${y}`}else if(x){let _=[];N.forEach(($,k)=>{let F=[];for(let R=0;R<A.length;R++){let O=A[R],P=$.connections.in.find(C=>C.from===O);F.push(P?P.weight:0)}let M=`W${y-1}_n${k}`,T=`B${y-1}_n${k}`,D=`Gemm_${y}_n${k}`,E=`Layer_${y}_n${k}`;f.graph.initializer.push({name:M,data_type:1,dims:[1,A.length],float_data:F}),f.graph.initializer.push({name:T,data_type:1,dims:[1],float_data:[$.bias]}),f.graph.node.push({op_type:"Gemm",input:[m,M,T],output:[D],name:`gemm_l${y}_n${k}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]}),f.graph.node.push({op_type:Zt($.squash),input:[D],output:[E],name:`act_l${y}_n${k}`}),_.push(E)});let I=`Layer_${y}`;f.graph.node.push({op_type:"Concat",input:_,output:[I],name:`concat_l${y}`,attributes:[{name:"axis",type:"INT",i:i?1:0}]}),m=I;let L=n.pool2dMappings?.find($=>$.afterLayerIndex===y);if(L){let $=[L.kernelHeight,L.kernelWidth],k=[L.strideHeight,L.strideWidth],F=[L.padTop||0,L.padLeft||0,L.padBottom||0,L.padRight||0],M=`Pool_${y}`;if(f.graph.node.push({op_type:L.type,input:[m],output:[M],name:`pool_after_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:$},{name:"strides",type:"INTS",ints:k},{name:"pads",type:"INTS",ints:F}]}),m=M,n.flattenAfterPooling){let E=`PoolFlat_${y}`;f.graph.node.push({op_type:"Flatten",input:[m],output:[E],name:`flatten_after_l${y}`,attributes:[{name:"axis",type:"INT",i:1}]}),m=E,f.metadata_props=f.metadata_props||[];let R=f.metadata_props.find(O=>O.key==="flatten_layers");if(R)try{let O=JSON.parse(R.value);Array.isArray(O)&&!O.includes(y)&&(O.push(y),R.value=JSON.stringify(O))}catch{R.value=JSON.stringify([y])}else f.metadata_props.push({key:"flatten_layers",value:JSON.stringify([y])})}f.metadata_props=f.metadata_props||[];let T=f.metadata_props.find(E=>E.key==="pool2d_layers");if(T)try{let E=JSON.parse(T.value);Array.isArray(E)&&!E.includes(y)&&(E.push(y),T.value=JSON.stringify(E))}catch{T.value=JSON.stringify([y])}else f.metadata_props.push({key:"pool2d_layers",value:JSON.stringify([y])});let D=f.metadata_props.find(E=>E.key==="pool2d_specs");if(D)try{let E=JSON.parse(D.value);Array.isArray(E)&&(E.push({...L}),D.value=JSON.stringify(E))}catch{D.value=JSON.stringify([L])}else f.metadata_props.push({key:"pool2d_specs",value:JSON.stringify([L])})}}else{let _=[],I=new Array(N.length).fill(0);for(let T=0;T<N.length;T++){let D=N[T];I[T]=D.bias;for(let E=0;E<A.length;E++){let R=A[E],O=D.connections.in.find(P=>P.from===R);_.push(O?O.weight:0)}}let L=`W${y-1}`,$=`B${y-1}`,k=`Gemm_${y}`,F=`Layer_${y}`;f.graph.initializer.push({name:L,data_type:1,dims:[N.length,A.length],float_data:_}),f.graph.initializer.push({name:$,data_type:1,dims:[N.length],float_data:I}),a?(f.graph.node.push({op_type:Zt(N[0].squash),input:[k],output:[F],name:`act_l${y}`}),f.graph.node.push({op_type:"Gemm",input:[m,L,$],output:[k],name:`gemm_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]})):(f.graph.node.push({op_type:"Gemm",input:[m,L,$],output:[k],name:`gemm_l${y}`,attributes:[{name:"alpha",type:"FLOAT",f:1},{name:"beta",type:"FLOAT",f:1},{name:"transB",type:"INT",i:1}]}),f.graph.node.push({op_type:Zt(N[0].squash),input:[k],output:[F],name:`act_l${y}`})),m=F;let M=n.pool2dMappings?.find(T=>T.afterLayerIndex===y);if(M){let T=[M.kernelHeight,M.kernelWidth],D=[M.strideHeight,M.strideWidth],E=[M.padTop||0,M.padLeft||0,M.padBottom||0,M.padRight||0],R=`Pool_${y}`;if(f.graph.node.push({op_type:M.type,input:[m],output:[R],name:`pool_after_l${y}`,attributes:[{name:"kernel_shape",type:"INTS",ints:T},{name:"strides",type:"INTS",ints:D},{name:"pads",type:"INTS",ints:E}]}),m=R,n.flattenAfterPooling){let C=`PoolFlat_${y}`;f.graph.node.push({op_type:"Flatten",input:[m],output:[C],name:`flatten_after_l${y}`,attributes:[{name:"axis",type:"INT",i:1}]}),m=C,f.metadata_props=f.metadata_props||[];let B=f.metadata_props.find(Y=>Y.key==="flatten_layers");if(B)try{let Y=JSON.parse(B.value);Array.isArray(Y)&&!Y.includes(y)&&(Y.push(y),B.value=JSON.stringify(Y))}catch{B.value=JSON.stringify([y])}else f.metadata_props.push({key:"flatten_layers",value:JSON.stringify([y])})}f.metadata_props=f.metadata_props||[];let O=f.metadata_props.find(C=>C.key==="pool2d_layers");if(O)try{let C=JSON.parse(O.value);Array.isArray(C)&&!C.includes(y)&&(C.push(y),O.value=JSON.stringify(C))}catch{O.value=JSON.stringify([y])}else f.metadata_props.push({key:"pool2d_layers",value:JSON.stringify([y])});let P=f.metadata_props.find(C=>C.key==="pool2d_specs");if(P)try{let C=JSON.parse(P.value);Array.isArray(C)&&(C.push({...M}),P.value=JSON.stringify(C))}catch{P.value=JSON.stringify([M])}else f.metadata_props.push({key:"pool2d_specs",value:JSON.stringify([M])})}}}if(n.allowRecurrent)for(let y=1;y<t.length-1;y++){let A=t[y],N=A.length;if(f.metadata_props||(f.metadata_props=[]),N>=8&&N<10&&f.metadata_props.push({key:"rnn_pattern_fallback",value:JSON.stringify({layer:y,reason:"size_between_gru_lstm_thresholds"})}),N>=10&&N%5===0){let v=N/5,w=t[y-1],x=A.slice(0,v),_=A.slice(v,v*2),I=A.slice(v*2,v*3),L=A.slice(v*3,v*4),$=A.slice(v*4,v*5),k=[x,_,I,L],F=k.length,M=w.length,T=[],D=[],E=[];for(let O=0;O<F;O++){let P=k[O];for(let C=0;C<v;C++){let B=P[C];for(let Y=0;Y<M;Y++){let V=w[Y],rt=B.connections.in.find(it=>it.from===V);T.push(rt?rt.weight:0)}for(let Y=0;Y<v;Y++)if(P===I&&Y===C){let V=B.connections.self[0];D.push(V?V.weight:0)}else D.push(0);E.push(B.bias)}}f.graph.initializer.push({name:`LSTM_W${y-1}`,data_type:1,dims:[F*v,M],float_data:T}),f.graph.initializer.push({name:`LSTM_R${y-1}`,data_type:1,dims:[F*v,v],float_data:D}),f.graph.initializer.push({name:`LSTM_B${y-1}`,data_type:1,dims:[F*v],float_data:E}),f.graph.node.push({op_type:"LSTM",input:[m,`LSTM_W${y-1}`,`LSTM_R${y-1}`,`LSTM_B${y-1}`],output:[`Layer_${y}_lstm_hidden`],name:`lstm_l${y}`,attributes:[{name:"hidden_size",type:"INT",i:v},{name:"layout",type:"INT",i:0}]}),f.metadata_props=f.metadata_props||[];let R=f.metadata_props.findIndex(O=>O.key==="lstm_emitted_layers");if(R>=0)try{let O=JSON.parse(f.metadata_props[R].value);Array.isArray(O)&&!O.includes(y)&&(O.push(y),f.metadata_props[R].value=JSON.stringify(O))}catch{f.metadata_props[R].value=JSON.stringify([y])}else f.metadata_props.push({key:"lstm_emitted_layers",value:JSON.stringify([y])})}if(N>=8&&N%4===0){let v=N/4,w=t[y-1],x=A.slice(0,v),_=A.slice(v,v*2),I=A.slice(v*2,v*3),L=A.slice(v*3,v*4),$=[x,_,I],k=$.length,F=w.length,M=[],T=[],D=[];for(let O=0;O<k;O++){let P=$[O];for(let C=0;C<v;C++){let B=P[C];for(let Y=0;Y<F;Y++){let V=w[Y],rt=B.connections.in.find(it=>it.from===V);M.push(rt?rt.weight:0)}for(let Y=0;Y<v;Y++)if(P===I&&Y===C){let V=B.connections.self[0];T.push(V?V.weight:0)}else T.push(0);D.push(B.bias)}}f.graph.initializer.push({name:`GRU_W${y-1}`,data_type:1,dims:[k*v,F],float_data:M}),f.graph.initializer.push({name:`GRU_R${y-1}`,data_type:1,dims:[k*v,v],float_data:T}),f.graph.initializer.push({name:`GRU_B${y-1}`,data_type:1,dims:[k*v],float_data:D});let E=y===1?"input":`Layer_${y-1}`;f.graph.node.push({op_type:"GRU",input:[E,`GRU_W${y-1}`,`GRU_R${y-1}`,`GRU_B${y-1}`],output:[`Layer_${y}_gru_hidden`],name:`gru_l${y}`,attributes:[{name:"hidden_size",type:"INT",i:v},{name:"layout",type:"INT",i:0}]}),f.metadata_props=f.metadata_props||[];let R=f.metadata_props.findIndex(O=>O.key==="gru_emitted_layers");if(R>=0)try{let O=JSON.parse(f.metadata_props[R].value);Array.isArray(O)&&!O.includes(y)&&(O.push(y),f.metadata_props[R].value=JSON.stringify(O))}catch{f.metadata_props[R].value=JSON.stringify([y])}else f.metadata_props.push({key:"gru_emitted_layers",value:JSON.stringify([y])})}}if(s&&(f.metadata_props=f.metadata_props||[],f.metadata_props.push({key:"layer_sizes",value:JSON.stringify(g)}),b.length&&f.metadata_props.push({key:"recurrent_single_step",value:JSON.stringify(b)}),n.validateConvSharing&&n.conv2dMappings&&n.conv2dMappings.length)){let y=[],A=[];for(let N of n.conv2dMappings){let v=N.layerIndex,w=t[v-1],x=t[v];if(!x||!w)continue;let _=[],I=!0;for(let $=0;$<N.outChannels;$++){let k=$*(N.outHeight*N.outWidth),F=x[k],M=[];for(let T=0;T<N.inChannels;T++)for(let D=0;D<N.kernelHeight;D++)for(let E=0;E<N.kernelWidth;E++){let R=T*(N.inHeight*N.inWidth)+D*N.inWidth+E,O=w[R],P=F.connections.in.find(C=>C.from===O);M.push(P?P.weight:0)}_.push(M)}let L=1e-9;for(let $=0;$<N.outChannels&&I;$++)for(let k=0;k<N.outHeight&&I;k++)for(let F=0;F<N.outWidth&&I;F++){let M=$*(N.outHeight*N.outWidth)+k*N.outWidth+F,T=x[M];if(!T)continue;let D=0;for(let E=0;E<N.inChannels&&I;E++){let R=k*N.strideHeight-(N.padTop||0),O=F*N.strideWidth-(N.padLeft||0);for(let P=0;P<N.kernelHeight&&I;P++)for(let C=0;C<N.kernelWidth&&I;C++){let B=R+P,Y=O+C;if(B<0||B>=N.inHeight||Y<0||Y>=N.inWidth){D++;continue}let V=E*(N.inHeight*N.inWidth)+B*N.inWidth+Y,rt=w[V],it=T.connections.in.find(X=>X.from===rt),G=it?it.weight:0;Math.abs(G-_[$][D])>L&&(I=!1),D++}}if(!I)break}I?y.push(v):(A.push(v),console.warn(`Conv2D weight sharing mismatch detected in layer ${v}`))}y.length&&f.metadata_props.push({key:"conv2d_sharing_verified",value:JSON.stringify(y)}),A.length&&f.metadata_props.push({key:"conv2d_sharing_mismatch",value:JSON.stringify(A)})}return f}function gn(e,t={}){if(zo(e),e.nodes.forEach((i,a)=>i.index=a),!e.connections||e.connections.length===0)throw new Error("ONNX export currently only supports simple MLPs");let n=qo(e),s=[];if(t.allowRecurrent)try{for(let i=1;i<n.length-1;i++){let a=n[i],r=a.length;if(r>=10&&r%5===0){let c=r/5;a.slice(c*2,c*3).every(p=>p.connections.self.length===1)&&s.push({layerIndex:i,unitSize:c})}}}catch{}Vo(n,e,t);let o=Yo(e,n,t);if(t.includeMetadata){let i=[],a=[];for(let r=1;r<n.length-1;r++){let c=n[r-1].length,l=n[r].length,u=Math.sqrt(c);if(Math.abs(u-Math.round(u))>1e-9)continue;let p=Math.round(u);for(let h of[3,2]){if(h>=p)continue;let d=p-h+1;if(d*d===l){if(t.conv2dMappings?.some(m=>m.layerIndex===r))break;a.push(r),i.push({layerIndex:r,inHeight:p,inWidth:p,inChannels:1,kernelHeight:h,kernelWidth:h,strideHeight:1,strideWidth:1,outHeight:d,outWidth:d,outChannels:1,note:"heuristic_inferred_no_export_applied"});break}}}a.length&&(o.metadata_props=o.metadata_props||[],o.metadata_props.push({key:"conv2d_inferred_layers",value:JSON.stringify(a)}),o.metadata_props.push({key:"conv2d_inferred_specs",value:JSON.stringify(i)}))}return s.length&&(o.metadata_props=o.metadata_props||[],o.metadata_props.push({key:"lstm_groups_stub",value:JSON.stringify(s)})),o}var Re=H(()=>{"use strict";ft();Nt()});var bn=H(()=>{"use strict";Re();Re()});function Sn(e){if(!e.nodes.some(d=>d.type==="output"))throw new Error("Cannot create standalone function: network has no output nodes.");let t={},n=[],s={},o=0,i=[],a=[],r=[],c={logistic:"function logistic(x){ return 1 / (1 + Math.exp(-x)); }",tanh:"function tanh(x){ return Math.tanh(x); }",relu:"function relu(x){ return x > 0 ? x : 0; }",identity:"function identity(x){ return x; }",step:"function step(x){ return x > 0 ? 1 : 0; }",softsign:"function softsign(x){ return x / (1 + Math.abs(x)); }",sinusoid:"function sinusoid(x){ return Math.sin(x); }",gaussian:"function gaussian(x){ return Math.exp(-Math.pow(x, 2)); }",bentIdentity:"function bentIdentity(x){ return (Math.sqrt(Math.pow(x, 2) + 1) - 1) / 2 + x; }",bipolar:"function bipolar(x){ return x > 0 ? 1 : -1; }",bipolarSigmoid:"function bipolarSigmoid(x){ return 2 / (1 + Math.exp(-x)) - 1; }",hardTanh:"function hardTanh(x){ return Math.max(-1, Math.min(1, x)); }",absolute:"function absolute(x){ return Math.abs(x); }",inverse:"function inverse(x){ return 1 - x; }",selu:"function selu(x){ var a=1.6732632423543772,s=1.0507009873554805; var fx=x>0?x:a*Math.exp(x)-a; return fx*s; }",softplus:"function softplus(x){ if(x>30)return x; if(x<-30)return Math.exp(x); return Math.max(0,x)+Math.log(1+Math.exp(-Math.abs(x))); }",swish:"function swish(x){ var s=1/(1+Math.exp(-x)); return x*s; }",gelu:"function gelu(x){ var cdf=0.5*(1.0+Math.tanh(Math.sqrt(2.0/Math.PI)*(x+0.044715*Math.pow(x,3)))); return x*cdf; }",mish:"function mish(x){ var sp_x; if(x>30){sp_x=x;}else if(x<-30){sp_x=Math.exp(x);}else{sp_x=Math.log(1+Math.exp(x));} var tanh_sp_x=Math.tanh(sp_x); return x*tanh_sp_x; }"};e.nodes.forEach((d,f)=>{d.index=f,i.push(d.activation),a.push(d.state)}),r.push("for(var i = 0; i < input.length; i++) A[i] = input[i];");for(let d=e.input;d<e.nodes.length;d++){let f=e.nodes[d],m=f.squash,b=m.name||`anonymous_squash_${d}`;if(!(b in t)){let v;c[b]?(v=c[b],v.startsWith(`function ${b}`)||(v=`function ${b}${v.substring(v.indexOf("("))}`),v=An(v)):(v=m.toString(),v=An(v),v.startsWith("function")?v=`function ${b}${v.substring(v.indexOf("("))}`:v.includes("=>")?v=`function ${b}${v.substring(v.indexOf("("))}`:v=`function ${b}(x){ return x; }`),t[b]=v,n.push(v),s[b]=o++}let g=s[b],y=[];for(let v of f.connections.in){if(typeof v.from.index>"u")continue;let w=`A[${v.from.index}] * ${v.weight}`;v.gater&&typeof v.gater.index<"u"&&(w+=` * A[${v.gater.index}]`),y.push(w)}if(f.connections.self.length>0){let v=f.connections.self[0],w=`S[${d}] * ${v.weight}`;v.gater&&typeof v.gater.index<"u"&&(w+=` * A[${v.gater.index}]`),y.push(w)}let A=y.length>0?y.join(" + "):"0";r.push(`S[${d}] = ${A} + ${f.bias};`);let N=typeof f.mask=="number"&&f.mask!==1?f.mask:1;r.push(`A[${d}] = F[${g}](S[${d}])${N!==1?` * ${N}`:""};`)}let l=[];for(let d=e.nodes.length-e.output;d<e.nodes.length;d++)typeof e.nodes[d]?.index<"u"&&l.push(e.nodes[d].index);r.push(`return [${l.map(d=>`A[${d}]`).join(",")}];`);let u=Object.entries(s).sort(([,d],[,f])=>d-f).map(([d])=>d).join(","),p=e._activationPrecision==="f32"?"Float32Array":"Float64Array",h="";return h+=`(function(){
|
|
26
26
|
`,h+=`${n.join(`
|
|
27
27
|
`)}
|
|
28
28
|
`,h+=`var F = [${u}];
|