#!/usr/bin/env python """ Reimplementation by Jens Kleesiek of A Sparse Generative Model of V1 Simple Cells with Intrinsic Plasticity C. Weber and J. Triesch (2008) Neural Computation, 20, pp. 1261-84 Usage: First, download all files into one directory: - helmholtz.py (this file) - retina.py (for reading the image data patches) - KTimage.py (for exporting the weights and activations as pgm files for display) - look.tcl (to display those pgm files; look.tcl may be in any directory) - data.tar.gz (filtered images - preprocessing already done) Second, tar xvzf data.tar.gz (creates a folder 'data' with the filtered images inside). Third, create a directory /tmp/coco for the weights and activations files. Fourth, run: python helmholtz.py After the weights and activation files are written, start: ./look.tcl a w 0 1 (left mouse click reloads the newest weights and activation files). Fifth, wait ... """ import numpy as N import retina as R import KTimage as KT print "Sparse Helmholtz machine for V1 responses\nusing Wake-Sleep Algorithm" class helmholtz(object): def __init__(self, nvis, nhid, path): """ Data """ self.__retinaSize = N.sqrt(nvis) self.__data = R.data(str(path), 481, 321, self.__retinaSize) """ Parameters """ self.__nvis = nvis self.__nhid = nhid self.__alpha_bu = 0.1 self.__alpha_td = 0.02 """ Weights """ self.__Wbu = N.random.uniform(-0.1,0.1,(self.__nhid,self.__nvis)) self.__Wtd = N.random.uniform(-0.1,0.1,(self.__nvis,self.__nhid)) """ Intrinsic Plasticity """ self.__a = 2.5 self.__b = -5.0 self.__mu = 0.01 self.__eta_a = 0.0001 self.__eta_b = 0.0001 def __fantasy_vector(self): """ generates binary vector via threshold """ # generate uniform distributed numbers rnd = N.random.uniform(0,1,self.__nhid) fantasy = N.zeros(self.__nhid) val = 0.1 fantasy[N.nonzero(rnd