Created
December 1, 2022 00:53
-
-
Save fabiospampinato/7c3eeab0fb2611804204c66dc6c51e54 to your computer and use it in GitHub Desktop.
A 99% precise neural network that learned the XOR function. There's about a 1kb fixed overhead, the model is ~just those two hex strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xor(t){const _=xor;return _._||(_._=!0,_.p=(e,t)=>{const r=[];for(let n=0,c=e.length;n<c;n++){r[n]=[];for(let c=0,a=t[0].length;c<a;c++){let a=0;for(let r=0,l=e[0].length;r<l;r++)a+=e[n][r]*t[r][c];r[n][c]=a}}return r},_.m=(e,t)=>{const r=new Array(e.length);for(let n=0,c=e.length;n<c;n++){r[n]=new Array(e[n].length);for(let c=0,a=e[n].length;c<a;c++)r[n][c]=t(e[n][c],n,c)}return r},_.d=(e,t)=>{const r="float64"===t?Float64Array:Float32Array;return e.split("|").map((e=>{const t=e.length/2,n=r.BYTES_PER_ELEMENT,c=new ArrayBuffer(t+(t%n?n-t%n:0)),a=new Uint8Array(c),l=new r(c);for(let t=0,r=e.length;t<r;t+=2)a[t/2]=parseInt(e.slice(t,t+2),16);return Array.from(l).slice(0,t)}))},_.a0=(e,t)=>{const r=1/(1+Math.exp(-e));return t?r*(1-r):r},_.a1=(e,t)=>{const r=1/(1+Math.exp(-e));return t?r*(1-r):r},_.w0=_.d("cf70bbc08a93cfc043c6bb40c6ee8240|de3eb8c06b4a4e4080843bc0480001c1"),_.w1=_.d("c98b9fc1|eb82af40|dd0cbac0|e8d02d41")),_.m(_.p(_.m(_.p([t],_.w0),_.a0),_.w1),_.a1)[0][0]} | |
console.log(xor([0,0])); | |
console.log(xor([1,0])); | |
console.log(xor([0,1])); | |
console.log(xor([1,1])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment