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

Monday, June 20, 2011

Two functions

a net can compute more than one function, here is an example:

import nef
net=nef.Network('Test Network')
net.add_to(world)
input1=net.make_input('input1',values=[0])
input2=net.make_input('input2',values=[0])
input3=net.make_input('input3',values=[0])

A=net.make('A',neurons=100,dimensions=1)
B=net.make('B',neurons=100,dimensions=1)
F=net.make('F',neurons=100,dimensions=1)
C=net.make('C',neurons=100,dimensions=3)
D=net.make('D',neurons=100,dimensions=2)


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

net.connect(A,C,transform=[[1],[0],[0]])
net.connect(B,C,transform=[[0],[1],[0]])
net.connect(F,C,transform=[[0],[0],[1]])


def multiply(x):
  return x[0]*x[1],x[0]*x[2]    # just add more functions
                                              # the dimension of the recieving network must match

net.connect(C,D,func=multiply)

neuron range - radius

the radius sets the range that a net can represent, the default is 1. however the nets have difficulty representing their extreme range because it involves half the neurons firing all the time. therefore, in practice the maximum is lower than the radius

Strong claim

In order to compute a non linear function you must have a combined representation of the variables. So it takes two steps, combine and then compute. The combining can be considered equivilent to the function of the hidden layer in a network - see the multiplication example

multipy and transpose

 Here is the multiplication example where the result is transposed into two different values

import nef
net=nef.Network('Test Network')
net.add_to(world)
input1=net.make_input('input1',values=[0])
input2=net.make_input('input2',values=[0])
A=net.make('A',neurons=100,dimensions=1)
B=net.make('B',neurons=100,dimensions=1)
C=net.make('C',neurons=100,dimensions=2)
D=net.make('D',neurons=100,dimensions=2)


net.connect(input1,A)
net.connect(input2,B)
net.connect(A,C,transform=[[1],[0]])
net.connect(B,C,transform=[[0],[1]],pstc=0.03) # can also set pstc here


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

net.connect(C,D,func=multiply,transform=[[.5],[1]])

script: combining values in a function

This example takes values from two different networks and multiplies them. Any function can be done in this way - by converting a python function

import nef
net=nef.Network('Test Network')
net.add_to(world)
input1=net.make_input('input1',values=[0])
input2=net.make_input('input2',values=[0])
A=net.make('A',neurons=100,dimensions=1)
B=net.make('B',neurons=100,dimensions=1)
C=net.make('C',neurons=100,dimensions=2)
D=net.make('D',neurons=100,dimensions=1)


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


# transform - the brackets are the dimensions of the receiving network
# the values in the brackets are the transpose weights

net.connect(A,C,transform=[[1],[0]])
net.connect(B,C,transform=[[0],[1]])


# define a python function



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




# compute that function here

net.connect(C,D,func=multiply)

script: passing values

Here is some script from the tutorial for passing values 
 
import nef
net=nef.Network('Test Network')
net.add_to(world)
input=net.make_input('input',values=[0])
A=net.make('A',neurons=100,dimensions=1)
B=net.make('B',neurons=100,dimensions=1)
net.connect(input,A)
net.connect(A,B)
 
Here it is broken down:


# this part sets it up
 
import nef
net=nef.Network('Test Network')
net.add_to(world)
# create an input
# input is the name of the input
# the fact that it is colored may mean input is a key word also 
# probably best to use something else, e.g., input1
input=net.make_input('input',values=[0])
 
# create some networks
A=net.make('A',neurons=100,dimensions=1)
B=net.make('B',neurons=100,dimensions=1)
 
# connect everything up
net.connect(input,A)
net.connect(A,B)
 

nengo script

Nengo uses Python to run script. To create a script open a txt document, write the script, and save it as name.py (i.e., python code). To run it, open the script from within the python environment and it will run in the same display window used by the nengo graphical interface. It is not currently possible to go back and forth between the graphical interface and script. If you want to encode a custom function into connection weights you need to use the script. The scripting language can encode any python function as connection weights. That is, nengo translates directly from python code to spiking neurons

see scripting tutorial here:

http://www.arts.uwaterloo.ca/~cnrglab/?q=node/616