This blog is for notes on how to use the Nengo spiking neuron modeling system

Tuesday, June 21, 2011

vectors

Nengo can represent an individual values in each dimension of a net but it can also treat all the dimensions as a vector. Vectors are used as symbols in nengo, i.e., the pattern in the vector represents something specific, such as word. The dot product measures the similarity between two vectors

e.g.:

if you have two three dimensional vectors a1 a2 a3 and b1 b2 b3
you get the dot product by multiplying the vectors and adding up the product
so.... a1*b1+a2*b2+a3*b3 = dot product of ab

To do this in nengo the parts need to be created, then they can be added (note that the adding happens for free just by putting the vectors into the same dimension in a net)

Here is an example (you can test it by making the function controls look similar or dissimilar):

import nef
net=nef.Network('Test Network')
net.add_to(world)

input1=net.make_input('input1',values=[0,0,1])
input2=net.make_input('input2',values=[1,0,0])

A=net.make('A',neurons=100,dimensions=3)
B=net.make('B',neurons=100,dimensions=3)

m1=net.make('m1',neurons=100,dimensions=2)
m2=net.make('m2',neurons=100,dimensions=2)
m3=net.make('m3',neurons=100,dimensions=2)

Dot=net.make('Dot',neurons=100,dimensions=1)

net.connect(input1,A)
net.connect(input2,B)

net.connect(A,m1,transform=[[1,0,0],[0,0,0]])
net.connect(A,m2,transform=[[0,1,0],[0,0,0]])
net.connect(A,m3,transform=[[0,0,1],[0,0,0]])

net.connect(B,m1,transform=[[0,0,0],[1,0,0]])
net.connect(B,m2,transform=[[0,0,0],[0,1,0]])
net.connect(B,m3,transform=[[0,0,0],[0,0,1]])

def multiply(x):
  return x[0]*x[1]

net.connect(m1,Dot,func=multiply)
net.connect(m2,Dot,func=multiply)
net.connect(m3,Dot,func=multiply)



No comments:

Post a Comment