import nef.nef_theano as nef import nef.convolution import hrr D = 10 vocab = hrr.Vocabulary(D, include_pairs=True) vocab.parse('a+b+c+d+e') net = nef.Network('Convolution') #Create the network object net.make('A', 300, D) #Make a population of 300 neurons and 10 dimensions net.make('B', 300, D) net.make('C', 300, D) conv = nef.convolution.make_convolution(net, '*', 'A', 'B', 'C', 100) #Call the code to construct a convolution network using #the created populations and 100 neurons per dimension net.run(1) # run for 1 second
N=100 # number of neurons per dimension import nef.nef_theano as nef import nps import nef.convolution import hrr import math import random # semantic pointers do not work well with small numbers of dimensions. # To keep this example model small enough to be easily run, we have lowered # the number of dimensions (D) to 16 and chosen a random number seed for # which this model works well. seed=17 net=nef.Network('Question Answering with Control',seed=seed) # Make a simple node to generate interesting input for the network random.seed(seed) vocab=hrr.Vocabulary(D,max_similarity=0.1) class Input(nef.SimpleNode): def __init__(self,name): self.zero=[0]*D nef.SimpleNode.__init__(self,name) self.RED_CIRCLE=vocab.parse('STATEMENT+RED*CIRCLE').v self.BLUE_SQUARE=vocab.parse('STATEMENT+BLUE*SQUARE').v self.RED=vocab.parse('QUESTION+RED').v self.SQUARE=vocab.parse('QUESTION+SQUARE').v def origin_x(self): if 0.1<self.t<0.3: return self.RED_CIRCLE
N = 60 D = 2 import nef.nef_theano as nef import random import math random.seed(27) net = nef.Network('Learn Square') #Create the network object # Create input and output populations. net.make('pre', N, D) #Make a population with 60 neurons, 1 dimensions net.make('post', N, D) #Make a population with 60 neurons, 1 dimensions net.make('error', N, D) #Make a population with 60 neurons, 1 dimensions # Create a random function input. net.make_input('input', math.sin) #Create a white noise input function .1 base freq, max #freq 10 rad/s, and RMS of .4; 0 is a seed net.connect('input', 'pre') # Create a modulated connection between the 'pre' and 'post' ensembles. net.learn( error='error', pre='pre', post='post', rate=5e-7) #Make an error population with 100 neurons, and a learning #rate of 5e-7
D = 16 subdim = 4 N = 100 seed = 7 import nef.nef_theano as nef import nef.convolution import hrr import math import random random.seed(seed) vocab = hrr.Vocabulary(D, max_similarity=0.1) net = nef.Network('Question Answering with Memory') #Create the network object net.make('A', 1, D, mode='direct') #Make some pseudo populations (so they run #well on less powerful machines): 1 neuron, #16 dimensions, direct mode net.make('B', 1, D, mode='direct') net.make_array('C', N, D / subdim, dimensions=subdim, quick=True, radius=1.0 / math.sqrt(D)) #Make a real population, with 100 neurons per #array element and D/subdim elements in the array #each with subdim dimensions, set the radius as #appropriate for multiplying things of this #dimension
N = 60 D = 1 import nef.nef_theano as nef import random import math random.seed(27) net = nef.Network('Learn Communication') #Create the network object # Create input and output populations. net.make('pre', N, D) #Make a population with 60 neurons, 1 dimensions net.make('post', N, D) #Make a population with 60 neurons, 1 dimensions net.make('error', N, D) # Create a random function input. net.make_input('input', math.sin) #Create a white noise input function .1 base freq, max #freq 10 rad/s, and RMS of .5; 12 is a seed net.connect('input', 'pre') # Create a modulated connection between the 'pre' and 'post' ensembles. net.learn( error='error', pre='pre', post='post', rate=5e-7) #Make an error population with 100 neurons, and a learning #rate of 5e-7 # Set the modulatory signal. net.connect('pre', 'error')
D = 16 subdim = 4 N = 100 seed = 7 import nef.nef_theano as nef import nef.convolution import hrr import math import random random.seed(seed) vocab = hrr.Vocabulary(D, max_similarity=0.1) net = nef.Network('Question Answering') #Create the network object net.make('A', 1, D, mode='direct') #Make some pseudo populations (so they #run well on less powerful machines): #1 neuron, 16 dimensions, direct mode net.make('B', 1, D, mode='direct') net.make_array('C', N, D / subdim, dimensions=subdim, quick=True, radius=1.0 / math.sqrt(D)) #Make a real population, with 100 neurons per #array element and D/subdim elements in the array #each with subdim dimensions, set the radius as #appropriate for multiplying things of this
N = 60 D = 2 import nef.nef_theano as nef import random import math random.seed(37) net = nef.Network('Learn Product') #Create the network object # Create input and output populations. net.make('pre', N, D) #Make a population with 60 neurons, D dimensions net.make('post', N, 1) #Make a population with 60 neurons, 1 dimensions net.make('error', N, 1) #Make a population with 60 neurons, 1 dimensions # Create a random function input. net.make_input('input', math.sin) net.connect('input', 'pre') # Create a modulated connection between the 'pre' and 'post' ensembles. net.learn( error='error', pre='pre', post='post', rate=5e-7) #Make an error population with 100 neurons, and a learning #rate of 5e-7 # Set the modulatory signal to compute the desired function def product(x):
import nef.nef_theano as nef import nps D = 5 net = nef.Network('Basal Ganglia') #Create the network object net.make_input('input', [0] * D) #Create a controllable input function #with a starting value of 0 for each of D #dimensions net.make('output', 1, D, mode='direct') #Make a population with 100 neurons, 5 dimensions, and set #the simulation mode to direct nps.basalganglia.make_basal_ganglia( net, 'input', 'output', D, same_neurons=False, neurons=50) #Make a basal ganglia model with 50 neurons per action net.add_to_nengo()
for i in range(6): self.add( space.Box(1, 1, 1, mass=1, color=Color(0x8888FF), flat_shading=False), random.uniform(-5, 5), random.uniform(-5, 5), random.uniform(4, 6)) self.sch.add(space.Room.start, args=(self, )) from ca.nengo.util.impl import NodeThreadPool, NEFGPUInterface net = nef.Network('Braitenberg') input1 = net.make_input('right eye', [0]) input2 = net.make_input('left eye', [0]) sense1 = net.make("right input", N, 1) sense2 = net.make("left input", N, 1) motor1 = net.make("right motor", N, 1) motor2 = net.make("left motor", N, 1) net.connect(input1, sense1) net.connect(input2, sense2) net.connect(sense2, motor1) net.connect(sense1, motor2) net.add_to_nengo()