cubnm.sim
Simulation of the model
Group of simulations that are executed in parallel |
|
Group of reduced Wong-Wang simulations (Deco 2014) |
|
Group of reduced Wong-Wang simulations (excitatory only, Deco 2013) |
- class cubnm.sim.SimGroup(duration, TR, sc_path, sc_dist_path=None, out_dir='same', ext_out=True, states_ts=False, states_sampling=None, window_size=10, window_step=2, rand_seed=410, exc_interhemispheric=True, force_cpu=False, force_gpu=False, serial_nodes=False, gof_terms=['+fc_corr', '-fc_diff', '-fcd_ks'], bw_params='friston2003', bold_remove_s=30, fcd_drop_edges=True, noise_segment_length=30, sim_verbose=False, progress_interval=500)
Group of simulations that are executed in parallel (as possible depending on the available hardware) on GPU/CPU.
Parameters
- duration:
float simulation duration (in seconds)
- TR:
float BOLD TR (in seconds)
- sc_path:
str path to structural connectome strengths (as an unlabled .txt) Shape: (nodes, nodes)
- sc_dist_path:
str, optional path to structural connectome distances (as an unlabled .txt) Shape: (nodes, nodes) If provided v (velocity) will be a free parameter and there will be delay in inter-regional connections
- out_dir: {‘same’ or
str}, optional ‘same’: will create a directory named based on sc_path
str: will create a directory in the provided path
- ext_out:
bool, optional return mean internal model variables to self.sim_states
- states_ts:
bool, optional return time series of model states to self.sim_states Note that this will increase the memory usage and is not recommended for large number of simulations (e.g. in a grid search)
- states_sampling:
float, optional sampling rate of model states in seconds. Default is None, which uses BOLD TR as the sampling rate.
- window_size:
int, optional dynamic FC window size (in TR)
- window_step:
int, optional dynamic FC window step (in TR)
- rand_seed:
int, optional seed used for the noise simulation
- exc_interhemispheric:
bool, optional excluded interhemispheric connections from sim FC and FCD calculations
- force_cpu:
bool, optional use CPU for the simulations (even if GPU is available). If set to False the program might use GPU or CPU depending on GPU availability
- force_gpu:
bool, optional on some HPC/HTC systems occasionally GPUtil might not detect an available GPU device. Use this if there is a GPU available but is not being used for the simulation. If set to True but a GPU is not available will lead to errors.
- serial_nodes:
bool, optional only applicable to GPUs; uses one thread per simulation and do calculation of nodes serially. This is an experimental feature which is generally not recommended and has significantly slower performance in typical use cases. Only may provide performance benefits with very large grids as computing time does not scale with the number of simulations as much as the parallel (default) mode.
- gof_terms:
listofstr, optional list of goodness-of-fit terms to be used for scoring. May include: - ‘-fcd_ks’: negative Kolmogorov-Smirnov distance of FCDs - ‘+fc_corr’: Pearson correlation of FCs - ‘-fc_diff’: negative absolute difference of FC means - ‘-fc_normec’: negative Euclidean distance of FCs divided by max EC [sqrt(n_pairs*4)]
- bw_params: {‘friston2003’ or ‘heinzle2016-3T’ or
dict}, optional see
cubnm.utils.get_bw_params()for details- bold_remove_s:
float, optional remove the first bold_remove_s seconds from the simulated BOLD in FC, FCD and mean state calculations (but the entire BOLD will be returned to .sim_bold)
- fcd_drop_edges:
bool, optional drop the edge windows in FCD calculations
- noise_segment_length:
floator None, optional in seconds, length of the noise segments in the simulations The noise segment will be repeated after shuffling of nodes and time points. To generate noise for the entire simulation without repetition, set this to None. Note that varying the noise segment length will result in a different noise array even if seed is fixed (but fixed combination of seed and noise_segment_length will result in reproducible noise)
- sim_verbose:
bool, optional verbose output of the simulation including details of simulations and a progress bar. This may slightly make the simulations slower.
- progress_interval:
int, optional msec; interval of progress updates in the simulation Only used if sim_verbose is True
Attributes
- param_lists:
dictofnp.ndarray - dictionary of parameter lists, including
global parameters with shape (N_SIMS,)
regional parameters with shape (N_SIMS, nodes)
‘v’: conduction velocity. Shape: (N_SIMS,)
- property N
- property bw_params
- property do_delay
- get_config(include_N=False, for_reinit=False)
Get the configuration of the simulation group
Parameters
- include_N:
bool, optional include N in the output config is ignored when for_reinit is True
- for_reinit:
bool, optional include the parameters that need reinitialization 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, optional 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:
- clear()
Clear the simulation outputs
- score(emp_fc_tril, emp_fcd_tril)
Calcualates individual goodness-of-fit terms and aggregates them.
Parameters
- emp_fc_tril:
np.ndarray 1D array of empirical FC lower triangle. Shape: (edges,)
- emp_fcd_tril:
np.ndarray 1D array of empirical FCD lower triangle. Shape: (window_pairs,)
Returns
- scores:
pd.DataFrame The goodness of fit measures (columns) of each simulation (rows)
- emp_fc_tril:
- duration:
- class cubnm.sim.rWWSimGroup(*args, do_fic=True, max_fic_trials=5, fic_penalty=True, **kwargs)
Bases:
SimGroupGroup of reduced Wong-Wang simulations (Deco 2014) that are executed in parallel
Parameters
- do_fic:
bool, optional do analytical-numerical Feedback Inhibition Control if provided wIE parameters will be ignored
- max_fic_trials:
int, optional maximum number of trials for FIC numerical adjustment
- fic_penalty:
bool, optional penalize deviation from FIC target mean rE of 3 Hz
- *args, **kwargs:
see
cubnm.sim.SimGroupfor details
Attributes
- param_lists:
dictofnp.ndarray - dictionary of parameter lists, including
‘G’: global coupling. Shape: (N_SIMS,)
‘wEE’: local excitatory self-connection strength. Shape: (N_SIMS, nodes)
‘wEI’: local inhibitory self-connection strength. Shape: (N_SIMS, nodes)
‘wIE’: local excitatory to inhibitory connection strength. Shape: (N_SIMS, nodes)
‘v’: conduction velocity. Shape: (N_SIMS,)
Example
To see example usage in grid search and evolutionary algorithms see
cubnm.optimize.Here, as an example on how to use SimGroup independently, we will run a single simulation and save the outputs to disk.
from cubnm import sim, datasets sim_group = sim.rWWSimGroup( duration=60, TR=1, sc_path=datasets.load_sc('strength', 'schaefer-100', return_path=True), ) sim_group.N = 1 sim_group.param_lists['G'] = np.array([0.5]) sim_group.param_lists['wEE'] = np.repeat(0.21, nodes*N_SIMS) sim_group.param_lists['wEI'] = np.repeat(0.15, nodes*N_SIMS) sim_group.run()
- model_name = 'rWW'
- global_param_names = ['G']
- regional_param_names = ['wEE', 'wEI', 'wIE']
- get_config(*args, **kwargs)
Get the configuration of the simulation group
Parameters
- include_N:
bool, optional include N in the output config is ignored when for_reinit is True
- for_reinit:
bool, optional include the parameters that need reinitialization if changed
Returns
- config:
dict dictionary of simulation group configuration
- include_N:
- score(emp_fc_tril, emp_fcd_tril, fic_penalty_scale=2)
Calcualates individual goodness-of-fit terms and aggregates them. In FIC models also calculates fic_penalty.
Parameters
- emp_fc_tril:
np.ndarray 1D array of empirical FC lower triangle. Shape: (edges,)
- emp_fcd_tril:
np.ndarray 1D array of empirical FCD lower triangle. Shape: (window_pairs,)
- fic_penalty_scale:
float, optional scale of the FIC penalty term. Set to 0 to disable the FIC penalty term. Note that while it is included in the cost function of optimizer, it is not included in the aggregate GOF
Returns
- scores:
pd.DataFrame The goodness of fit measures (columns) of each simulation (rows)
- emp_fc_tril:
- clear()
Clear the simulation outputs
- do_fic:
- class cubnm.sim.rWWExSimGroup(*args, **kwargs)
Bases:
SimGroupGroup of reduced Wong-Wang simulations (excitatory only, Deco 2013) that are executed in parallel
Parameters
- *args, **kwargs:
see
cubnm.sim.SimGroupfor details
Attributes
- param_lists:
dictofnp.ndarray - dictionary of parameter lists, including
‘G’: global coupling. Shape: (N_SIMS,)
‘w’: local excitatory self-connection strength. Shape: (N_SIMS, nodes)
‘I0’: local external input current. Shape: (N_SIMS, nodes)
‘sigma’: local noise sigma. Shape: (N_SIMS, nodes)
‘v’: conduction velocity. Shape: (N_SIMS,)
Example
To see example usage in grid search and evolutionary algorithms see
cubnm.optimize.Here, as an example on how to use SimGroup independently, we will run a single simulation and save the outputs to disk.
from cubnm import sim, datasets sim_group = sim.rWWExSimGroup( duration=60, TR=1, sc_path=datasets.load_sc('strength', 'schaefer-100', return_path=True), ) sim_group.N = 1 sim_group.param_lists['G'] = np.array([0.5]) sim_group.param_lists['w'] = np.repeat(0.9, nodes*N_SIMS) sim_group.param_lists['I0'] = np.repeat(0.3, nodes*N_SIMS) sim_group.param_lists['sigma'] = np.repeat(0.001, nodes*N_SIMS) sim_group.run()
- model_name = 'rWWEx'
- global_param_names = ['G']
- regional_param_names = ['w', 'I0', 'sigma']
- clear()
Clear the simulation outputs