cubnm.sim.wc¶
Group of Wilson-Cowan simulations that are executed in parallel. |
- class cubnm.sim.wc.WCSimGroup(*args, **kwargs)¶
Bases:
cubnm.sim.base.SimGroupGroup of Wilson-Cowan simulations that are executed in parallel.
Parameters¶
- *args, **kwargs:
see
cubnm.sim.base.SimGroupfor details
Attributes¶
- param_lists:
dictofnp.ndarray - dictionary of parameter lists, including
'G': global coupling strength. Shape: (N_SIMS,)'c_EE': local E to E coupling. Shape: (N_SIMS, nodes)'c_IE': local I to E coupling. Shape: (N_SIMS, nodes)'c_EI': local E to I coupling. Shape: (N_SIMS, nodes)'c_II': local I to I coupling. Shape: (N_SIMS, nodes)'P_E': excitatory background drive. Shape: (N_SIMS, nodes)'P_I': inhibitory background drive. Shape: (N_SIMS, nodes)'sigma_E': excitatory noise strength. Shape: (N_SIMS, nodes)'sigma_I': inhibitory noise strength. Shape: (N_SIMS, nodes)'v': conduction velocity. Shape: (N_SIMS,)
Equations¶
\[\begin{split}\begin{gather} \tau^E\dot{E_i} = -E + (1 - E) S^E[c^{EE} E_i - c^{IE}I_i + G \sum_j{C_{ij} E_j} + P_i^E] + \sigma_i^E\epsilon_i^E \\ \tau^I\dot{I_i} = -I + (1 - I) S^I[c^{EI} E_i - c^{II}I_i + P_i^I] + \sigma_i^I\epsilon_i^I, \text{where:} \\ S^E(x) = \frac{1}{1 + e^{-a^E(x - \mu^E)}} \\ S^I(x) = \frac{1}{1 + e^{-a^I(x - \mu^I)}} \\ \end{gather}\end{split}\]References¶
Wilson et al. 1972 Biophysical Journal (10.1016/S0006-3495(72)86068-5)
Papadopoulos et al. 2020 PLOS Computational Biology (10.1371/journal.pcbi.1008144)
- model_name = 'WC'¶
- global_param_names = ['G']¶
- regional_param_names = ['c_EE', 'c_IE', 'c_EI', 'c_II', 'P_E', 'P_I', 'sigma_E', 'sigma_I']¶
- state_names = ['E', 'I']¶
- sel_state_var = 'E'¶
- n_noise = 2¶
- default_params¶
- post_init()¶
Post-initilaization hook that normally does nothing, but can be overridden in derived classes to add custom post-initialization steps.
- _check_dt()¶
Check if integrations steps are valid
- _set_default_params(missing=True)¶
Set default parameters for the simulations.
Parameters¶
- missing:
bool, optional If True (default), only sets parameters that are currently None or have an incorrect length in self.param_lists. If False, always overwrites all listed defaults.
- missing:
- get_config(include_N=False, for_reinit=False)¶
Get the configuration of the simulation group
Parameters¶
- include_N:
bool include N in the output config is ignored when for_reinit is True
- for_reinit:
bool include the parameters that need reinitialization of the simulation core session if changed
Returns¶
- config:
dict dictionary of simulation group configuration
- include_N:
- run(force_reinit=False)¶
Run the simulations in parallel (as possible) on GPU/CPU through the
cubnm._core.run_simulations()function which runs compiled C++/CUDA code.Parameters¶
- force_reinit:
bool force reinitialization of the session. At the beginning of each session (when cubnm is imported) some variables are initialized on CPU/GPU and reused in every run. Set this to True if you want to reinitialize these variables. This is rarely needed.
- force_reinit:
- _process_out(out)¶
Assigns model outputs (as arrays) to object attributes with correct shapes, names and types.
Parameters¶
- out:
tuple output of
cubnm._core.run_simulationsfunction
Notes¶
The simulation outputs are assigned to the following object attributes:
- init_time:
float initialization time of the simulations
- init_time:
- run_time:
float run time of the simulations
- run_time:
- sim_bold:
np.ndarray simulated BOLD time series. Shape: (N_SIMS, duration/TR, nodes)
- sim_bold:
- sim_states:
dictofnp.ndarray simulated state variables with keys as state names and values as arrays with the shape (N_SIMS, nodes) when
states_tsis False, and (N_SIMS, duration/TR, nodes) whenstates_tsis True
- sim_states:
If
do_fcisTrue, additionally includes:- sim_fc_trils:
np.ndarray simulated FC lower triangle. Shape: (N_SIMS, n_pairs)
- sim_fc_trils:
If
do_fcdisTrue, additionally includes:- sim_fcd_trils:
np.ndarray simulated FCD lower triangle. Shape: (N_SIMS, n_window_pairs)
- sim_fcd_trils:
- out:
- get_state_averages()¶
Get the averages of state variables across time and nodes for each simulation.
Returns¶
- state_averages:
pd.DataFrame DataFrame of state averages with columns as state names and rows as simulations
- state_averages:
- get_noise()¶
Get the (recreated) noise time series. This requires recreation of the noise array if noise segmenting is on. Noise will be recreated based on shuffling indices of nodes and time steps, similar to how it is done in the core code.
Returns¶
- noise:
np.ndarray Noise segment array. Shape: (n_noise, nodes, bw_it, inner_it)
- noise:
- get_sim_fc(idx)¶
Get the simulated FC of a given simulation
idxas a square matrix.Parameters¶
- idx:
int index of the simulation to get the FC for
Returns¶
- fc:
np.ndarray simulated FC matrix of shape (nodes, nodes) for the simulation with index
idx
- idx:
- get_sim_fcd(idx)¶
Get the simulated FCD of a given simulation
idxas a square matrix.Parameters¶
- idx:
int index of the simulation to get the FC for
Returns¶
- fcd:
np.ndarray simulated FC matrix of shape (n_windows, n_windows) for the simulation with index
idx
- idx:
- slice(key, inplace=False)¶
Slice the simulation group to a single simulation
Parameters¶
- key:
int index of the simulation to slice
- inplace:
bool the object will be sliced in place and therefore the data of other simulations will be removed. Otherwise a new object copied from the current object will be returned.
Returns¶
- obj:
cubnm.sim.SimGroup sliced simulation group
- key:
- clear()¶
Clear the simulation outputs
- _problem_init(problem)¶
Extends BNMProblem initialization if needed. By default it doesn’t do anything.
Parameters¶
- problem:
cubnm.optimize.BNMProblem optimization problem object
- problem:
- _problem_evaluate(problem, X, out, *args, **kwargs)¶
Extends BNMProblem evaluation if needed. By default it doesn’t do anything.
Parameters¶
- X:
np.ndarray the normalized parameters of current population in range [0, 1]. Shape: (N, ndim)
- out:
dict the output dictionary to store the results with keys ‘F’ and ‘G’. Currently only ‘F’ (cost) is used.
- X:
- score(emp_fc_tril=None, emp_fcd_tril=None, emp_bold=None, force_cpu=False, usable_mem=None)¶
Calcualates individual goodness-of-fit terms and aggregates them.
Note
If emp_bold is provided, emp_fc_tril and emp_fcd_tril will be ignored.
Note
For each measure, if the value is NaN, it will be set to the “worst” possible value. NaNs may occur in simulated FCD or FC. For example, in the rWWEx model, when excitation is too high and noise is low, S and in turn BOLD in some areas may become saturated and show no variability. This can result in correlations of their BOLD signals with other nodes (within certain dynamic windows) being NaN.
Parameters¶
- emp_fc_tril:
np.ndarrayor None 1D array of empirical FC lower triangle. Shape: (edges,)
- emp_fcd_tril:
np.ndarrayor None 1D array of empirical FCD lower triangle. Shape: (window_pairs,)
- emp_bold:
np.ndarrayor None cleaned and parcellated empirical BOLD time series. Shape: (nodes, volumes) Motion outliers should either be excluded (not recommended as it disrupts the temporal structure) or replaced with zeros. If provided emp_fc_tril and emp_fcd_tril will be ignored.
- force_cpu:
bool force CPU for the calculations. Otherwise if GPU is available some of the scores (including “+fc_corr”, “-fcd_ks”) will be calculated on GPU.
- usable_mem:
int amount of available GPU memory to be used in bytes. If None, 80% of the free memory will be used.
Returns¶
- scores:
pd.DataFrame The goodness of fit measures (columns) of each simulation (rows)
- emp_fc_tril:
- _get_save_data()¶
Get the simulation outputs and parameters to be saved to disk
Returns¶
- out_data:
dict dictionary of simulation outputs and parameters
- out_data:
- save()¶
Save simulation outputs to disk as an npz file.
- classmethod _get_test_configs(cpu_gpu_identity=False)¶
Get configs for testing the simulations
Parameters¶
- cpu_gpu_identity:
bool indicates whether configs are for CPU/GPU identity tests in which case force_cpu is not included in the configs since tests will be done on both CPU and GPU
Returns¶
configs:
dictoflist- cpu_gpu_identity: