def _create_sim(self, integrator=None, inhom_mmpr=False, delays=False, run_sim=True): mpr = MontbrioPazoRoxin() conn = Connectivity.from_file() if inhom_mmpr: dispersion = 1 + np.random.randn(conn.weights.shape[0])*0.1 mpr = MontbrioPazoRoxin(eta=mpr.eta*dispersion) conn.speed = np.r_[3.0 if delays else np.inf] if integrator is None: dt = 0.01 integrator = EulerDeterministic(dt=dt) else: dt = integrator.dt sim = Simulator(connectivity=conn, model=mpr, integrator=integrator, monitors=[Raw()], simulation_length=0.1) # 10 steps sim.configure() if not delays: self.assertTrue((conn.idelays == 0).all()) buf = sim.history.buffer[...,0] # kernel has history in reverse order except 1st element 🤕 rbuf = np.concatenate((buf[0:1], buf[1:][::-1]), axis=0) state = np.transpose(rbuf, (1, 0, 2)).astype('f') self.assertEqual(state.shape[0], 2) self.assertEqual(state.shape[2], conn.weights.shape[0]) if isinstance(sim.integrator, IntegratorStochastic): sim.integrator.noise.reset_random_stream() if run_sim: (t,y), = sim.run() return sim, state, t, y else: return sim
def main_example(tvb_sim_model, connectivity_zip=CONFIGURED.DEFAULT_CONNECTIVITY_ZIP, dt=0.1, noise_strength=0.001, simulation_length=100.0, config=CONFIGURED): plotter = Plotter(config) # --------------------------------------1. Load TVB connectivity---------------------------------------------------- connectivity = Connectivity.from_file(connectivity_zip) connectivity.configure() plotter.plot_tvb_connectivity(connectivity) # ----------------------2. Define a TVB simulator (model, integrator, monitors...)---------------------------------- # Create a TVB simulator and set all desired inputs # (connectivity, model, surface, stimuli etc) # We choose all defaults in this example simulator = Simulator() simulator.integrator = HeunStochastic(dt=dt) simulator.integrator.noise.nsig = np.array(ensure_list(noise_strength)) simulator.model = tvb_sim_model simulator.connectivity = connectivity mon_raw = Raw(period=simulator.integrator.dt) simulator.monitors = (mon_raw, ) # -----------------------------------3. Simulate and gather results------------------------------------------------- # Configure the simulator with the TVB-NEST interface... # simulator.configure(tvb_nest_interface=tvb_nest_model) simulator.configure() # ...and simulate! t_start = time.time() results = simulator.run(simulation_length=simulation_length) print("\nSimulated in %f secs!" % (time.time() - t_start)) # -------------------------------------------6. Plot results-------------------------------------------------------- plot_results(results, simulator, None, "State Variables", simulator.model.variables_of_interest, plotter) return connectivity, results