Could I have an example usage of the "set_block" method?

Request or post your example code here
Post Reply
asinha
Posts: 37
Joined: Wed Oct 15, 2014 5:12 pm
Location: Hatfield, Hertfordshire, UK
Contact:

Could I have an example usage of the "set_block" method?

Post by asinha »

I'd like to use the "set_block" method correctly. I was wondering if any one had an example code snippet that would explain it?

For example, if I have the following network:

Code: Select all

TIFGroup * neurons_e = new TIFGroup(1000);
SparseConnection * con_ee = new SparseConnection(neurons_e,neurons_e,someweight,sparseness,GLUT);
and I want to increase the strengths of a subset of the con_ee connections, can I use set_block to do it? How? For example if I want to increase the strengths of all the connections between neurons from NeuronID 250 and NeuronID 500?

Thanks,
Ankur
User avatar
zenke
Site Admin
Posts: 156
Joined: Tue Oct 14, 2014 11:34 am
Location: Basel, CH
Contact:

Re: Could I have an example usage of the "set_block" method?

Post by zenke »

Hi,

yes you should be able to do it with set_block. For your example that would introduce a cell assembly into con_ee, you could use

Code: Select all

AurynWeight w = 0.3;
con_ee->set_block(250,500,250,500,w);
Auryn only offers very rudimentary ways of setting up and manipulating connections matrices. I found the best work flow to get the connectivity you need for more complex projects is to generate a weight matrix and weight structure needed with MATLAB or Python (numpy/scipy). Both programs allow powerful matrix manipulation and the results can be exported to the Matrix Market format. This format can then be loaded by SparseConnection (there is a short howto here http://www.fzenke.net/auryn/doku.php?id ... _in_python).

However, for simple manipulations such as adding a Hebbian assembly or changing the sub-blocks of a weight matrix Auryn has efficient and fast methods, such as set_block, for instance. A few things are important to note. First, set_block only modifies existing connections in a sparse matrix and does create non-existent ones. So once the connectivity is fixed (typically after initializing a SparseConnection or any of its descendants) set_block will only set the weights of existing connections in a block.
The second thing that is important to know is that in Auryn connection indices have to be read in "forward-direction" --- i.e. the connection w->get(i,j) if it exists connects neuron i to neuron j. So the row index i stores the presynaptic identity and index j the postsynaptic. This is in contrast to most people thinking in matrix notation where the activity vector is multiplied from the right ... I always found this confusing so Auryn does it the other way around and adds to the confusion.

With this said,

Code: Select all

void set_block(NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, AurynWeight weight);
will set all existing elements spanned by the block from presynaptic index lo_row to presynaptic index hi_row and from postsynaptic index lo_col to index hi_col with the weight weight.
asinha
Posts: 37
Joined: Wed Oct 15, 2014 5:12 pm
Location: Hatfield, Hertfordshire, UK
Contact:

Re: Could I have an example usage of the "set_block" method?

Post by asinha »

Ah, that makes sense. I was trying to use set_block, but I think I have a few too many blocks to manipulate - my simulation kept hanging up at the set_block loop.

I would like to do everything in my one C++ program file, though, instead of running part of a simulation, then saving matrix steps and making modifications with another program then again loading them etc. For example, would you have a quick way of strengthening the required synapses in Vogels et al (Figure 4C)? I guess I could use eigen or armadillo which are both fast C++ matrix/algebra libraries. Have you used them with auryn yet by any chance?

http://eigen.tuxfamily.org/dox/GettingStarted.html
http://arma.sourceforge.net/

Thanks again,
Ankur
User avatar
zenke
Site Admin
Posts: 156
Joined: Tue Oct 14, 2014 11:34 am
Location: Basel, CH
Contact:

Re: Could I have an example usage of the "set_block" method?

Post by zenke »

Hi Ankur,

Auryn is using its own tailored sparse matrix class which might not be well adapted to interact with eigen or armadillo. By now there are functions in place to do what you would like to do efficiently. What you might want to look into is the load_pattern method in SparseConnection.

Suppose you want to store a pattern such as I did in Vogels et al. Fig 4, you simply need to figure out the neuron indices you would want within that pattern. These indices you simply store as a list in text format in a file. In Auryn these files have the extension .pat for "pattern file" (you can store more than one pattern per file; see http://www.fzenke.net/auryn/doku.php?id=manual:pat for details).

Say you want neurons 1,3,5,8,9 in a pattern and 2,4,8,10 in a second, the pat-file would like like this.

Code: Select all

1
3
5
8
9

2
4
8
10
Let's assume this file is called mytwopatterns.pat. To add these assemblies on top of your random connectivity in your connection con_ee, all you need to do is call

Code: Select all

con_ee->load_patterns("mytwopatterns.pat",lambda);
where lambda is the strength that is added to any affected synapses. Note, you can also run load_patterns in overwrite mode in which synaptic weights will be set equal to lambda.

Pat files can additionally have a second column with a gamma parameter between zero and one which signifies the strength. When omitted gamma is assumed 1. With gamma values you can create graded attractor patterns in your cell assemblies as is shown in one of my bigger simulations which were released in the press package along with Vogels et al. 2011. Here you find one example of what you can do with it http://fzenke.net/uploads/images/movies ... _Large.mov

To create patterns I usually draw them in Gimp or any graphics tool, then save them to JPG (I convert them to grayscale first I should say). You can convert them to the format Auryn understands by a few line of python code along these lines

Code: Select all

import matplotlib.image as mpimg
import numpy as np

img=mpimg.imread(filename)
img = img.ravel()
img = np.array(img,dtype=float)
img /= 255.0
thr = 0.5

print "# Pattern loaded from file ", filename
for c in np.argwhere(img):
    i = c[0]
    val = img[i]
    if (val>thr):
        print "%i %f"%(i,1.*val)
I hope that helps!

Best,

Friedemann
asinha
Posts: 37
Joined: Wed Oct 15, 2014 5:12 pm
Location: Hatfield, Hertfordshire, UK
Contact:

Re: Could I have an example usage of the "set_block" method?

Post by asinha »

Aha! That sounds awesome! I'll go try it out today! Thanks for the detailed answer.
Post Reply