-
Notifications
You must be signed in to change notification settings - Fork 32
Combining models
DynaSim makes it easy to combine two or more existing DynaSim models. For instance, if you created a cortical model and someone else created a thalamic model, it is easy to combine them into a larger, thalamocortical model by concatenating their specifications and adding connections between their populations or compartments. This tutorial demonstrates how that can be achieved in DynaSim. The procedure is the same whether cells have one or more compartments and whether networks have one or more populations. This page demonstrates using the dsCombineSpecifications function to concatenate the specifications and adding connections between them either manually or using the dsApplyModifications function.
Contents:
- Method 1: manually add connections to specification structure
- Method 2: use
dsApplyModificationsto add connections - Specifying connectivity matrices
- Combining predefined model objects
Procedure: load two specifications and connect one or more populations (or compartments) in one specification to populations (or compartments) in the other specification.
This procedure can be used to combine any two models (e.g., networks, multi-compartment cells, point neurons, or any other models). It can be repeated any number of times to combine additional models into a single specification of a larger model.
Start with any two specifications. For instance,
s1=dsCheckSpecification('RS.pop'); % load RS specification from default DynaSim library
s2=dsCheckSpecification('FS.pop'); % load FS specification from default DynaSim library
Note: dsCheckSpecification is used here to load a demo specification from
the DynaSim library; it does not need to be used with user-defined
specifications stored in the variables s1 and s2.
The point neurons, multi-compartment cells, networks, or whatever is
specified in s1 and s2 can be combined into a new, larger model by
concatenating their specifications and adding connections between
populations or compartments specified in them.
s=dsCombineSpecifications(s1,s2); % concatenate specifications
s.connections(1).direction='RS->FS'; % note: "RS" and "FS" are population names in "RS.pop" and "FS.pop"
s.connections(1).mechanism_list={'iAMPA','iNMDA'}; % tip: see DynaSim/models for a list of mechanisms in the DynaSim library (e.g., iAMPA.mech, iNMDA.mech)
s.connections(2).direction='FS->RS';
s.connections(2).mechanism_list={'iGABAa'};
vary={'FS->RS.iGABAa','gGABAa',[0 1] % tip: enter "open iGABAa.mech" to see GABAa parameters
'RS->FS.iAMPA' ,'gAMPA' ,[0 1] % tip: enter "open iAMPA.mech" to see AMPA parameters
'RS->FS.iNMDA' ,'gNMDA' ,[0 20]};% tip: enter "open iNMDA.mech" to see NMDA parameters
simulator_options={'vary',vary,'tspan',[0 1000],'solver','rk1','dt',.01,'verbose_flag',1};
data=dsSimulate(s,simulator_options{:}); % run simulation
dsPlot(data,'plot_type','waveform'); % plot results
Using dsApplyModifications to add connections
s=dsCombineSpecifications(s1,s2); % concatenate specifications
s=dsApplyModifications(s,{'RS->FS','mechanism_list','+(iAMPA,iNMDA)'}); % add AMPA and NMDA synapses from RS to FS
s=dsApplyModifications(s,{'FS->RS','mechanism_list','+iGABAa'}); % add GABAa synapse from FS to RS
data=dsSimulate(s,simulator_options{:}); % run simulation
dsPlot(data,'plot_type','waveform'); % waveform plots
dsPlot(data,'plot_type','raster'); % raster plots
In the above examples, each specification contains a point neuron model.
However, the same approach will work using any two specifications. For
instance, if s1 specifies a thalamic model, and s2 specifies a
cortical model, then a thalamo-cortical model can be created by following
the same procedure, substituting the names of populations and choosing
the desired connection mechanisms. For Method 1 (Manually adding connections), the index into the
connections field will need to be incremented to introduce new elements
if any connections (e.g., between populations or compartments) already
exist in either s1 or s2.
For a more complex example using dsApplyModifications to connect two intra-laminar circuits with
multi-compartment neurons into a larger, inter-laminar network model, see:
https://github.com/jsherfey/PFC_models/blob/master/PFC_2layers.m
To construct a thalamo-cortical model, specifications from the following repositories could be similarly combined:
Tips for storing specifications to facilitate combination:
- Store specification in MAT file. e.g.) Given MAT file
thalamus.matwith DynaSim specificationspecfor a thalamic model:load('thalamus.mat'); s1=spec;. Note: Models saved using the DynaSim GUI will be stored in MAT files and can be used in a script with this method. - Create a function that defines and outputs the specification. e.g.) Given function
get_thalamus.mthat returns a DynaSim specification for a thalamic model:s1=get_thalamus. Given a second functionget_cortex.mthat specifies a cortical model, the two specifications can be concatenated usings=dsCombineSpecifications(get_thalamus,get_cortex)and connected manually or usingdsApplyModificationsas described above.
Other tips for working with predefined specifications using dsApplyModifications:
- Rename populations to avoid duplicate names. e.g.)
s=dsApplyModifications(s,{'RS','name','CtxRS'});
- Modify population size without indexing the specification. e.g.)
s=dsApplyModifications(s,{'RS','size',10});
- Modify parameters without indexing the specification. e.g.)
s=dsApplyModifications(s,{'RS','Cm',1.2});
- Remove mechanisms (e.g., remove the anomalous rectifier h-current from RS). e.g.)
s=dsApplyModifications(s,{'RS','mechanism_list','-iAR'});
Using connectivity matrices defined in script:
nRS=10; % # of RS cells
nFS=2; % # of FS cells
netcon=rand(nFS,nRS)<.5; % this can be any matrix with dimensions [N_pre x N_post]
s=dsApplyModifications(s,{'RS','size',nRS}); % set size of RS population
s=dsApplyModifications(s,{'FS','size',nFS}); % set size of FS population
s=dsApplyModifications(s,{'FS->RS','netcon',netcon}); % set connectivity matrix "netcon" from FS to RS cells
data=dsSimulate(s,simulator_options{:}); % run simulation
dsPlot(data,'plot_type','raster'); % plot results
Using expressions that evaluate to the appropriate connectivity matrix:
s=dsApplyModifications(s,{'FS->RS','netcon','rand(Npre,Npost)<.5'}); % set connectivity matrix "netcon"
data=dsSimulate(s,simulator_options{:}); % run simulation
dsPlot(data,'plot_type','raster'); % plot results
Both approaches are demonstrated in this specification of the pyramidal-interneuron gamma-rhythmic network.
Tips for efficient connectivity matrices:
- The fastest simulation with a custom connectivity matrix can be achieved by specifying the desired custom matrix within the connection mechanism *.mech file. This can be achieved in three ways:
- Specify the connectivity using built-in Matlab functions in a single line in the mechanism
file (e.g.,
netcon=rand(N_pre,N_post)<prob; prob=.5in a custom connection mechanismmyAMPA.mech) - Creating an external function (e.g.,
get_connectivity) that returns the desired connectivity matrix and using the output to define the connectivity matrix in the mechanism file (e.g.,netcon=get_connectivity(N_pre,N_post)inmyAMPA.mech) - Saving the matrix to a MAT file and using it to define connectivity in the mechanism
file (e.g.,
netcon=getfield(load('my_connectivity.mat','netcon'))inmyAMPA.mech). Note: the variablenetconcan be given any other name in the custommyAMPA.mechfile.
- Specify the connectivity using built-in Matlab functions in a single line in the mechanism
file (e.g.,
- In some cases, using sparse matrices can be more efficient. Sparse matrices will be used if
sparse_flagis set to1in the call todsSimulate.
-
Predefined mechanisms are stored in *.mech files (e.g., mech1.mech, mech2.mech) and include linkers that make their functions and state variables available for use in other mechanism and population equations. They can be specified using
spec.populations.equations='dX/dt=f(X,t); ...; {mech1,mech2,...}'orspec.populations.mechanism_list = {'mech1','mech2',...}. See the introduction to mechanisms and Using custom mechanisms for more details. -
Predefined populations of point neurons are stored in *.pop files (e.g., popX.pop) and are standalone population models. They can be specified in spec.populations.equations (e.g.,
spec.populations.equations='popX') or directly simulated (e.g.,dsPlot(dsSimulate('popX'))). See Using predefined populations for more details and examples. -
Predefined networks and multicompartment neurons are stored using functions (in *.m files) (e.g., net1.m, net2.m) that return specification structures, which also specify standalone models. They can be used the same way specification structures
s1ands2are used above. Examples:s=dsCombineSpecifications(net1,net2),dsPlot(dsSimulate(net1)),s1=dsApplyModifications(net1,{'object','key',value}).