Comment on: Github is adopting a code of conduct
1 22 Jul 2015 11:18 u/cronenburger in v/programmingComment on: A Neural Network in 11 Lines of Python
In practice it does a matrix transpose operation. The * expands the list into function parameters for the zip function. A single row matrix like [[1, 2, 3]], *[[1, 2, 3]] turns into [1,2,3] and zip([1,2,3]) will match each element with nothing, to create 3 single element tuples.
A multi row matrix with the asterisk like *[[1,2,3],[4,5,6]] turns into zip([1,2,3],[4,5,6]) which of course zips into [(1,4), (2, 5), (3, 6)]
Comment on: A Neural Network in 11 Lines of Python
Quite a bit faster. A quick test showed numpy was twice as fast in this specific case. This code is also a lot less readable than the numpy one (perhaps better variable names would help.) I was happy that I could do it in the same number of lines because its almost all matrix operations.
Comment on: A Neural Network in 11 Lines of Python
This is a much better explanation.
Comment on: A Neural Network in 11 Lines of Python
Here it is in pure python
import math, random
X = [ [0,0,1],[0,1,1],[1,0,1],[1,1,1] ]
y = zip(*[[0,1,1,0]]) # transpose
syn0 = [[2*random.random()-1 for x in range(4)] for _ in range(3)] # 3x4
syn1 = [[2*random.random()-1 for x in range(1)] for _ in range(4)] # 4x1
for j in xrange(60000):
l1 = [[1/(1+math.exp(-sum(a*b for a,b in zip(r, c)))) for c in zip(*syn0)] for r in X]
l2 = [[1/(1+math.exp(-sum(a*b for a,b in zip(r, c)))) for c in zip(*syn1)] for r in l1]
l2_delta = [[(ry[0]-a)*(a*(1-a)) for a in r] for r, ry in zip(l2, y)]
l1_delta = [[n*a*(1-a) for a,n in zip(r,m)] for r, m in zip(l1, [[sum(a2*b2 for a2,b2 in zip(r2,c2)) for c2 in syn1] for r2 in l2_delta])]
syn1 = [[n+sum(a*b for a,b in zip(r,c)) for c, n in zip(zip(*l2_delta), m)] for r, m in zip(zip(*l1), syn1)]
syn0 = [[n+sum(a*b for a,b in zip(r,c)) for c, n in zip(zip(*l1_delta), m)] for r, m in zip(zip(*X), syn0)]
Why do you think no one has boycotted github yet?
It really sounds like you just want to be offended about something. If you don't like github don't use it. You can still clone projects from github while using a different service or hosting it yourself almost trivially.