Skip to content

Instantly share code, notes, and snippets.

@adamobeng

adamobeng/nn.py Secret

Created March 7, 2020 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamobeng/72751b9571f2141ea194c5ba4c422aba to your computer and use it in GitHub Desktop.
Save adamobeng/72751b9571f2141ea194c5ba4c422aba to your computer and use it in GitHub Desktop.
neural network in a single Tweet
from numpy import *
r=random
c=hstack
p=dot
N=r.randn
s=lambda x:1/(1+exp(-x))
a=lambda x:s(x)*(1-s(x))
h,j=X.shape
w=N(5,j+1)
e=N(1,6)
for i in r.randint(0,h,1000*h):o=c((1,X[i]));m=p(w,o);n=c((1,s(m)));d=p(e,n);b=0.02*(Y[i]-s(d));g=b;w+=outer(e[:,1:]*a(d)*a(m),o)*b;e+=n*g*a(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment