def run_filters(args):

    i,j,dtheta,alpha = args
    print i,j

    dt = 0.001
    phi = 1.0
    zeta = 1.0
    eta = 1.0
    gamma = 1.0
    timewindow = 30000
    dm = 0.0
    tau = 1.0
    nparticles = 1000

    #env is the "environment", that is, the true process to which we don't have access

    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(phi=phi,tau=tau,alpha=alpha,
                                 thetas=np.arange(-dtheta,1.1*dtheta,2*dtheta),
                                 dm=dm,randomstate=code_rng)

    
    env_rng.seed(12345)
    code_rng.seed(67890)
    env.reset(np.array([0.0]))
    code.reset()
    
    [densem,densevar,spsg,sg,dense_mse] = pf.gaussian_filter(code,env,timewindow=timewindow,dt=dt,
                                                            dense=True)
   
    env_rng.seed(12345)
    code_rng.seed(67890)
    env.reset(np.array([0.0]))
    code.reset()
    
    [sparsem,sparsevar,spsg,sg,sparse_mse] = pf.gaussian_filter(code,env,timewindow=timewindow,dt=dt,
                                                                dense=False)

    env_rng.seed(12345)
    code_rng.seed(67890)
    env.reset(np.array([0.0]))
    code.reset()
    
    [particle_mse,ws] = pf.mse_particle_filter(code, env, timewindow=timewindow,
                                                         dt=dt, nparticles=nparticles,
                                                         testf=(lambda x:x))
    return i,j,dense_mse,sparse_mse,particle_mse
def run_filters(arg):
    i,dtheta = arg
    print arg
    dt = 0.001
    phi = 1.0
    zeta = 1.0
    eta = 1.0
    gamma = 1.0
    alpha = 0.5
    timewindow = 200000
    dm = 0.0
    tau = 1.0
    nparticles = 500

    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/2,tau=tau,
                                 thetas=np.arange(-20.0,20.0,dtheta),
                                 dm=dm,randomstate=code_rng)
    
    env_rng.seed(12345)
    code_rng.seed(67890)
    env.reset(np.array([0.0]))
    code.reset()
    
    [densem,densevar,spsg,sg,dense_mse] = pf.gaussian_filter(code,env,timewindow=timewindow,dt=dt,
                                                            dense=True)
    
    env_rng.seed(12345)
    code_rng.seed(67890)
    env.reset(np.array([0.0]))
    code.reset()
    
    [sparsem,sparsevar,spsg,sg,sparse_mse] = pf.gaussian_filter(code,env,timewindow=timewindow,dt=dt,
                                                                dense=False)
    
    env_rng.seed(12345)
    code_rng.seed(67890)
    env.reset(np.array([0.0]))
    code.reset()
    
    [msep,ws] = pf.mse_particle_filter(code, env, timewindow=timewindow,
                                                         dt=dt, nparticles=nparticles,
                                                         testf=(lambda x:x))

    return i,dense_mse,sparse_mse,msep
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]
code = pn.PoissonPlasticCode(A=alpha,phi=phi/2,tau=tau,
                             thetas=np.arange(-20.0,20.0,0.15),
                             dm=dm,randomstate=code_rng)

#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()
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: