Skip to content

Commit

Permalink
doc updates [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Circle Ci committed Dec 12, 2024
1 parent 9898e4f commit 15e07b7
Show file tree
Hide file tree
Showing 85 changed files with 688 additions and 347 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport numpy as np\nfrom hnn_core.batch_simulate import BatchSimulate\nfrom hnn_core import jones_2009_model\n\n# The number of cores may need modifying depending on your current machine.\nn_jobs = 10"
"import matplotlib.pyplot as plt\nimport numpy as np\nfrom hnn_core.batch_simulate import BatchSimulate\nfrom hnn_core import jones_2009_model\n\n# The number of cores may need modifying depending on your current machine.\nn_jobs = 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `add_evoked_drive` function simulates external input to the network,\nmimicking sensory stimulation or other external events.\n\n- `evprox` indicates a proximal drive, targeting dendrites near the cell\n bodies.\n- `mu=40` and `sigma=5` define the timing (mean and spread) of the input.\n- `weights_ampa` and `synaptic_delays` control the strength and\n timing of the input.\n\nThis evoked drive causes the initial positive deflection in the dipole\nsignal, triggering a cascade of activity through the network and\nresulting in the complex waveforms observed.\n\n"
]
},
{
Expand All @@ -55,14 +62,14 @@
},
"outputs": [],
"source": [
"def set_params(param_values, net=None):\n \"\"\"\n Set parameters in the network drives.\n\n Parameters\n ----------\n param_values : dict\n Dictionary of parameter values.\n net : instance of Network, optional\n If None, a new network is created using the specified model type.\n \"\"\"\n weights_ampa = {'L2_basket': param_values['weight_basket'],\n 'L2_pyramidal': param_values['weight_pyr'],\n 'L5_basket': param_values['weight_basket'],\n 'L5_pyramidal': param_values['weight_pyr']}\n\n synaptic_delays = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,\n 'L5_basket': 1., 'L5_pyramidal': 1.}\n\n # Add an evoked drive to the network.\n net.add_evoked_drive('evprox',\n mu=40,\n sigma=5,\n numspikes=1,\n location='proximal',\n weights_ampa=weights_ampa,\n synaptic_delays=synaptic_delays)"
"def set_params(param_values, net=None):\n \"\"\"\n Set parameters for the network drives.\n\n Parameters\n ----------\n param_values : dict\n Dictionary of parameter values.\n net : instance of Network, optional\n If None, a new network is created using the specified model type.\n \"\"\"\n weights_ampa = {'L2_basket': param_values['weight_basket'],\n 'L2_pyramidal': param_values['weight_pyr'],\n 'L5_basket': param_values['weight_basket'],\n 'L5_pyramidal': param_values['weight_pyr']}\n\n synaptic_delays = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,\n 'L5_basket': 1., 'L5_pyramidal': 1.}\n\n # Add an evoked drive to the network.\n net.add_evoked_drive('evprox',\n mu=40,\n sigma=5,\n numspikes=1,\n location='proximal',\n weights_ampa=weights_ampa,\n synaptic_delays=synaptic_delays)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define a parameter grid for the batch simulation.\n\n"
"Next, we define a parameter grid for the batch simulation.\n\n"
]
},
{
Expand All @@ -73,14 +80,14 @@
},
"outputs": [],
"source": [
"param_grid = {\n 'weight_basket': np.logspace(-4 - 1, 10),\n 'weight_pyr': np.logspace(-4, -1, 10)\n}"
"param_grid = {\n 'weight_basket': np.logspace(-4, -1, 20),\n 'weight_pyr': np.logspace(-4, -1, 20)\n}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define a function to calculate summary statistics\n\n"
"We then define a function to calculate summary statistics.\n\n"
]
},
{
Expand Down Expand Up @@ -109,14 +116,14 @@
},
"outputs": [],
"source": [
"# Comment off this code, if dask and distributed Python packages are installed\n# from dask.distributed import Client\n# client = Client(threads_per_worker=1, n_workers=5, processes=False)\n\n\n# Run the batch simulation and collect the results.\nnet = jones_2009_model(mesh_shape=(3, 3))\nbatch_simulation = BatchSimulate(net=net,\n set_params=set_params,\n summary_func=summary_func)\nsimulation_results = batch_simulation.run(param_grid,\n n_jobs=n_jobs,\n combinations=False,\n backend='multiprocessing')\n# backend='dask' if installed\nprint(\"Simulation results:\", simulation_results)"
"# Initialize the network model and run the batch simulation.\nnet = jones_2009_model(mesh_shape=(3, 3))\nbatch_simulation = BatchSimulate(net=net,\n set_params=set_params,\n summary_func=summary_func)\nsimulation_results = batch_simulation.run(param_grid,\n n_jobs=n_jobs,\n combinations=False,\n backend='loky')\n\nprint(\"Simulation results:\", simulation_results)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This plot shows an overlay of all smoothed dipole waveforms from the\nbatch simulation. Each line represents a different set of parameters,\nallowing us to visualize the range of responses across the parameter space.\n\n"
"This plot shows an overlay of all smoothed dipole waveforms from the\nbatch simulation. Each line represents a different set of synaptic strength\nparameters (`weight_basket`), allowing us to visualize the range of responses\nacross the parameter space.\nThe colormap represents synaptic strengths, from weaker (purple)\nto stronger (yellow).\n\nAs drive strength increases, dipole responses show progressively larger\namplitudes and more distinct features, reflecting heightened network\nactivity. Weak drives (purple lines) produce smaller amplitude signals with\nsimpler waveforms, while stronger drives (yellow lines) generate\nlarger responses with more pronounced oscillatory features, indicating\nmore robust network activity.\n\nThe y-axis represents dipole amplitude in nAm (nanoAmpere-meters), which is\nthe product of current flow and distance in the neural tissue.\n\nStronger synaptic connections (yellow lines) generally show larger\namplitude responses and more pronounced features throughout the simulation.\n\n"
]
},
{
Expand All @@ -127,7 +134,7 @@
},
"outputs": [],
"source": [
"dpl_waveforms = []\nfor data_list in simulation_results['simulated_data']:\n for data in data_list:\n dpl_smooth = data['dpl'][0].copy().smooth(window_len=30)\n dpl_waveforms.append(dpl_smooth.data['agg'])\n\nplt.figure(figsize=(10, 6))\nfor waveform in dpl_waveforms:\n plt.plot(waveform, alpha=0.5, linewidth=3)\nplt.title('Overlay of Dipole Waveforms')\nplt.xlabel('Time (ms)')\nplt.ylabel('Dipole Amplitude (nAm)')\nplt.grid(True)\nplt.tight_layout()\nplt.show()"
"dpl_waveforms, param_values = [], []\nfor data_list in simulation_results['simulated_data']:\n for data in data_list:\n dpl_smooth = data['dpl'][0].copy().smooth(window_len=30)\n dpl_waveforms.append(dpl_smooth.data['agg'])\n param_values.append(data['param_values']['weight_basket'])\n\nplt.figure(figsize=(10, 6))\ncmap = plt.get_cmap('viridis')\nlog_param_values = np.log10(param_values)\nnorm = plt.Normalize(log_param_values.min(), log_param_values.max())\n\nfor waveform, log_param in zip(dpl_waveforms, log_param_values):\n color = cmap(norm(log_param))\n plt.plot(waveform, color=color, alpha=0.7, linewidth=2)\nplt.title('Overlay of Dipole Waveforms')\nplt.xlabel('Time (ms)')\nplt.ylabel('Dipole Amplitude (nAm)')\nplt.grid(True)\nplt.tight_layout()\nplt.show()"
]
},
{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@
from hnn_core import jones_2009_model

# The number of cores may need modifying depending on your current machine.
n_jobs = 10
n_jobs = 4
###############################################################################
# The `add_evoked_drive` function simulates external input to the network,
# mimicking sensory stimulation or other external events.
#
# - `evprox` indicates a proximal drive, targeting dendrites near the cell
# bodies.
# - `mu=40` and `sigma=5` define the timing (mean and spread) of the input.
# - `weights_ampa` and `synaptic_delays` control the strength and
# timing of the input.
#
# This evoked drive causes the initial positive deflection in the dipole
# signal, triggering a cascade of activity through the network and
# resulting in the complex waveforms observed.


def set_params(param_values, net=None):
"""
Set parameters in the network drives.
Set parameters for the network drives.
Parameters
----------
Expand All @@ -57,16 +69,16 @@ def set_params(param_values, net=None):
synaptic_delays=synaptic_delays)

###############################################################################
# Define a parameter grid for the batch simulation.
# Next, we define a parameter grid for the batch simulation.


param_grid = {
'weight_basket': np.logspace(-4 - 1, 10),
'weight_pyr': np.logspace(-4, -1, 10)
'weight_basket': np.logspace(-4, -1, 20),
'weight_pyr': np.logspace(-4, -1, 20)
}

###############################################################################
# Define a function to calculate summary statistics
# We then define a function to calculate summary statistics.


def summary_func(results):
Expand Down Expand Up @@ -95,36 +107,54 @@ def summary_func(results):
###############################################################################
# Run the batch simulation and collect the results.

# Comment off this code, if dask and distributed Python packages are installed
# from dask.distributed import Client
# client = Client(threads_per_worker=1, n_workers=5, processes=False)


# Run the batch simulation and collect the results.
# Initialize the network model and run the batch simulation.
net = jones_2009_model(mesh_shape=(3, 3))
batch_simulation = BatchSimulate(net=net,
set_params=set_params,
summary_func=summary_func)
simulation_results = batch_simulation.run(param_grid,
n_jobs=n_jobs,
combinations=False,
backend='multiprocessing')
# backend='dask' if installed
backend='loky')

print("Simulation results:", simulation_results)
###############################################################################
# This plot shows an overlay of all smoothed dipole waveforms from the
# batch simulation. Each line represents a different set of parameters,
# allowing us to visualize the range of responses across the parameter space.
# batch simulation. Each line represents a different set of synaptic strength
# parameters (`weight_basket`), allowing us to visualize the range of responses
# across the parameter space.
# The colormap represents synaptic strengths, from weaker (purple)
# to stronger (yellow).
#
# As drive strength increases, dipole responses show progressively larger
# amplitudes and more distinct features, reflecting heightened network
# activity. Weak drives (purple lines) produce smaller amplitude signals with
# simpler waveforms, while stronger drives (yellow lines) generate
# larger responses with more pronounced oscillatory features, indicating
# more robust network activity.
#
# The y-axis represents dipole amplitude in nAm (nanoAmpere-meters), which is
# the product of current flow and distance in the neural tissue.
#
# Stronger synaptic connections (yellow lines) generally show larger
# amplitude responses and more pronounced features throughout the simulation.

dpl_waveforms = []
dpl_waveforms, param_values = [], []
for data_list in simulation_results['simulated_data']:
for data in data_list:
dpl_smooth = data['dpl'][0].copy().smooth(window_len=30)
dpl_waveforms.append(dpl_smooth.data['agg'])
param_values.append(data['param_values']['weight_basket'])

plt.figure(figsize=(10, 6))
for waveform in dpl_waveforms:
plt.plot(waveform, alpha=0.5, linewidth=3)
cmap = plt.get_cmap('viridis')
log_param_values = np.log10(param_values)
norm = plt.Normalize(log_param_values.min(), log_param_values.max())

for waveform, log_param in zip(dpl_waveforms, log_param_values):
color = cmap(norm(log_param))
plt.plot(waveform, color=color, alpha=0.7, linewidth=2)
plt.title('Overlay of Dipole Waveforms')
plt.xlabel('Time (ms)')
plt.ylabel('Dipole Amplitude (nAm)')
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified dev/_images/sphx_glr_plot_batch_simulate_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_batch_simulate_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_batch_simulate_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_connectivity_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_connectivity_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_connectivity_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_firing_pattern_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_firing_pattern_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_firing_pattern_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_beta_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_beta_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_beta_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_beta_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_gamma_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_gamma_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_gamma_006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_somato_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dev/_images/sphx_glr_plot_simulate_somato_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 15e07b7

Please sign in to comment.