def test_network_sim(): """ Test single trajectory without using simtypes """ session, net = tools.db.get_network(45) handler = erfs.MeanfieldHandler(net) # somewhat legacy parameters for this test run std_pars = { "show_results": False, "id": net.id, "sig_start": 0., # noise parameters mpr.W_NOISE: 0., # sigma_w mpr.EL_NOISE: 0., # = sigma_L mpr.P_EE: 0.5, # recurrent connectivity p "cores": 4, # cores to use for sim "sig_center": 0.3, "sig_len": 1000., "sig_weight": .4, "sig_width": .2, "sig_rate": 2000., "base_seed_run": 25757712619, "base_seed": 29529492, # runtime "tmax": 2000., } handler.set_states({ mpr.W_J: net.e.paramset.parameters['w_0'] + net.e.paramset.parameters['w_1'] }) sim = NestSimulator(handler, cores=4) sim.set_paramset("bump") sim.set_params("gen", **std_pars) sim_ret = sim.run() print "E-rate after offset: ", sim_ret["pop_rate"]["e"] print "I-rate after offset: ", sim_ret["pop_rate"]["i"] print "Averaged maximal E-rate after offset: ", max(sim_ret["shape_mean"]) np.testing.assert_almost_equal(sim_ret["pop_rate"]["e"], 6.07852487681, decimal=10) np.testing.assert_almost_equal(sim_ret["pop_rate"]["i"], 4.81666666667, decimal=10) np.testing.assert_almost_equal(max(sim_ret["shape_mean"]), 42.245566508, decimal=10)
def test_simtype_drift(): """Test the SimDrift simtype""" session, net = tools.db.get_network(45) # get meanfield handler (abstracts network parameter handling) and set connectivity parameter handler = erfs.MeanfieldHandler(net) # get simulation type btype = session.query(cb.SimType).filter(cb.SimType.name == "drift").one() # get simulation wrapper # set to_memory = False to save simulation to hdf5 file wrapper = btype.get_wrapper(to_memory=True, session=session) reps = 1 initials = 2 tmax = 2000. # parameters used for this example gen_params = { # noise parameters mpr.EL_NOISE: 0., mpr.P_EE: 1., # 1mV of noise on the leak reversal potentials mpr.W_NOISE: 0., # run parameters "cores": 4, # cores to use for sim "tmax": tmax, # runtime "base_seed": 1, # seed for connectivity noise "base_seed_run": 1, # seed for run noise "reps": reps, # do only 1 repetition "initials": initials } # run the simulation wrapper.run(handler, **gen_params) assert wrapper.data_file['dirs'].shape == (initials, reps, int(tmax)) np.testing.assert_array_almost_equal( wrapper.data_file['dirs'][:, :, -1].flatten(), [6.210974216461182, 396.7076110839844])
def test_simtype_bump(): """Test the SimBump simtype""" session, net = tools.db.get_network(45) # get meanfield handler (abstracts network parameter handling) and set connectivity parameter handler = erfs.MeanfieldHandler(net) # get simulation type btype = session.query(cb.SimType).filter(cb.SimType.name == "bump").one() # get simulation wrapper # set to_memory = False to save simulation to hdf5 file wrapper = btype.get_wrapper(to_memory=True, session=session) tmax = 2000. # parameters used for this example gen_params = { # noise parameters mpr.EL_NOISE: 0., mpr.P_EE: 1., # 1mV of noise on the leak reversal potentials mpr.W_NOISE: 0., # run parameters "cores": 4, # cores to use for sim "tmax": tmax, # runtime "base_seed": 1, # seed for connectivity noise "base_seed_run": 1, # seed for run noise "sig_center": 0.3, # center of signal } # run the simulation wrapper.run(handler, **gen_params) assert wrapper.data_file['dirs'].shape == (int(tmax),) np.testing.assert_almost_equal( wrapper.data_file['dirs'][-1], 239.6555633544922)
import matplotlib.pyplot as pl import classes.base as cb import meanfield.error_functions as erfs import tools.db from classes.static import MeanfieldParameters as mpr # to show all network ids: tools.db.print_networks() session, net = tools.db.get_network(48) # get meanfield handler (abstracts network parameter handling) and set connectivity parameter handler = erfs.MeanfieldHandler(net) # get simulation type btype = session.query(cb.SimType).filter(cb.SimType.name == "bump").one() # get simulation wrapper # set to_memory = False to save simulation to hdf5 file wrapper = btype.get_wrapper(to_memory=True, session=session) # parameters for simulation sim_params = { "cores": 4, # cores to use for sim "sig_center": 0.3, # center of signal "tmax": 8000., # runtime "base_seed": 1, # seed for connectivity noise "base_seed_run": 1, # seed for run noise # network noise parameters mpr.W_NOISE: 0., # sigma_w mpr.EL_NOISE: 0., # = sigma_L mpr.P_EE: 0.5, # recurrent connectivity p