-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
23 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
""" | ||
==================== | ||
06. Batch Simulation | ||
07. Batch Simulation | ||
==================== | ||
This example shows how to do batch simulations in HNN-core, allowing users to | ||
|
@@ -13,17 +13,17 @@ | |
# Ryan Thorpe <[email protected]> | ||
# Mainak Jas <[email protected]> | ||
|
||
############################################################################# | ||
# Let us import hnn_core. | ||
############################################################################### | ||
# Let us import ``hnn_core``. | ||
|
||
import hnn_core | ||
import numpy as np | ||
from hnn_core import BatchSimulate | ||
from hnn_core.batch_simulate import BatchSimulate | ||
from hnn_core import jones_2009_model | ||
|
||
# The number of cores may need modifying depending on your current machine. | ||
n_jobs = 10 | ||
########################################################################### | ||
############################################################################### | ||
|
||
|
||
def set_params(param_values, net=None): | ||
|
@@ -57,7 +57,8 @@ def set_params(param_values, net=None): | |
weights_ampa=weights_ampa, | ||
synaptic_delays=synaptic_delays) | ||
|
||
########################################################################### | ||
############################################################################### | ||
# Define a parameter grid for the batch simulation. | ||
|
||
|
||
param_grid = { | ||
|
@@ -67,6 +68,9 @@ def set_params(param_values, net=None): | |
'sigma': np.linspace(1, 20, 5) | ||
} | ||
|
||
############################################################################### | ||
# Run the batch simulation and collect the results. | ||
|
||
batch_simulation = BatchSimulate(set_params=set_params) | ||
simulation_results = batch_simulation.run(param_grid, | ||
n_jobs=n_jobs, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Batch simulation.""" | ||
"""Batch Simulation.""" | ||
|
||
# Authors: Abdul Samad Siddiqui <[email protected]> | ||
# Nick Tolley <[email protected]> | ||
|
@@ -8,21 +8,24 @@ | |
from joblib import Parallel, delayed | ||
from .dipole import simulate_dipole | ||
from .network_models import (jones_2009_model, | ||
calcium_model, law_2021_model) | ||
calcium_model, law_2021_model) | ||
|
||
|
||
class BatchSimulate: | ||
def __init__(self, set_params, net_name='jones', tstop=170, | ||
dt=0.025, n_trials=1, record_vsec=False, | ||
record_isec=False, postproc=False): | ||
""" | ||
Initialize the BatchSimulate class. | ||
"""Initialize the BatchSimulate class. | ||
Parameters | ||
---------- | ||
set_params : func | ||
User-defined function that sets parameters in network drives. | ||
`set_params(net, params) -> None` | ||
``set_params(net, params) -> None`` | ||
where ``net`` is a Network object and ``params`` is a dictionary | ||
of the parameters that will be set inside the function. | ||
net_name : str | ||
The name of the network model to use. Default is `jones`. | ||
tstop : float, optional | ||
|
@@ -59,8 +62,7 @@ def __init__(self, set_params, net_name='jones', tstop=170, | |
self.postproc = postproc | ||
|
||
def run(self, param_grid, return_output=True, combinations=True, n_jobs=1): | ||
""" | ||
Run batch simulations. | ||
"""Run batch simulations. | ||
Parameters | ||
---------- | ||
|
@@ -88,8 +90,7 @@ def run(self, param_grid, return_output=True, combinations=True, n_jobs=1): | |
return results | ||
|
||
def simulate_batch(self, param_combinations, n_jobs=1): | ||
""" | ||
Simulate a batch of parameter sets in parallel. | ||
"""Simulate a batch of parameter sets in parallel. | ||
Parameters | ||
---------- | ||
|
@@ -113,8 +114,7 @@ def simulate_batch(self, param_combinations, n_jobs=1): | |
return res | ||
|
||
def _run_single_sim(self, param_values): | ||
""" | ||
Run a single simulation. | ||
"""Run a single simulation. | ||
Parameters | ||
---------- | ||
|
@@ -154,8 +154,7 @@ def _run_single_sim(self, param_values): | |
return {'net': net, 'dpl': dpl, 'param_values': param_values} | ||
|
||
def _generate_param_combinations(self, param_grid, combinations=True): | ||
""" | ||
Generate combinations of parameters from the grid. | ||
"""Generate combinations of parameters from the grid. | ||
Parameters | ||
---------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters