5 · A parameter sweep¶
How much background input does the toy network model need to fire? Run it for several values of one number and plot the rates, in Python. About five minutes.
Open this notebook in your project folder, the one with configs/ (tutorial 1): download it with the button at the top of this page, then start jupyter lab there.
The sweep¶
A plain loop. Each value gets a network model folder of its own, a copy of the toy with one number changed, as in tutorial 2, so every network you ran stays a folder you can open and run again.
Copied!
import shutil
from pathlib import Path
import yaml
from microcircuit_lab import Simulation, read_run
from microcircuit_lab.analysis import compute_population_firing_rates
indegrees = [600, 700, 800, 900, 1000, 1100, 1200]
rates = {}
for indegree in indegrees:
# A copy of the toy with another indegree.
name = f"toy_indegree_{indegree}"
folder = Path("configs/network") / name
shutil.copytree("configs/network/toy", folder, dirs_exist_ok=True)
background_file = folder / "poisson_background.yaml"
background = yaml.safe_load(background_file.read_text())
for entry in background["poisson_background"].values():
entry["indegree"] = indegree
background_file.write_text(yaml.safe_dump(background, sort_keys=False))
# Run it with the toy's settings, and keep its mean rates.
simulation = Simulation.from_yaml(network_name=name, simulation_name="toy")
simulation.run()
rates[indegree] = compute_population_firing_rates(read_run(simulation.output_dir), begin=200.0)
import shutil
from pathlib import Path
import yaml
from microcircuit_lab import Simulation, read_run
from microcircuit_lab.analysis import compute_population_firing_rates
indegrees = [600, 700, 800, 900, 1000, 1100, 1200]
rates = {}
for indegree in indegrees:
# A copy of the toy with another indegree.
name = f"toy_indegree_{indegree}"
folder = Path("configs/network") / name
shutil.copytree("configs/network/toy", folder, dirs_exist_ok=True)
background_file = folder / "poisson_background.yaml"
background = yaml.safe_load(background_file.read_text())
for entry in background["poisson_background"].values():
entry["indegree"] = indegree
background_file.write_text(yaml.safe_dump(background, sort_keys=False))
# Run it with the toy's settings, and keep its mean rates.
simulation = Simulation.from_yaml(network_name=name, simulation_name="toy")
simulation.run()
rates[indegree] = compute_population_firing_rates(read_run(simulation.output_dir), begin=200.0)
yaml.safe_loadreads a YAML file as a plain dict; change a value, write it back.Simulation.from_yaml(...).run()ismicrocircuit-lab runin Python.compute_population_firing_ratesreads each run's spikes back from its run folder, leaving out the first 200 ms. The other measures and plots: Analysing a run.
The result¶
Copied!
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(4, 3))
for population in ["E", "I"]:
ax.plot(indegrees, [rates[k][population] for k in indegrees], "o-", label=population)
ax.set_xlabel("background indegree")
ax.set_ylabel("rate (spikes/s)")
ax.legend()
plt.show()
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(4, 3))
for population in ["E", "I"]:
ax.plot(indegrees, [rates[k][population] for k in indegrees], "o-", label=population)
ax.set_xlabel("background indegree")
ax.set_ylabel("rate (spikes/s)")
ax.legend()
plt.show()
Up to about 800 inputs the network stays silent; with a little more it fires, and the rate then grows fast with the drive. The toy's 1000 inputs give about 20 spikes/s.
- Every value left a network model folder,
configs/network/toy_indegree_<value>/, and a run folder inoutput/. - The same loop works as a script, from a terminal: the toy example has one,
experiments/toy/background_drive_sweep.py. - To sweep a setting instead (seed, duration): Running from a script.
Next: 6 · NEST and Brian2.