diff --git a/assets/images/button_philpax.png b/assets/images/button_philpax.png new file mode 100644 index 0000000..ccef948 Binary files /dev/null and b/assets/images/button_philpax.png differ diff --git a/experiments/free-will/app.js b/experiments/free-will/app.js index 63e0192..be2bbb8 100644 --- a/experiments/free-will/app.js +++ b/experiments/free-will/app.js @@ -1 +1 @@ -(()=>{function I(){}function _t(t){return t()}function st(){return Object.create(null)}function L(t){t.forEach(_t)}function lt(t){return typeof t=="function"}function Ft(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Et(t){return Object.keys(t).length===0}function Z(t){return t??""}var ht=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;var ct=class t{_listeners="WeakMap"in ht?new WeakMap:void 0;_observer=void 0;options;constructor(e){this.options=e}observe(e,n){return this._listeners.set(e,n),this._getObserver().observe(e,this.options),()=>{this._listeners.delete(e),this._observer.unobserve(e)}}_getObserver(){return this._observer??(this._observer=new ResizeObserver(e=>{for(let n of e)t.entries.set(n.target,n),this._listeners.get(n.target)?.(n)}))}};ct.entries="WeakMap"in ht?new WeakMap:void 0;var Mt=!1;function St(){Mt=!0}function Nt(){Mt=!1}function u(t,e){t.appendChild(e)}function j(t,e,n){t.insertBefore(e,n||null)}function A(t){t.parentNode&&t.parentNode.removeChild(t)}function Y(t,e){for(let n=0;nt.removeEventListener(e,n,r)}function g(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ot(t){return Array.from(t.childNodes)}function U(t,e){e=""+e,t.data!==e&&(t.data=e)}function At(t){let e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}var K;function G(t){K=t}var X=[];var at=[],et=[],Tt=[],be=Promise.resolve(),gt=!1;function Dt(){gt||(gt=!0,be.then(ut))}function ot(t){et.push(t)}var mt=new Set,tt=0;function ut(){if(tt!==0)return;let t=K;do{try{for(;ttt.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),et=e}var $e=new Set;function ft(t,e){t&&t.i&&($e.delete(t),t.i(e))}function C(t){return t?.length!==void 0?t:Array.from(t)}var ve=["allowfullscreen","allowpaymentrequest","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],ke=new Set([...ve]);function Ee(t,e,n){let{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),ot(()=>{let i=t.$$.on_mount.map(_t).filter(lt);t.$$.on_destroy?t.$$.on_destroy.push(...i):L(i),t.$$.on_mount=[]}),o.forEach(ot)}function Me(t,e){let n=t.$$;n.fragment!==null&&(Lt(n.after_update),L(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Se(t,e){t.$$.dirty[0]===-1&&(X.push(t),Dt(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{let F=D.length?D[0]:x;return a.ctx&&o(a.ctx[_],a.ctx[_]=F)&&(!a.skip_bound&&a.bound[_]&&a.bound[_](F),w&&Se(t,_)),x}):[],a.update(),w=!0,L(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){St();let _=Ot(e.target);a.fragment&&a.fragment.l(_),_.forEach(A)}else a.fragment&&a.fragment.c();e.intro&&ft(t.$$.fragment),Ee(t,e.target,e.anchor),Nt(),ut()}G(c)}var Ne;typeof HTMLElement=="function"&&(Ne=class extends HTMLElement{$$ctor;$$s;$$c;$$cn=!1;$$d={};$$r=!1;$$p_d={};$$l={};$$l_u=new Map;constructor(t,e,n){super(),this.$$ctor=t,this.$$s=e,n&&this.attachShadow({mode:"open"})}addEventListener(t,e,n){if(this.$$l[t]=this.$$l[t]||[],this.$$l[t].push(e),this.$$c){let r=this.$$c.$on(t,e);this.$$l_u.set(e,r)}super.addEventListener(t,e,n)}removeEventListener(t,e,n){if(super.removeEventListener(t,e,n),this.$$c){let r=this.$$l_u.get(e);r&&(r(),this.$$l_u.delete(e))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let t=function(o){return()=>{let i;return{c:function(){i=h("slot"),o!=="default"&&g(i,"name",o)},m:function(c,a){j(c,i,a)},d:function(c){c&&A(i)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;let e={},n=At(this);for(let o of this.$$s)o in n&&(e[o]=[t(o)]);for(let o of this.attributes){let i=this.$$g_p(o.name);i in this.$$d||(this.$$d[i]=xt(i,o.value,this.$$p_d,"toProp"))}for(let o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:e,$$scope:{ctx:[]}}});let r=()=>{this.$$r=!0;for(let o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){let i=xt(o,this.$$d[o],this.$$p_d,"toAttribute");i==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,i)}this.$$r=!1};this.$$c.$$.after_update.push(r),r();for(let o in this.$$l)for(let i of this.$$l[o]){let s=this.$$c.$on(o,i);this.$$l_u.set(i,s)}this.$$l={}}}attributeChangedCallback(t,e,n){this.$$r||(t=this.$$g_p(t),this.$$d[t]=xt(t,n,this.$$p_d,"toProp"),this.$$c?.$set({[t]:this.$$d[t]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(t){return Object.keys(this.$$p_d).find(e=>this.$$p_d[e].attribute===t||!this.$$p_d[e].attribute&&e.toLowerCase()===t)||t}});function xt(t,e,n,r){let o=n[t]?.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="toAttribute")switch(o){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}var it=class{$$=void 0;$$set=void 0;$destroy(){Me(this,1),this.$destroy=I}$on(e,n){if(!lt(n))return I;let r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{let o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(e){this.$$set&&!Et(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}};var Rt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Rt);var Oe=(t,e)=>new Array(t).fill(e),Ae=new FinalizationRegistry(t=>{wasm_bindings.dealloc_matrix(t)}),J=(t,e,n)=>{let r={m:t,n:e,data:wasm_bindings.alloc_matrix(t,e,n)};return Ae.register(r,r.data),r},B=t=>new Float32Array(wasm_bindings.memory.buffer,wasm_bindings.matrix_buffer(t.data),t.n*t.m),wt=t=>{let e=J(t.length,1,NaN);return B(e).set(t),e},vt=t=>e=>{let[n,r]=V(e),o=J(n,r,NaN),i=B(o),s=B(e);for(let d=0;d[t,e],bt=(t,e)=>{let[n,r]=V(t),[o,i]=V(e);if(r!==o)throw"actually, mathematics forbids this.";let s=J(n,i,NaN);return wasm_bindings.gemm(t.data,e.data,s.data),s},It=(t,e)=>{let n=bt(t,e);return n.backward=r=>{e.backward(bt(Bt(t),r)),t.backward(bt(r,Bt(e)))},n},pt=t=>(e,n)=>{let[r,o]=V(e),[i,s]=V(n);if(i!==r||s!==o)throw"no.";let d=J(r,o,0),c=B(d),a=B(e),w=B(n);for(let _=0;_(t.backward=n=>{let r=B(n),o=B(t);for(let i=0;i(t.backward=()=>{},t),Bt=t=>{let[e,n]=V(t),r=J(n,e,NaN);return wasm_bindings.transpose(t.data,r.data),r},Te=(t,e,n)=>{let[r,o]=V(e),[i,s]=V(n);if(i!==r||s!==o)throw"no.";let d=J(r,o,NaN);return t(e.data,n.data,d.data),d},De=(t,e)=>Te(wasm_bindings.hadamard,t,e),zt=(t,e)=>n=>{let r=vt(t)(n);return r.backward=o=>n.backward(De(o,vt(e)(n))),r},Le=(t,e)=>{let n=pt((r,o)=>r+o)(t,e);return n.backward=r=>{t.backward(r),e.backward(r)},n},Pt=t=>Math.min(Math.max(Math.log(t),-100),100),je=zt(Math.tanh,t=>1-Math.tanh(t)**2),$t=t=>1/(Math.exp(-t)+1),Re=zt($t,t=>$t(t)*(1-$t(t))),Ie=(t,e)=>{let n=pt((r,o)=>-o*Pt(r)+-(1-o)*Pt(1-r))(t,e);return n.backward=r=>{t.backward(pt((o,i)=>o*i)(r,pt((o,i)=>-i/o+-(i-1)/(1-o))(t,e)))},n},S=32,Be=.003,Wt=t=>vt(()=>Math.random()*2*t-t),Gt=(t={})=>{let e=t.learningRate??Be,n=Math.sqrt(6/(S+S)),r=Math.sqrt(6/(S+1)),o=Oe(3,null).map(s=>({weight:yt(Wt(n)(J(S,S,NaN)),e),bias:yt(J(S,1,0),e)})),i=yt(Wt(r)(J(1,S,NaN)),e);return{layers:o,outputProjection:i,learningRate:e}},Jt=(t,e)=>{let n=Ce(wt(t));for(let r of e.layers)n=Le(It(r.weight,n),r.bias),n=je(n);return n=It(e.outputProjection,n),n=Re(n),n};var Ht=(t,e)=>{let n=Jt(e,t);return B(n)[0]},qt=(t,e,n)=>{let r=Jt(e,t),o=B(r)[0];return isNaN(o)?!1:(Ie(r,wt([n])).backward(wt([1])),!0)},Vt=(t,e,n={})=>{let r=n.replaySteps??4,o=n.replayWindow??64,i=n.random??Math.random,s=!1;for(t.training_step??=0;t.training_step{if(!Number.isInteger(t)||t<1)throw new RangeError("order must be a positive integer");return{order:t,priorOnes:e.priorOnes??1,priorTotal:e.priorTotal??2,counts:new Map}},Ut=(t,e)=>e.slice(-t.order).join(""),Xt=(t,e)=>{if(e.length{if(e.length0&&le(t);return{c(){e=h("div"),n=h("div"),r=h("button"),r.textContent="\u2190 Left",o=E(),i=h("button"),i.textContent="\u2192 Right",s=E(),d=h("br"),c=E(),a=h("table");for(let f=0;fAaronson oracle concept. Optimal free will is ~50% on all predictors.',g(r,"class","svelte-e31mm4"),g(i,"class","svelte-e31mm4"),g(n,"class","buttons svelte-e31mm4"),g(x,"class","label svelte-e31mm4"),g(P,"class","label svelte-e31mm4"),g(a,"class","sequence svelte-e31mm4"),g(e,"id","app"),g(e,"tabindex","0"),g(e,"class","svelte-e31mm4")},m(f,z){j(f,e,z),u(e,n),u(n,r),u(n,o),u(n,i),u(e,s),u(e,d),u(e,c),u(e,a);for(let l=0;l0?N?N.p(f,z):(N=le(f),N.c(),N.m(e,q)):N&&(N.d(1),N=null)},i:I,o:I,d(f){f&&A(e),Y(m,f),Y(k,f),Y(M,f),N&&N.d(),t[11](null),$=!1,L(b)}}}var dt=100,We=20;function qe(t,e,n){let r=[1,2,3,4],o=["d","ArrowLeft","1"],i=["f","ArrowRight","0"],s=[],d=r.map(()=>[]),c=[],a,w=32,_=r.map(Zt),x=[],D=v=>{if(x.length===0)return .5;let $=[];for(let p of x)$.push(Math.min(1-1e-7,Math.max(1e-7,Ht(p,v.slice(-S)))));let b=$.map(p=>Math.log(p/(1-p))).reduce((p,m)=>p+m,0)/$.length;return 1/(1+Math.exp(-b))},F=v=>{for(_.forEach((p,m)=>{d[m].push(+(Xt(p,s)>=.5)),Qt(p,s,v)}),n(1,d),c.push(+(D(s)>=.5)),n(2,c),s.push(v),n(0,s);!(s.lengthVt(m,s));if(p.length===x.length)break;console.warn(`Replaced ${x.length-p.length} NN model(s) after a non-finite update`),x=p}if(window.models=x,!a)return;let $=a.querySelector("table td.val"),b=a.querySelector("table td.label");$&&n(4,w=Math.floor((a.getBoundingClientRect().width-b.getBoundingClientRect().width)/$.getBoundingClientRect().width))},O=v=>{let $=s.slice(-dt),b=v.slice(-dt);return $.filter((p,m)=>p===b[m]).length/$.length},P=v=>{o.includes(v.key)?F(1):i.includes(v.key)&&F(0)},R=()=>F(1),W=()=>F(0);function q(v){at[v?"unshift":"push"](()=>{a=v,n(3,a)})}return[s,d,c,a,w,r,F,O,P,R,W,q]}var kt=class extends it{constructor(e){super(),jt(this,e,qe,Pe,Ft,{})}},ae=kt;var nt;function ze(t,e){let n=new Uint8Array(nt.exports.memory.buffer,t,e);console.log("WASM",new TextDecoder().decode(n))}var ue={env:{memory:new WebAssembly.Memory({initial:5,maximum:500}),console_log_ex:ze}},Ge=async()=>{if(typeof window<"u")return WebAssembly.instantiateStreaming(fetch("gemm.wasm"),ue);let t=new Function("specifier","return import(specifier)"),{readFile:e}=await t("node:fs/promises");return WebAssembly.instantiate(await e("static/gemm.wasm"),ue)},fe=Ge().then(t=>(nt=t.instance,nt.exports.init_debug(),globalThis.wasm_instance=nt,globalThis.wasm_bindings=nt.exports,nt.exports));fe.then(()=>{new ae({target:document.querySelector("#app")})});})(); +(()=>{function B(){}function xt(t){return t()}function ut(){return Object.create(null)}function L(t){t.forEach(xt)}function ft(t){return typeof t=="function"}function Ot(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function At(t){return Object.keys(t).length===0}function U(t){return t??""}var bt=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;var pt=class t{_listeners="WeakMap"in bt?new WeakMap:void 0;_observer=void 0;options;constructor(e){this.options=e}observe(e,n){return this._listeners.set(e,n),this._getObserver().observe(e,this.options),()=>{this._listeners.delete(e),this._observer.unobserve(e)}}_getObserver(){return this._observer??(this._observer=new ResizeObserver(e=>{for(let n of e)t.entries.set(n.target,n),this._listeners.get(n.target)?.(n)}))}};pt.entries="WeakMap"in bt?new WeakMap:void 0;var Ct=!1;function Tt(){Ct=!0}function Dt(){Ct=!1}function c(t,e){t.appendChild(e)}function R(t,e,n){t.insertBefore(e,n||null)}function T(t){t.parentNode&&t.parentNode.removeChild(t)}function nt(t,e){for(let n=0;nt.removeEventListener(e,n,r)}function x(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function jt(t){return Array.from(t.childNodes)}function X(t,e){e=""+e,t.data!==e&&(t.data=e)}function Lt(t){let e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}var rt;function J(t){rt=t}var Y=[];var dt=[],it=[],It=[],ke=Promise.resolve(),$t=!1;function Bt(){$t||($t=!0,ke.then(_t))}function ct(t){it.push(t)}var yt=new Set,ot=0;function _t(){if(ot!==0)return;let t=rt;do{try{for(;ott.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),it=e}var Ee=new Set;function ht(t,e){t&&t.i&&(Ee.delete(t),t.i(e))}function D(t){return t?.length!==void 0?t:Array.from(t)}var Se=["allowfullscreen","allowpaymentrequest","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],Ne=new Set([...Se]);function Ae(t,e,n){let{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),ct(()=>{let i=t.$$.on_mount.map(xt).filter(ft);t.$$.on_destroy?t.$$.on_destroy.push(...i):L(i),t.$$.on_mount=[]}),o.forEach(ct)}function Ce(t,e){let n=t.$$;n.fragment!==null&&(Pt(n.after_update),L(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Te(t,e){t.$$.dirty[0]===-1&&(Y.push(t),Bt(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{let C=w.length?w[0]:v;return u.ctx&&o(u.ctx[d],u.ctx[d]=C)&&(!u.skip_bound&&u.bound[d]&&u.bound[d](C),y&&Te(t,d)),v}):[],u.update(),y=!0,L(u.before_update),u.fragment=r?r(u.ctx):!1,e.target){if(e.hydrate){Tt();let d=jt(e.target);u.fragment&&u.fragment.l(d),d.forEach(T)}else u.fragment&&u.fragment.c();e.intro&&ht(t.$$.fragment),Ae(t,e.target,e.anchor),Dt(),_t()}J(a)}var De;typeof HTMLElement=="function"&&(De=class extends HTMLElement{$$ctor;$$s;$$c;$$cn=!1;$$d={};$$r=!1;$$p_d={};$$l={};$$l_u=new Map;constructor(t,e,n){super(),this.$$ctor=t,this.$$s=e,n&&this.attachShadow({mode:"open"})}addEventListener(t,e,n){if(this.$$l[t]=this.$$l[t]||[],this.$$l[t].push(e),this.$$c){let r=this.$$c.$on(t,e);this.$$l_u.set(e,r)}super.addEventListener(t,e,n)}removeEventListener(t,e,n){if(super.removeEventListener(t,e,n),this.$$c){let r=this.$$l_u.get(e);r&&(r(),this.$$l_u.delete(e))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let t=function(o){return()=>{let i;return{c:function(){i=h("slot"),o!=="default"&&x(i,"name",o)},m:function(a,u){R(a,i,u)},d:function(a){a&&T(i)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;let e={},n=Lt(this);for(let o of this.$$s)o in n&&(e[o]=[t(o)]);for(let o of this.attributes){let i=this.$$g_p(o.name);i in this.$$d||(this.$$d[i]=wt(i,o.value,this.$$p_d,"toProp"))}for(let o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:e,$$scope:{ctx:[]}}});let r=()=>{this.$$r=!0;for(let o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){let i=wt(o,this.$$d[o],this.$$p_d,"toAttribute");i==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,i)}this.$$r=!1};this.$$c.$$.after_update.push(r),r();for(let o in this.$$l)for(let i of this.$$l[o]){let s=this.$$c.$on(o,i);this.$$l_u.set(i,s)}this.$$l={}}}attributeChangedCallback(t,e,n){this.$$r||(t=this.$$g_p(t),this.$$d[t]=wt(t,n,this.$$p_d,"toProp"),this.$$c?.$set({[t]:this.$$d[t]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(t){return Object.keys(this.$$p_d).find(e=>this.$$p_d[e].attribute===t||!this.$$p_d[e].attribute&&e.toLowerCase()===t)||t}});function wt(t,e,n,r){let o=n[t]?.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="toAttribute")switch(o){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}var at=class{$$=void 0;$$set=void 0;$destroy(){Ce(this,1),this.$destroy=B}$on(e,n){if(!ft(n))return B;let r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{let o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(e){this.$$set&&!At(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}};var qt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(qt);var je=(t,e)=>new Array(t).fill(e),Le=new FinalizationRegistry(t=>{wasm_bindings.dealloc_matrix(t)}),V=(t,e,n)=>{let r={m:t,n:e,data:wasm_bindings.alloc_matrix(t,e,n)};return Le.register(r,r.data),r},P=t=>new Float32Array(wasm_bindings.memory.buffer,wasm_bindings.matrix_buffer(t.data),t.n*t.m),Et=t=>{let e=V(t.length,1,NaN);return P(e).set(t),e},Mt=t=>e=>{let[n,r]=H(e),o=V(n,r,NaN),i=P(o),s=P(e);for(let p=0;p[t,e],vt=(t,e)=>{let[n,r]=H(t),[o,i]=H(e);if(r!==o)throw"actually, mathematics forbids this.";let s=V(n,i,NaN);return wasm_bindings.gemm(t.data,e.data,s.data),s},zt=(t,e)=>{let n=vt(t,e);return n.backward=r=>{e.backward(vt(Gt(t),r)),t.backward(vt(r,Gt(e)))},n},mt=t=>(e,n)=>{let[r,o]=H(e),[i,s]=H(n);if(i!==r||s!==o)throw"no.";let p=V(r,o,0),a=P(p),u=P(e),y=P(n);for(let d=0;d(t.backward=n=>{let r=P(n),o=P(t);for(let i=0;i(t.backward=()=>{},t),Gt=t=>{let[e,n]=H(t),r=V(n,e,NaN);return wasm_bindings.transpose(t.data,r.data),r},Ie=(t,e,n)=>{let[r,o]=H(e),[i,s]=H(n);if(i!==r||s!==o)throw"no.";let p=V(r,o,NaN);return t(e.data,n.data,p.data),p},Be=(t,e)=>Ie(wasm_bindings.hadamard,t,e),Ht=(t,e)=>n=>{let r=Mt(t)(n);return r.backward=o=>n.backward(Be(o,Mt(e)(n))),r},Pe=(t,e)=>{let n=mt((r,o)=>r+o)(t,e);return n.backward=r=>{t.backward(r),e.backward(r)},n},Jt=t=>Math.min(Math.max(Math.log(t),-100),100),We=Ht(Math.tanh,t=>1-Math.tanh(t)**2),Ft=t=>1/(Math.exp(-t)+1),qe=Ht(Ft,t=>Ft(t)*(1-Ft(t))),ze=(t,e)=>{let n=mt((r,o)=>-o*Jt(r)+-(1-o)*Jt(1-r))(t,e);return n.backward=r=>{t.backward(mt((o,i)=>o*i)(r,mt((o,i)=>-i/o+-(i-1)/(1-o))(t,e)))},n},O=32,Ge=.003,Vt=t=>Mt(()=>Math.random()*2*t-t),Ut=(t={})=>{let e=t.learningRate??Ge,n=Math.sqrt(6/(O+O)),r=Math.sqrt(6/(O+1)),o=je(3,null).map(s=>({weight:kt(Vt(n)(V(O,O,NaN)),e),bias:kt(V(O,1,0),e)})),i=kt(Vt(r)(V(1,O,NaN)),e);return{layers:o,outputProjection:i,learningRate:e}},Xt=(t,e)=>{let n=Re(Et(t));for(let r of e.layers)n=Pe(zt(r.weight,n),r.bias),n=We(n);return n=zt(e.outputProjection,n),n=qe(n),n};var Yt=(t,e)=>{let n=Xt(e,t);return P(n)[0]},Zt=(t,e,n)=>{let r=Xt(e,t),o=P(r)[0];return isNaN(o)?!1:(ze(r,Et([n])).backward(Et([1])),!0)},Kt=(t,e,n={})=>{let r=n.replaySteps??4,o=n.replayWindow??64,i=n.random??Math.random,s=!1;for(t.training_step??=0;t.training_step{if(!Number.isInteger(t)||t<1)throw new RangeError("order must be a positive integer");return{order:t,priorOnes:e.priorOnes??1,priorTotal:e.priorTotal??2,counts:new Map}},te=(t,e)=>e.slice(-t.order).join(""),ee=(t,e)=>{if(e.length{if(e.length0&&pe(t);return{c(){e=h("div"),n=h("div"),r=h("button"),r.textContent="\u2190 Left",o=E(),i=h("button"),i.textContent="\u2192 Right",s=E(),p=h("br"),a=E(),u=h("table");for(let f=0;f0?A?A.p(f,G):(A=pe(f),A.c(),A.m(e,z)):A&&(A.d(1),A=null)},i:B,o:B,d(f){f&&T(e),nt(M,f),nt(S,f),nt(N,f),A&&A.d(),t[12](null),K=!1,L(Nt)}}}var gt=100,Ve=20;function Ze(t,e,n){let r=[1,2,3,4],o=["d","ArrowLeft","1"],i=["f","ArrowRight","0"],s=o.map(($,_)=>`${$}/${i[_]}`).join(", "),p=[],a=r.map(()=>[]),u=[],y,d=32,v=r.map(Qt),w=[],C=$=>{if(w.length===0)return .5;let _=[];for(let b of w)_.push(Math.min(1-1e-7,Math.max(1e-7,Yt(b,$.slice(-O)))));let m=_.map(b=>Math.log(b/(1-b))).reduce((b,g)=>b+g,0)/_.length;return 1/(1+Math.exp(-m))},k=$=>{for(v.forEach((b,g)=>{a[g].push(+(ee(b,p)>=.5)),ne(b,p,$)}),n(1,a),u.push(+(C(p)>=.5)),n(2,u),p.push($),n(0,p);!(p.lengthKt(g,p));if(b.length===w.length)break;console.warn(`Replaced ${w.length-b.length} NN model(s) after a non-finite update`),w=b}if(window.models=w,!y)return;let _=y.querySelector("table td.val"),m=y.querySelector("table td.label");_&&n(4,d=Math.floor((y.getBoundingClientRect().width-m.getBoundingClientRect().width)/_.getBoundingClientRect().width))},W=$=>{let _=p.slice(-gt),m=$.slice(-gt);return _.filter((b,g)=>b===m[g]).length/_.length},I=$=>{o.includes($.key)?k(1):i.includes($.key)&&k(0)},q=()=>k(1),z=()=>k(0);function j($){dt[$?"unshift":"push"](()=>{y=$,n(3,y)})}return[p,a,u,y,d,r,s,k,W,I,q,z,j]}var St=class extends at{constructor(e){super(),Wt(this,e,Ze,Je,Ot,{})}},_e=St;var st;function He(t,e){let n=new Uint8Array(st.exports.memory.buffer,t,e);console.log("WASM",new TextDecoder().decode(n))}var he={env:{memory:new WebAssembly.Memory({initial:5,maximum:500}),console_log_ex:He}},Ue=async()=>{if(typeof window<"u")return WebAssembly.instantiateStreaming(fetch("gemm.wasm"),he);let t=new Function("specifier","return import(specifier)"),{readFile:e}=await t("node:fs/promises");return WebAssembly.instantiate(await e("static/gemm.wasm"),he)},me=Ue().then(t=>(st=t.instance,st.exports.init_debug(),globalThis.wasm_instance=st,globalThis.wasm_bindings=st.exports,st.exports));me.then(()=>{new _e({target:document.querySelector("#app")})});})();