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

Thursday, June 23, 2011

dot product on memory

Here is some code to get the dot product (measure of similarity) for a memory store and a probe. the memory remembers what it has been exposed to. The dot product should be high if anything in memory matches the probe. Try exposing the memory to two animals then see how it reacts to an animal it has not seen before

import nef
import hrr
vocab=hrr.Vocabulary(128)
vocab.parse('cat,dog,mouse')

net=nef.Network('Test Network',quick=True)

#input1=net.make_input('input1',values=vocab.parse('cat').v)
#input2=net.make_input('input2',values=vocab.parse('cat').v)

A=net.make_array('A',neurons=30,dimensions=1,length=128)
B=net.make_array('B',neurons=30,dimensions=1,length=128)
C=net.make_array('C',neurons=30,dimensions=1,length=128)

M=net.make_array('M',neurons=30,dimensions=2,length=128)

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



#net.connect(input1,A)
#net.connect(input2,B,weight=0.01)
net.connect(B,B)
net.connect(C,B)

net.connect(A,M,index_post=[i*2 for i in range(128)]) # index_post refers to the destination, index_pre refers to the source
net.connect(B,M,index_post=[i*2+1 for i in range(128)]) # default is to take every one

# inside [] is python for take every second starting at 0 or take every second starting at 1


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

net.connect(M,Dot,func=multiply) # default is to apply the function to every ensemble in the network M

net.add_to(world)


No comments:

Post a Comment