Esempio n. 1
0
def simulator( v2, N_filters, nonlinearity, N_cells , sigma_spatial , N_timebins ):
    retina = simulate_retina.LNLNP_ring_model( nonlinearity = nonlinearity , 
                                               N_cells = N_cells , 
                                               sigma_spatial = sigma_spatial )
#    stimulus = simulate_retina.white_gaussian_stimulus( dimension  = N_cells[0] , 
#                                                         sigma = 1. )
    stimulus = simulate_retina.Stimulus( simulate_retina.white_gaussian )
    return simulate_retina.run_LNLNP( retina , stimulus = stimulus , 
                   N_timebins = N_timebins ,
                   average_me = {'features':lambda x: NL(np.dot(filters,x))} )
Esempio n. 2
0
def phaseout( objective, true_run , stimulus , V2 , phase ):
    iterations[0] = -1
    model = copy.deepcopy( true_run['model'] )
    model['U'] = retina.ring_weights( shape=true_run['model']['U'].shape, 
                                      offset_out=phase)
    phase_objective = LL_with_U( objective , model['U'] , V2 )
    true_objective  = LL_with_U( objective , true_run['model']['U'] , V2 )
    params      = optimize_V1( phase_objective , true_run , model['U'], V2 )
    opt_params  = optimize_V1( true_objective  , true_run , true_run['model']['V'], V2 )
    model['V']  = params['V1']
    dLopt = true_objective.LL(true_run['model']['V']) - true_objective.LL(opt_params)
    dLL   = phase_objective.LL(params) - true_objective.LL(opt_params)
    seed        = Rand.get_state()
    true_100    = retina.run_LNLNP( true_model , stimulus = stimulus , 
                                    keep=frozenset(['intensity']), N_timebins = 100000 )
    Rand.set_state(seed)
    this_100 = retina.run_LNLNP( model , stimulus = stimulus , 
                                 keep=frozenset(['intensity']), N_timebins = 100000 )
    intensities = np.vstack([true_100['intensity'].flatten(),this_100['intensity'].flatten()])
    order       = np.argsort( intensities[0,:] )
    intensities = intensities[:,order[::20]]
    p.close('all')
    p.figure(1, figsize=(10,12))
    ax0 = p.subplot(3,1,1)
    p.plot( true_100['model']['V'].T )
    #ax0.xaxis.set_label_text('subunits')
    p.title('V filters')
    ax1 = p.subplot(3,1,2)
    p.plot( true_100['model']['U'].T )
    #ax1.xaxis.set_label_text('cones')
    p.title('True U filters ,  sigma = %.0f' % (sigma_spatial[0]))
    ax2 = p.subplot(3,1,3)
    p.semilogy( intensities.T )
    ax2.xaxis.set_label_text('samples reordered by intensity of true model')
    ax2.yaxis.set_label_text('intensities in spikes / bin')
    p.title('Intensities of true vs. out-of-phase model  (dLL=%.1e bits/spike, dLopt=%.1e) ' % \
             (dLL/np.log(2.), dLopt/np.log(2.)) )
    #p.subplot(2,1,2)
    #p.plot( intensities.T )
    p.savefig('/Users/kolia/Desktop/out-of-phase_sigma%d_phase%.1f.pdf' % \
             (true_run['model']['sigma_spatial'][0], phase),format='pdf')
Esempio n. 3
0
             (dLL/np.log(2.), dLopt/np.log(2.)) )
    #p.subplot(2,1,2)
    #p.plot( intensities.T )
    p.savefig('/Users/kolia/Desktop/out-of-phase_sigma%d_phase%.1f.pdf' % \
             (true_run['model']['sigma_spatial'][0], phase),format='pdf')

N_cells       = [ 20 , 13 , 7 ]
V2            =  0.5 * np.ones(N_cells[1])
def NL(x): return x + 0.5 * (V2 * ( x ** 2 ).T).T

for sigma_spatial in [[ 20., 3. ] , [ 10., 3. ] , [ 5., 3. ] , [ 2., 3. ] , [1.,3.]]:
    true_model = retina.LNLNP_ring_model( nonlinearity = NL , N_cells = N_cells , 
                                           sigma_spatial = sigma_spatial )
    
    stimulus = retina.Stimulus( retina.white_gaussian )
    true_run = retina.run_LNLNP( true_model , stimulus = stimulus , 
                             keep=frozenset(['intensity']), N_timebins = 1000000 )
    
    obj_V1 = LL_V1( true_model['V'] )
    
    phaseout( obj_V1, true_run , stimulus , V2 , 0.5 )
    
    
# candidate 'saturating' nonlinearities:
# exp(2.*x+1.) - exp(3.*(x-0.5)) + exp(3.5*(x-1.045))
# x = arange(-2.,3.1,0.1) ; plot( x, exp(3.*(x+1.)) - exp(3.001*(x+0.999)) + exp(4.*(x-1.718)))

import numpy as np
import pylab as p
# based on the taylor expansion of 1/(1+exp(x)) wrt exp(x) at exp(x0) 
taylor = lambda x0,N,shift,constant,scale : lambda x : \
         scale*( 1. - constant - np.sum( (-1)**(np.arange(N)[:,np.newaxis])   * \