I enjoyed reading "A tutorial on the free-energy framework for modelling perception and learning" by Rafal Bogacz, which is freely available here. In particular, the author encourages to replicate the results in the paper. He is himself giving solutions in matlab, so I had to do the same in python all within a notebook...
A set of bash code to resize images to a fixed size.
Problem statement: we have a set of images with heterogeneous sizes and we want to homogenize the database to avoid problems when classifying them. Solution: ImageMagick.
We first identify the size and type of images in the database. The database is a collection of folders containing each a collection of files. We thus do a nested recursive loop:
Sometimes, you need to pick up the $N$-th extremal values in a mutli-dimensional matrix.
Let's suppose it is represented as a
nd-array (here, I further suppose you are using the numpy library from the python language). Finding extremal values is easy with
argsort but this function operated on 1d vectors... Juggling around indices is sometimes not such an easy task, but luckily, we have the
Let's unwrap an easy solution combining these functions:
It is insanely useful to create movies to illustrate a talk, blog post or just to include in a notebook:
from IPython.display import HTML HTML('<center><video controls autoplay loop src="../files/noise.mp4" width=61.8%/></center>')
For years I have used a custom made solution made around saving single frames and then calling
ffmpeg to save that files to a movie file. That function (called
anim_save had to be maintained accross different libraries to reflect new needs (going to WEBM and MP4 formats for instance). That made the code longer than necessary and had not its place in a scientific library.
Here, I show how to use the
animation library from matplotlib to replace that
After reading the paper http://www.jneurosci.org/content/34/37/12601.full by Helena X. Wang, Elisha P. Merriam, Jeremy Freeman, and David J. Heeger (The Journal of Neuroscience, 10 September 2014, 34(37): 12601-12615; doi: 10.1523/JNEUROSCI.1034-14.2014), I was interested to test the hypothesis they raise in the discussion section :
The aperture-inward bias in V1–V3 may reflect spatial interactions between visual motion signals along the path of motion (Raemaekers et al., 2009; Schellekens et al., 2013). Neural responses might have been suppressed when the stimulus could be predicted from the responses of neighboring neurons nearer the location of motion origin, a form of predictive coding (Rao and Ballard, 1999; Lee and Mumford, 2003). Under this hypothesis, spatial interactions between neurons depend on both stimulus motion direction and the neuron's relative RF locations, but the neurons themselves need not be direction selective. Perhaps consistent with this hypothesis, psychophysical sensitivity is enhanced at locations further along the path of motion than at motion origin (van Doorn and Koenderink, 1984; Verghese et al., 1999).
Concerning the origins of aperture-inward bias, I want to test an alternative possibility. In some recent modeling work:
Laurent Perrinet, Guillaume S. Masson. Motion-based prediction is sufficient to solve the aperture problem. Neural Computation, 24(10):2726--50, 2012 http://invibe.net/LaurentPerrinet/Publications/Perrinet12pred
I was surprised to observe a similar behavior: the trailing edge was exhibiting a stronger activation (i. e. higher precision revealed by a lower variance in this probabilistic model) while I would have thought intuitively the leading edge would be more informative. In retrospect, it made sense in a motion-based prediction algorithm as information from the leading edge may propagate in more directions (135° for a 45° bar) than in the trailing edge (45°, that is a factor of 3 here). While we made this prediction we did not have any evidence for it.
In this script the predictive coding is done using the
MotionParticles package and for a http://motionclouds.invibe.net/ within a disk aperture.
For a master's project in computational neuroscience, we adopted a quite novel workflow to go all the steps from the learning of the small steps to the wrtiting of the final thesis. Though we were flexible in our method during the 6 months of this work, a simple workflow emerged that I describe here.
In this notebook, we test the convergence of SparseNet as a function of different learning parameters. This shows the relative robusteness of this method according to the coding parameters, but also the importance of homeostasis to obtain an efficient set of filters:
- first, whatever the learning rate, the convergence is not complete without homeostasis,
- second, we achieve better convergence for similar learning rates and on a certain range of learning rates for the homeostasis
- third, the smoothing parameter
alpha_homeohas to be properly set to achieve a good convergence.
- last, this homeostatic rule works with the diferent variants of sparse coding.
See also :
- http://blog.invibe.net/posts/2015-05-05-reproducing-olshausens-classical-sparsenet.html for a description of how SparseNet is implemented in the scikit-learn package
- http://blog.invibe.net/posts/2015-05-06-reproducing-olshausens-classical-sparsenet-part-2.html for a descrtiption of how we managed to implement the homeostasis
- this PR to sklearn