from pylab import * from IPython.core.display import Image def fig(x): return Image(filename="Figures/"+x+".png") from pylab import * def figs(*args): for i,f in enumerate(args): subplot(1,len(args),i+1) axis("off") fig = imshow(imread("Figures/"+f+".png")) from scipy import linalg # McCulloch-Pitts Neuron figs("mp-concrete","mp-neuron-abstract") def H(x): return 1.0*(x>=0.0) fig("gates-1") fig("gates-2") # example output from Rule 110 fig("r110-example") # interacting "particles" in Rule 110 fig("r110-interactions") fig("rule110-construction") # Rule 110 Zoom # http://uncomp.uwe.ac.uk/genaro/rule110/ctsRule110.html figs("rule110-zoom") N = 100 niter = 100 vstart = 1.0 * (rand(N)>0.5) # counting the number of bits Mall = linalg.circulant(1*(roll(arange(N)<3,-1))) imshow(Mall,interpolation='none',cmap=cm.gray) print 1*(dot(Mall,vstart)>=3) Mlo = linalg.circulant(-1*(arange(N)<2)) # Rule 110, two steps v = vstart.copy() result = [] for i in range(niter): result.append(v) v111 = (dot(Mall,v)>=3) vx00 = (dot(Mlo,v)>=0) on = (-1*v111-1*vx00>=0) v = 1*on imshow(array(result),interpolation='nearest',cmap=cm.gray) Z = zeros((N,N)) v = concatenate([vstart,zeros(2*N)]) M = array(bmat([[Z,-1*eye(N),-1*eye(N)],[Mall,Z,Z],[Mlo,Z,Z]])) b = concatenate([zeros(N),3*ones(N),zeros(N)]) imshow(M) result = [] for i in range(2*niter): result.append(v) v = H(dot(M,v)-b) result = array(result) imshow(result,interpolation='nearest',cmap=cm.gray) imshow(result[::2,:N],interpolation='nearest',cmap=cm.gray)