def runGauss(dtheta): env_rng = np.random.mtrand.RandomState() env = ge.GaussianEnv(gamma=gamma,eta=eta,zeta=zeta, x0=0.0,y0=.0,L=1.0,N=1,order=1, sigma=0.1,Lx=1.0,Ly=1.0,randomstate=env_rng) env.reset(np.array([0.0])) #code is the population of neurons, plastic poisson neurons code_rng = np.random.mtrand.RandomState() code = pn.PoissonPlasticCode(A=alpha,phi=phi,tau=tau, thetas=np.arange(-10.0,10.0,dtheta), dm=dm,randomstate=code_rng,alpha=alpha) #s is the stimulus, sps holds the spikes, rates the rates of # each neuron and particles give the position of the particles # weights gives the weights associated with each particle env_rng.seed(12345) code_rng.seed(67890) env.reset(np.array([0.0])) code.reset() results = pf.gaussian_filter(code,env,timewindow=timewindow,dt=dt, mode = 'Silent', dense = True) presults = pf.fast_particle_filter(code,env,timewindow=timewindow,dt=dt, nparticles=nparticles, mode='Silent', dense=False) print "ping" return [dtheta,results,presults]
env.reset(np.array([0.0])) #code is the population of neurons, plastic poisson neurons code_rng = np.random.mtrand.RandomState() code = pn.PoissonPlasticCode(A=alpha,phi=phi,tau=tau,thetas=np.arange(-3.0,3.0,0.1),dm=dm,alpha=alpha,randomstate=code_rng) env_rng.seed(12345) code_rng.seed(67890) #s is the stimulus, sps holds the spikes, rates the rates of each neuron and particles give the position of the particles #weights gives the weights associated with each particle f = lambda x : -1.0+2.0/(1.0+np.exp(-5*x)) [s,mse,frate,m,st,spiketrain,spiketimes] = pf.fast_particle_filter(code,env,dt=dt,timewindow=timewindow,nparticles=nparticles,mode='v',testf = f) plt.close() times = np.arange(0.0,dt*timewindow,dt) plt.figure() ax1 = plt.gcf().add_subplot(1,1,1) ax1.plot(times,map(f,s),'r',label = 'True Sate') #m = np.average(particles,weights=weights,axis=1) #st = np.std(particles,weights=weights,axis=1) #ext = (0.0,dt*timewindow,code.neurons[-1].theta,code.neurons[0].theta) #plt.imshow(rates.T,extent=ext,cmap = cm.gist_yarg,aspect = 'auto',interpolation ='nearest') thetas = [code.neurons[i].theta for i in spiketrain] ax1.plot(times[spiketimes],map(f,thetas),'yo',label='Observed Spikes')
code_rng.seed(code_seed) env.reset(np.array([0.0])) code.reset() if gaussian: [mg,varg,spsg,sg,mseg] = pf.gaussian_filter(code,env,timewindow=timewindow,dt=dt,mode = 'v',dense=True) stg = np.sqrt(varg) print stg.shape, varg.shape env_rng.seed(env_seed) code_rng.seed(code_seed) env.reset(np.array([0.0])) code.reset() #[mp,varp,spsp,sp,msep,parts,ws] = pf.particle_filter(code,env,timewindow=timewindow,dt=dt,nparticles=nparticles,mode = 'v',testf = (lambda x:x)) [s,msep,spikecount,m,st,sptrain,sptimes] = pf.fast_particle_filter(code,env,timewindow=timewindow,dt=dt,nparticles=nparticles,mode = 'v',testf = (lambda x:x),dense=True) if gaussian: print "MSE of gaussian filter %f"% mseg print "MSE of particle filter %f"% msep times = np.arange(0.0,dt*timewindow,dt) plt.figure() ax1 = plt.gcf().add_subplot(1,1,1) ax1.plot(times,s,'r',label = 'True Sate') #m = np.average(particles,weights=weights,axis=1) #st = np.std(particles,weights=weights,axis=1) #ext = (0.0,dt*timewindow,code.neurons[-1].theta,code.neurons[0].theta) #plt.imshow(rates.T,extent=ext,cmap = cm.gist_yarg,aspect = 'auto',interpolation ='nearest')