from ca.nengo.util import MU import random def destroy_connections(w,proportion): if proportion>1: proportion=1 total=len(w)*len(w) pool=list(xrange(total)) for i in xrange(int(proportion*total)): x=random.randrange(total-i) w[x/len(w)][x%len(w)]=0 pool[x]=pool[total-i-1] return w def make(network,source,origin,target,termination,pstc,transform=None,destroy=0): source=network.getNode(source) target=network.getNode(target) decoder=source.getOrigin(origin).decoders if transform is not None: decoder=MU.prod(decoder,transform) w=MU.prod(target.encoders,MU.transpose(decoder)) if destroy>0: destroy_connections(w,destroy) t=target.addTermination(termination,w,pstc,False) network.addProjection(source.getOrigin('AXON'),t)