示例#1
0
def runPF(nparticle):
	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,0.15),
                                 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.particle_filter(code,env,timewindow=timewindow,dt=dt,
                                 nparticles=nparticle,mode = 'Silent')
	print "ping"	
	return [nparticle,results[4]]
env_rng.seed(12345)
code_rng.seed(67890)

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')

env_rng.seed(12345)
code_rng.seed(67890)

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))
if gaussian:
    print "MSE of gaussian filter %f"% mseg
print "MSE of particle filter %f"% msep

if plotting:
    
    #matplotlib.rcParams['font.size']=10
    
    plt.close()    
    plt.figure()
    ax1 = plt.gcf().add_subplot(2,1,1)
    times = np.arange(0.0,dt*timewindow,dt)
    if gaussian:    
        ax1.plot(times,sg,'r',label='Signal')