-
-
Save hunghg255/0c36feb3c6aecda41e89397edbb30131 to your computer and use it in GitHub Desktop.
A little NN trained to learn XOR
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(d){const a={0:1,1:1,7:.05,2:2,3:-2.8,4:-.09,5:2,6:-4.8,8:.04,26:5.7,14:.9,9:10,10:4.5,11:3.3,12:6.8,13:-5.6,15:.01,27:-7.9,21:.9,16:3.8,17:6.4,18:-1.1,19:5,20:2.5,22:0,28:4.7,29:.08,23:2.2,24:-2.3,25:.5,30:.08};a[0]=d[0],a[1]=d[1],a[2]=a[3],a[3]=a[4],a[3]+=a[0]*a[5],a[3]+=a[1]*a[6],a[7]=1/(1+Math.exp(-a[3])),a[8]=a[7]*(1-a[7]),a[9]=a[10],a[10]=a[11],a[10]+=a[0]*a[12],a[10]+=a[1]*a[13],a[14]=1/(1+Math.exp(-a[10])),a[15]=a[14]*(1-a[14]),a[16]=a[17],a[17]=a[18],a[17]+=a[0]*a[19],a[17]+=a[1]*a[20],a[21]=1/(1+Math.exp(-a[17])),a[22]=a[21]*(1-a[21]),a[23]=a[24],a[24]=a[25],a[24]+=a[7]*a[26],a[24]+=a[14]*a[27],a[24]+=a[21]*a[28],a[29]=1/(1+Math.exp(-a[24])),a[30]=a[29]*(1-a[29]);var b=[];return b[0]=a[29],b} | |
console.log ( XOR ([ 0, 0 ]) ); | |
console.log ( XOR ([ 0, 1 ]) ); | |
console.log ( XOR ([ 1, 0 ]) ); | |
console.log ( XOR ([ 1, 1 ]) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment