import nef net = nef.Network('Creature') net.make_input('command_input', [0,0]) net.make('command', neurons=100, dimensions=2) net.make('motor', neurons=100, dimensions=2) net.make('position', neurons=1000, dimensions=2, radius=5) net.make('scared_direction', neurons=100, dimensions=2) def negative(x): return -x[0], -x[1] net.connect('position', 'scared_direction', func=negative) net.connect('position', 'position') net.make('plan', neurons=500, dimensions=5) net.connect('command', 'plan', index_post=[0,1]) net.connect('scared_direction', 'plan', index_post=[2,3]) net.make('scared', neurons=50, dimensions=1) net.make_input('scared_input', [0]) net.connect('scared_input', 'scared') net.connect('scared', 'plan', index_post=[4]) def plan_function(x): c_x, c_y, s_x, s_y, s = x return s*(s_x)+(1-s)*c_x, s*(s_y)+(1-s)*c_y net.connect('plan', 'motor', func=plan_function) def rescale(x): return x[0]*0.1, x[1]*0.1 net.connect('motor', 'position', func=rescale) net.connect('command_input', 'command') net.add_to_nengo() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make('Q_A', neurons=50, dimensions=1) net.make('Q_B', neurons=50, dimensions=1) net.make('Q_C', neurons=50, dimensions=1) net.make('Q_D', neurons=50, dimensions=1) net.connect('s', 'Q_A', transform=[1,0]) net.connect('s', 'Q_B', transform=[-1,0]) net.connect('s', 'Q_C', transform=[0,1]) net.connect('s', 'Q_D', transform=[0,-1]) net.make_input('input', [0,0]) net.connect('input', 's') net.add_to_nengo() net.view() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make_array('Q', neurons=50, length=4, dimensions=1) net.connect('s', 'Q', transform=[[1,0],[-1,0],[0,1],[0,-1]]) net.make_input('input', [0,0]) net.connect('input', 's') net.add_to_nengo() net.view() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make_array('Q', neurons=50, length=4, dimensions=1) net.make('Qall', neurons=200, dimensions=4) net.connect('s', 'Q', transform=[[1,0],[-1,0],[0,1],[0,-1]]) def maximum(x): max_x = max(x) result = [0,0,0,0] result[x.index(max_x)] = 1 return result net.make('Action', neurons=200, dimensions=4) net.connect('Q', 'Qall') net.connect('Qall', 'Action', func=maximum) net.make_input('input', [0,0]) net.connect('input', 's') net.add_to_nengo() net.view() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make_array('Q', neurons=50, length=4, dimensions=1) net.connect('s', 'Q', transform=[[1,0],[-1,0],[0,1],[0,-1]]) net.make_input('input', [0,0]) net.connect('input', 's') e = 0.1 i = -1 transform = [[e, i, i, i], [i, e, i, i], [i, i, e, i], [i, i, i, e]] net.connect('Q', 'Q', transform=transform) net.add_to_nengo() net.view() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make_array('Q', neurons=50, length=4, dimensions=1) net.connect('s', 'Q', transform=[[1,0],[-1,0],[0,1],[0,-1]]) net.make_array('Action', neurons=50, length=4, dimensions=1) net.connect('Q', 'Action') net.make_input('input', [0,0]) net.connect('input', 's') e = 0.5 i = -1 transform = [[e, i, i, i], [i, e, i, i], [i, i, e, i], [i, i, i, e]] # Let's force the feedback connection to only consider positive values def positive(x): if x[0]<0: return [0] else: return x net.connect('Action', 'Action', func=positive, transform=transform) net.add_to_nengo() net.view() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make_array('Q', neurons=50, length=4, dimensions=1) net.connect('s', 'Q', transform=[[1,0],[-1,0],[0,1],[0,-1]]) net.make_array('Action', neurons=50, length=4, dimensions=1) net.connect('Q', 'Action') net.make_input('input', [0,0]) net.connect('input', 's') e = 1 i = -1 transform = [[e, i, i, i], [i, e, i, i], [i, i, e, i], [i, i, i, e]] def positive(x): if x[0]<0: return [0] else: return x net.connect('Action', 'Action', func=positive, transform=transform) net.add_to_nengo() net.view() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make_array('Q', neurons=50, length=4, dimensions=1) net.connect('s', 'Q', transform=[[1,0],[-1,0],[0,1],[0,-1]]) net.make_array('Action', neurons=50, length=4, dimensions=1) net.connect('Q', 'Action') net.make_input('input', [0,0]) net.connect('input', 's') e = 0.5 i = -1 transform = [[e, i, i, i], [i, e, i, i], [i, i, e, i], [i, i, i, e]] def positive(x): if x[0]<0: return [0] else: return x net.connect('Action', 'Action', func=positive, transform=transform) # Apply this function on the output def select(x): if x[0]<=0: return [0] else: return [1] net.make_array('ActionValue', neurons=50, length=4, dimensions=1) net.connect('Action', 'ActionValue', func=select) net.add_to_nengo() net.view() import nef net = nef.Network('Selection') net.make('s', neurons=200, dimensions=2) net.make_array('Q', neurons=50, length=4, dimensions=1) net.connect('s', 'Q', transform=[[1,0],[-1,0],[0,1],[0,-1]]) net.make_array('Action', neurons=50, length=4, dimensions=1) net.connect('Q', 'Action') net.make_input('input', [0,0]) net.connect('input', 's') e = 0.2 i = -1 transform = [[e, i, i, i], [i, e, i, i], [i, i, e, i], [i, i, i, e]] def positive(x): if x[0]<0: return [0] else: return x net.connect('Action', 'Action', func=positive, transform=transform) # Apply this function on the output def select(x): if x[0]<=0: return [0] else: return [1] net.make_array('ActionValue', neurons=50, length=4, dimensions=1) net.connect('Action', 'ActionValue', func=select) net.add_to_nengo() net.view() mm=1 mp=1 me=1 mg=1 ws=1 wt=1 wm=1 wg=1 wp=0.9 we=0.3 e=0.2 ep=-0.25 ee=-0.2 eg=-0.2 le=0.2 lg=0.2 D = 5 tau_ampa=0.002 tau_gaba=0.008 N = 50 radius = 1.5 import nef net = nef.Network('Basal Ganglia') net.make_input('input', [0]*D) net.make_array('StrD1',N, D,intercept=(e,1),encoders=[[1]],radius=radius) net.make_array('StrD2',N, D,intercept=(e,1),encoders=[[1]],radius=radius) net.make_array('STN',N, D,intercept=(ep,1),encoders=[[1]],radius=radius) net.make_array('GPi',N, D,intercept=(eg,1),encoders=[[1]],radius=radius) net.make_array('GPe',N, D,intercept=(ee,1),encoders=[[1]],radius=radius) net.connect('input','StrD1',weight=ws*(1+lg),pstc=tau_ampa) net.connect('input','StrD2',weight=ws*(1-le),pstc=tau_ampa) net.connect('input','STN',weight=wt,pstc=tau_ampa) def func_str(x): if x[0]