teili.core package¶
Submodules¶
teili.core.groups module¶
Wrapper class for brian2 Group class.
Todo
Check if shared works for neuron as well.
- Raise error (understandable)
if addStateVariable is called before synapses are connected.
Find out, if it is possible to have delay as state variable for Connections.
Some functionality of the package is not compatible with subgroups yet.
- This: self.register_synapse = self.source.register_synapse is not ideal,
as it is not necessary to register a synapse for subgroups!
-
class
teili.core.groups.
Connections
(*args, **kw)[source]¶ Bases:
brian2.synapses.synapses.Synapses
,teili.core.groups.TeiliGroup
,brian2.core.names.Nameable
This class is a subclass of Synapses.
You can use it as a Synapses, and everything will be passed to Synapses. Alternatively, you can also pass an EquationBuilder object that has all keywords and parameters.
-
equation_builder
¶ Class which builds the synapse model.
- Type
teili
-
input_number
¶ Number of input to post synaptic neuron. This variable takes care of the summed issue present in brian2.
- Type
int
-
parameters
¶ Dictionary of parameter keys and values of the synapse model.
- Type
dict
-
verbose
¶ Flag to print more detail about synapse generation.
- Type
bool
-
__setattr__
(key, value)[source]¶ Function to set arguments to synapses
- Parameters
key (str) – Name of attribute to be set
value (TYPE) – Description
-
connect
(condition=None, i=None, j=None, p=1.0, n=1, skip_if_invalid=False, namespace=None, level=0, **Kwargs)[source]¶ Wrapper function to make synaptic connections among neurongroups.
- Parameters
condition (bool, str, optional) – A boolean or string expression that evaluates to a boolean. The expression can depend on indices i and j and on pre- and post-synaptic variables. Can be combined with arguments n, and p but not i or j.
i (int, str, optional) – Source neuron index.
j (int, str, optional) – Target neuron index.
p (float, optional) – Probability of connection.
n (int, optional) – The number of synapses to create per pre/post connection pair. Defaults to 1.
skip_if_invalid (bool, optional) – Flag to skip connection if invalid indices are given.
namespace (str, optional) – namespace of this synaptic connection.
level (int, optional) – Distance to the input layer needed for tags.
**Kwargs – Additional keyword arguments.
-
-
class
teili.core.groups.
Neurons
(*args, **kw)[source]¶ Bases:
brian2.groups.neurongroup.NeuronGroup
,teili.core.groups.TeiliGroup
This class is a subclass of NeuronGroup.
You can use it as a NeuronGroup, and everything will be passed to NeuronGroup. Alternatively, you can also pass an EquationBuilder object that has all keywords and parameters.
-
equation_builder
¶ Class which describes the neuron model equation and all properties and default parameters. See /model/builder/neuron_equation_builder.py and models/neuron_models.py.
- Type
TYPE
-
initialized
¶ Flag to register Neurons’ population with TeiliGroups.
- Type
bool
-
num_inputs
¶ Number of possible synaptic inputs. This overcomes the summed issue present in brian2.
- Type
int
-
num_synapses
¶ Number of synapses projecting to post-synaptic neuron group.
- Type
int
-
synapses_dict
¶ Dictionary with all synapse names and their respective synapse index.
- Type
dict
-
verbose
¶ Flag to print more details of neuron group generation.
- Type
bool
-
__getitem__
(item)[source]¶ Taken from brian2/brian2/groups/neurongroup.py
- Parameters
item (TYPE) – Description
- Returns
The respective neuron subgroup.
- Return type
- Raises
IndexError – Error that indicates that size of subgroup set by start and stop is out of bounds.
TypeError – Error to indicate that wrong syntax has been used.
-
__setattr__
(key, value)[source]¶ Set attribute method.
- Parameters
key (TYPE) – key of attribute to be set.
value (TYPE) – value of respective key to be set.
-
register_synapse
(synapsename)[source]¶ Registers a Synapse so we know the input number.
It counts all synapses connected with one neuron group.
- Raises
ValueError – If too many synapses project to a given post-synaptic neuron group this error is raised. You need to increae the number of inputs parameter.
- Parameters
synapsename (str) – Name of the synapse group to be registered.
- Returns
- dictionary with all synapse names and their respective
synapse index.
- Return type
dict
-
-
class
teili.core.groups.
TeiliGroup
(*args, **kw)[source]¶ Bases:
brian2.groups.group.Group
just a bunch of methods that are shared between neurons and connections class Group is already used by brian2.
-
standalone_params
¶ Dictionary of standalone parameters.
- Type
dict
-
standalone_vars
¶ List of standalone variables.
- Type
list
-
str_params
¶ Name of parameters to be updated.
- Type
dict
-
_add_mismatch_param
(param, std=0, lower=None, upper=None, seed=None)[source]¶ This function sets the input parameter (param) to a value (new_param) drawn from a normal distribution with standard deviation (std) expressed as a fraction of the current value (old_param).
- Parameters
param (str) – name of the parameter to which the mismatch has to be added
std (float) – normalized standard deviation, expressed as a fraction of the current parameter (e.g.: std = 0.1 means that the new value will be sampled from a normal distribution with standard deviation of 0.1*old_param, with old_value being the current value of the attribute param) (default: 0)
lower (float, optional) – lower bound for the parameter mismatch, expressed as a fraction of the standard deviation, see note below. (default: -1/std)
upper (float, optional) – upper bound for the parameter mismatch, expressed as a fraction of the standard deviation, see note below. (default: inf)
seed (int, optional) – seed value for the random generator. Set the seed if you want to make the mismatch values reproducible across simulations. (default: None)
- NOTE: the outuput value (new_param) is drawn from a Gaussian
distribution with parameters: mean: old_param standard deviation: std * old_param lower bound: lower * std * old_param + old_param (default: 0, i.e. lower = -1/std) upper bound: upper * std * old_param + old_param (default: inf)
using the function truncnorm. For details, see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.truncnorm.html
The seed will not work in standalone mode so far (TODO)
- Raises
NameError – if one of the specified parameters in the disctionary is not included in the model.
AttributeError – if the input parameter to be changed does not have units
UserWarning – if the lower bound is negative (i.e. if lower < -1/std) (e.g. if the specified parameter is a current, negative values are meaningless)
Example
Adding mismatch to Itau in a population of 100 DPI neurons using _add_mismatch_param(). >>> from teili.models.neuron_models import DPI >>> testNeurons = Neurons(100, equation_builder=DPI(num_inputs=2)) >>> testNeurons._add_mismatch_param(param=’Itau’, std=0.1)
This will truncate the distribution at 0, to prevent Itau to become negative.
To specify also the lower bound as 2 times the standard deviation: >>> testNeurons._add_mismatch_param(param=’Ith’,
std=0.1, lower=-2)
- TODO: Consider the mismatch for the parameter ‘Cm’ as a separate
case.
- TODO: Add UserWarning if mismatch has been added twice both in numpy
and standalone mode.
-
add_mismatch
(std_dict=None, seed=None, verbose=False)[source]¶ This function is a wrapper for the method _add_mismatch_param() to add mismatch to a dictionary of parameters specified in the input dictionary (std_dict). Mismatch is drawn from a Gaussian distribution with mean equal to the parameter’s current value.
If no dictionary is given, 20% mismatch is added to all the parameters of the model except variables specified in the no_mismatch_parameter file.
Note
if you want to specify also lower and upper bound of the mismatch distribution see _add_mismatch_param() which adds mismatch to a single parameter.
- Parameters
std_dict (dict, optional) – dictionary of parameter names as keys and standard deviation as values. Standard deviations are expressed as fraction of the current parameter value. If empty, 20% of missmatch will be added to all variables (example: if std_dict = {‘Itau’: 0.1}, the new parameter value will be sampled from a normal distribution with standard deviation of 0.1*old_param, with old_param being the old parameter value)
seed (int, optional) – seed value for the random generator. Set the seed if you want to make the mismatch values reproducible across simulations. The random generator state before calling this method will be restored after the call in order to avoid effects to the rest of your simulation (default = None)
Example
Adding mismatch to 100 DPI neurons.
First create the neuron population (this sets parameter default values): >>> from teili.models.neuron_models import DPI >>> testNeurons = Neurons(100, equation_builder=DPI(num_inputs=2))
Store the old values as array: >>> old_param_value = np.copy(getattr(testNeurons, ‘Itau’))
Add mismatch to the neuron Itau with a standard deviation of 10% of the current bias values: >>> testNeurons.add_mismatch({‘Itau’: 0.1})
-
add_state_variable
(name, unit=1, shared=False, constant=False, changeInStandalone=True)[source]¶ This method allows you to add a state variable.
Usually a state variable is defined in equations, that is changeable in standalone mode. If you pass a value, it will directly set it and decide based on that value, if the variable should be shared (scalar) or not (vector).
- Parameters
name (str) – Name of state variable.
unit (int, optional) – Unit of respective state variable.
shared (bool, optional) – Flag to indicate if state variable is shared.
constant (bool, optional) – Flag to indicate if state variable is constant.
changeInStandalone (bool, optional) – Flag to indicate if state variable should be subject to on-line change in cpp standalone mode.
-
add_subexpression
(name, dimensions, expr)[source]¶ This method allows you to add a subexpression (like a state variable but a string that can be evaluated over time) You can e.g. add a timedArray like that: >>> neuron_group.add_subexpression(‘I_arr’,nA.dim,’timed_array(t)’) (be aware, that you need to add a state variable I_arr first, that is somehow connected to other variables, so run_regularly may be an easier solution for your problem)
- Parameters
name (str) – name of the expression.
dimensions (brian2.units.fundamentalunits.Dimension) – dimension of the expression.
expr (str) – the expression.
-
get_params
(params=None, verbose=False)[source]¶ This function gets parameter values of neurons or synapses. In standalone mode, it only works after the simulation has been run.
- Parameters
params (list, optional) – list of parameters that should be retrieved. If params = None (default), a dictionary of all parameters with their current values is returned
- Returns
dictionary of parameters with their values
- Return type
dict
-
import_eq
(filename)[source]¶ Function to import pre-defined neuron/synapse models.
- Parameters
filename (str) – path/to/your/model.py Usually synapse models can be found in teiliApps/models/equations.
- Returns
- Dictionary keywords with all relevant
kwargs, to generate model.
- Return type
Dictionary
-
property
model
¶ This property allows the user to only show the model of a given member.
- Returns
Dictionary only containing model equations.
- Return type
dict
-
-
class
teili.core.groups.
TeiliSubgroup
(*args, **kw)[source]¶ Bases:
brian2.groups.subgroup.Subgroup
This helps to make Subgroups compatible, otherwise the same as Subgroup.
-
register_synapse
¶ Register a synapse group to TeiliGroup.
- Type
fct
-
property
num_synapses
¶ Property to overcome summed issue present in brian2.
- Returns
- Number of synapses that converge to the same
post-synaptic neuron group.
- Return type
int
-
-
teili.core.groups.
print_paramdict
(paramdict)[source]¶ This function prints a params dictionary for get and set_params.
- Parameters
paramdict (dict, required) – Parameter keys and values to be set.
-
teili.core.groups.
set_params
(briangroup, params, ndargs=None, raise_error=False, verbose=False)[source]¶ This function takes a params dictionary and sets the parameters of a briangroup.
- Parameters
brianggroup (brian2.groups.group, required) – Neuron or Synapsegroup to set parameters on.
params (dict, required) – Parameter keys and values to be set.
raise_error (boolean, optional) – determines if an error is raised if a parameter does not exist as a state variable of the group.
ndargs (dict, optional) – Addtional attribute arguments.
verbose (bool, optional) – Flag to get more details about parameter setting process. States are not printed in cpp standalone mode before the simulation has been run
teili.core.network module¶
Wrapper class for Network class of brian2.
This wrapper provides a more flexible interface, especially to change parameters on the fly after compilation
Todo
function that plots the whole network
-
class
teili.core.network.
TeiliNetwork
(*args, **kw)[source]¶ Bases:
brian2.core.network.Network
This is a subclass of brian2.Network.
This subclass does the same thing plus some additional methods for convenience and functionality to allow real time plotting and gui.
-
blocks
¶ Description
- Type
list
-
has_run
¶ Flag to indicate if network has been simulated already.
- Type
bool
-
standalone_params
¶ Dictionary of standalone parameters.
- Type
dict
-
thread
¶ Description
- Type
TYPE
-
add
(*objs)[source]¶ Does the same thing as Network.add (adding Groups to the Network)
It also adds the groups to a list for the parameter gui.
- Parameters
*objs – arguments (brian2 objects which should be added to the network).
-
add_standalone_params
(**params)[source]¶ Function to a add standalone parameter to the standaloneParam dict.
These parameters can be changed after building w/o recompiling the network.
- Parameters
**params (dict, required) – Dictionary with parameter to be added to standalone_params.
-
build
(report='stdout', report_period=10.0 * second, namespace=None, profile=True, level=0, recompile=False, standalone_params=None, clean=True, verbose=True)[source]¶ Building the network.
- Parameters
report (bool, optional) – Flag to provide more detailed information during run.
report_period (brian2.unit, optional) – How often should be reported (unit time).
namespace (None, optional) – Namespace containing all names of the network to be built.
profile (bool, optional) – Flag to enable profiling of the network in terms of execution time, resources etc. .
level (int, optional) – Description.
recompile (bool, optional) – Flag to indicate if network should rather be recompiled than used based on a prior build. Set this to False if you want to only change parameters rather than network topology.
standalone_params (dict, optional) – Dictionary with standalone parameters which should be changed.
clean (bool, optional) – Flag to clean-up standalone directory.
-
has_run
= False¶
-
property
neurongroups
¶ property to conveniently get all neurongroups in the network
- Returns
A dictionary of all neurongroups (e.g. for looping over them)
- Return type
dict
-
run
(duration=None, standalone_params={}, verbose=True, **kwargs)[source]¶ Wrapper function to simulate a network for the given duration.
Parameters which should be changeable, especially after cpp compilation, need to be provided to standalone_params.
- Parameters
duration (brain2.unit, optional) – Simulation time in s, i.e. 1000 * ms.
standalone_params (dict, optional) – Dictionary whose keys refer to parameters which should be changeable in cpp standalone mode.
verbose (bool, optional) – set to False if you don’t want the prints, it is set to True by default, as there are things that can go wrong during string replacement etc. so it is better to have a look manually.
**kwargs (optional) – Additional keyword arguments.
-
run_as_thread
(duration, **kwargs)[source]¶ Running network in a thread.
- Parameters
duration (brain2.unit, optional) – Simulation time in ms, i.e. 100 * ms.
**kwargs (optional) – Additional keyword arguments.
-
property
spikemonitors
¶ property to conveniently get all spikemonitors in the network
- Returns
A dictionary of all spike monitors (e.g. for looping over them)
- Return type
dict
-
property
statemonitors
¶ property to conveniently get all statemonitors in the network
- Returns
A dictionary of all statemonitors (e.g. for looping over them)
- Return type
dict
-
property
synapses
¶ property to conveniently get all synapses in the network
- Returns
A dictionary of all synapses (e.g. for looping over them).
- Return type
dict
-