teili.models.builder package

Submodules

teili.models.builder.combine module

This file contains a set of functions used by the library to combine models.

Combine_neu_dict is used for combining neuron models Combine_syn_dict is used for combining neuron models

Both functions use the var_replacer when the special overwrite character ‘%’ is found in the equations. If ‘%’ is found in the middle of the equation, like a modulo operation, substitutions are not performed.

Example

To use combine_neu_dict:

>>> from teili.models.builder.combine import combine_neu_dict
>>> combine_neu_dict(eq_templ, param_templ)

To use combine_syn_dict: >>> from teili.models.builder.combine import combine_syn_dict >>> combine_syn_dict(eq_templ, param_templ)

teili.models.builder.combine.combine_neu_dict(eq_templ, param_templ)[source]

Function to combine neuron models into a single neuron model.

This library offers this ability in order to combine single blocks into bigger and more complex Brian2 compatible models. combine_neu_dict also makes it possible to delete or overwrite an explicit function with the use of the special character ‘%’. .. rubric:: Example

Example with two different dictionaries both containing the explicit function for the variable ‘x’:

>>> x = theta
>>> %x = gamma
>>> x = gamma

‘%x’ without any assignment will simply delete the variable from the output and from the parameter dictionary.

To combine two dictionaries:

>>> combine_neu_dict(eq_templ, param_templ)
Parameters
  • eq_templ (dict) – Dictionary containing different keywords and equations

  • param_templ (dict) – Dictionary containing different parameters for the equation

Returns

[‘model’] Actually neuron model differential equation. dict: [‘threshold’] Dictionary with equations specifying behaviour of synapse to post-synaptic spike. dict: [‘reset’] Dictionary with equations specifying behaviour of synapse to pre-synaptic spike. dict: [‘parameters’] Dictionary of parameters.

Return type

dict

teili.models.builder.combine.combine_syn_dict(eq_templ, param_templ)[source]

Function to combine synapse models into a single synapse model.

This library offers this ability in order to combine single blocks into bigger and more complex Brian2 compatible models. combine_syn_dict also makes it possible to delete or overwrite an explicit function with the use of the special character ‘%’. Example with two different dictionaries both containing the explicit function for the variable ‘x’: .. rubric:: Example

Example with two different dictionaries both containing the explicit function for the variable ‘x’:

>>> x = theta
>>> %x = gamma
>>> x = gamma

‘%x’ without any assignment will simply delete the variable from the output and from the parameter dictionary.

To combine two dictionaries:

>>> combine_syn_dict(eq_templ, param_templ)
Parameters
  • eq_templ (dict) – Dictionary containing different keywords and equations.

  • param_templ (dict) – Dictionary containing different parameters for the equation.

Returns

[‘model’] Actually neuron model differential equation. dict: [‘on_post’] Dictionary with equations specifying behaviour of synapse to post-synaptic spike. dict: [‘on_pre’] Dictionary with equations specifying behaviour of synapse to pre-synaptic spike. dict: [‘parameters’] Dictionary of parameters.

Return type

dict

teili.models.builder.combine.var_replacer(first_eq, second_eq, params)[source]

Function to delete variables from equations and parameters.

It works with couples of strings and a dict of parameters: first_eq, second_eq and params It searches for every line in second_eq for the special character ‘%’ removing it, and then searching for the variable (even if in differential form ‘%dx/dt’) and erasing every line in first_eq starting with that variable (every explicit equation). If the character ‘=’ or ‘:’ is not in the line containing the variable in second_eq the entire line would be erased.

Parameters
  • first_eq (string) – The first subset of equations that we want to expand or overwrite.

  • second_eq (string) – The second subset of equations which will be added to first_eq. It also contains ‘%’ for overwriting or erasing lines in first_eq.

  • params (dict) – Dictionary of parameters to be replaced.

Returns

The first_eq string containing the replaced variable equations. result_second_eq: The second_eq string without the lines containing the special character ‘%’. params: The parameter dictionary not containing the removed/replaced variables.

Return type

result_first_eq

Examples

>>> '%x = theta' --> 'x = theta'
>>> '%x' --> ''

This feature allows to remove equations in the template that we don’t want to compute by writing ‘%[variable]’ in the other equation blocks.

To replace variables and lines:

>>> from teili.models.builder.combine import var_replacer
>>> var_replacer(first_eq, second_eq, params)

teili.models.builder.neuron_equation_builder module

This file contains a class that manages a neuron equation.

And it prepares a dictionary of keywords for easy synapse creation. It also provides a function to add lines to the model.

Example

To use the NeuronEquationBuilder “on the fly” you can initialize it as DPI neuron:

>>> from teili.models.builder.neuron_equation_builder import NeuronEquationBuilder
>>> num_inputs = 2
>>> my_neu_model = NeuronEquationBuilder.__init__(base_unit='current', adaptation='calcium_feedback',
                                   integration_mode='exponential', leak='leaky',
                                   position='spatial', noise='none')
>>> my_neuron.add_input_currents(num_inputs)

Or if you have a pre-defined neuron model you can import this dictionary as:

>>> from teili.models.builder.neuron_equation_builder import NeuronEquationBuilder
>>> my_neu_model = NeuronEquationBuilder.import_eq(
    '~/teiliApps/equations/DPI', num_inputs=2)

in both cases you can pass it to Neurons:

>>> from teili.core.groups import Neurons
>>> my_neuron = Neurons(2, equation_builder=my_neu_model, name="my_neuron")

Another way of using it is to import the DPI class directly:

>>> from teili.models.neuron_models import DPI
>>> from teili.core.groups import Neurons
>>> my_neuron = Neurons(2, equation_builder=DPI(num_inputs=2), name="my_neuron")
class teili.models.builder.neuron_equation_builder.NeuronEquationBuilder(keywords=None, base_unit='current', num_inputs=1, verbose=False, **kwargs)[source]

Bases: object

Class which builds neuron equation according to pre-defined properties such as spike-frequency adaptation, leakage etc.

keywords

Dictionary containing all relevant keywords and equations for brian2, such as model, refractory, reset, threshold and parameters.

Type

dict

num_inputs

Number specifying how many distinct neuron population project to the target neuron population.

Type

int

verbose

Flag to print more detailed output of neuron equation builder.

Type

bool

__call__(num_inputs)[source]

In the recommended way of using Neurons as provided bey teili the neuron model is imported from teili.models.neuron_models as properly initialised python object in which the number of incoming current, i.e. num_inputs, is set during the initialisation of the class. However, teili also supports to initialise the Equation_builder using a user-specified model without the need to implement the model directly in the existing software stack. This allows faster development time and mre flexibility as all functionality of teili is provided to user-specified models. This function allows the user to set the num_inputs argument to non-standard neuron model.

An usage example can be found in teiliApps/tutorials/neuron_synapse_builderobj_tutorial.py :param num_inputs: Number specifying how many distinct

neuron populations project to the target neuron population.

Returns

A deep copy of the NeuronEquationBuilder object.

Return type

NeuronEquationBuilder obj.

add_input_currents(num_inputs)[source]

Automatically adds the input current line according to num_inputs.

It also adds all these input currents as state variables.

Example

>>> Iin = Ie0 + Ii0 + Ie1 + Ii1 + ... + IeN + IiN (with N = num_inputs)
Parameters

num_inputs (int) – Number of inputs to the post-synaptic neuron

add_state_vars(stateVars)[source]

this function adds state variables to neuron equation by just adding a line to the neuron model equation.

Parameters

stateVars (dict) – State variable to be added to neuron model

export_eq(filename)[source]

Function to export generated neuron model to a file.

Parameters

filename (str) – Path/to/location/to/store/neuron_model.py.

classmethod import_eq(filename, num_inputs=1)[source]

Function to import pre-defined neuron_model.

num_inputs is used to add additional input currents that are used for different synapses that are summed.

Parameters
  • filename (str) – Path/to/location/where/model/is/stored/neuron_model.py.

  • num_inputs (int) – Number of inputs to the post-synaptic neuron.

Returns

Object containing keywords (dict) with all relevant

keys, to generate neuron_model.

Return type

NeuronEquationBuilder obj.

print_all()[source]

Method to print all dictionaries within a neuron model

teili.models.builder.neuron_equation_builder.print_neuron_model(Neuron_group)[source]

Function to print keywords of a Neuron model Usefull to check the entire equation and parameter list

Parameters

group (Neuron) – Synaptic group

NOTE: Even if mismatch is added, the values that are shown and not subject to mismatch

teili.models.builder.neuron_equation_builder.print_param_dictionaries(Dict)[source]

Function to print dictionaries of parameters in an ordered way.

Parameters

Dict (dict) – Parameter dictionary to be printed.

teili.models.builder.synapse_equation_builder module

This file contains a class that manages a synapse equation.

And it prepares a dictionary of keywords for easy synapse creation. It also provides a function to add lines to the model.

Example

To use the SynapseEquationBuilder “on the fly” you can initialize it as a DPI neuron:

>>> from teili.models.builder.synapse_equation_builder import SynapseEquationBuilder
>>> my_syn_model = SynapseEquationBuilder.__init__(base_unit='DPI',
                                                   plasticity='non_plastic')

Or if you have a pre-defined synapse model you can import this dictionary as follows:

>>> from teili.models.builder.synapse_equation_builder import SynapseEquationBuilder
>>> my_syn_model = SynapseEquationBuilder.import_eq(
    'teiliApps/equations/DPISyn')

In both cases you can pass it to Connections:

>>> from teili.core.groups import Connections
>>> my_synapse = Connections(testNeurons, testNeurons2,
                             equation_builder=DPISyn, name="my_synapse")

Another way of using it is to import the DPI class directly:

>>> from teili.models.synapse_models import DPISyn
>>> from teili.core.groups import Connections
>>> my_synapse = Connections(testNeurons, testNeurons2,
              equation_builder=DPISyn, name="my_synapse")
class teili.models.builder.synapse_equation_builder.SynapseEquationBuilder(keywords=None, base_unit='current', verbose=False, **kwargs)[source]

Bases: object

Class which builds synapse equation.

keywords

Dictionary containing all relevant keywords and equations for brian2, such as model, on_post, on_pre and parameters

Type

dict

keywords_original

Dictionary containing all needed keywords for equation builder.

Type

dict

verbose

Flag to print more detailed output of neuron equation builder.

Type

bool

__call__()[source]

This allows the user to call the object like a class in order to make new objects.

Maybe this use is a bit confusing, so rather not use it.

Returns

A deep copy of the SynapseEquationBuilder object.

Return type

SynapseEquationBuilder obj.

export_eq(filename)[source]

Function to export generated neuron model to a file.

Parameters

filename (str) – path/where/you/store/your/model.py Usually synapse models are stored in teili/models/equations

classmethod import_eq(filename)[source]

Function to import pre-defined synapse_model.

Parameters

filename (str) – path/to/your/synapse/model.py Usually synapse models can be found in teili/models/equations.

Returns

Object containing keywords (dict) with all relevant

keys, to generate synapse_model.

Return type

SynapseEquationBuilder obj.

Examples

synapse_object = SynapseEquationBuilder.import_eq(

‘teili/models/equations/DPISyn’)

print_all()[source]

Method to print all dictionaries within a synapse model

set_input_number(input_number)[source]

Sets the input number of synapse.

This is needed to overcome the summed issue in brian2.

Parameters

input_number (int) – Synapse’s input number

teili.models.builder.synapse_equation_builder.print_param_dictionaries(Dict)[source]

Function to print dictionaries of parameters in an ordered way.

Parameters

Dict (dict) – Parameter dictionary to be printed.

teili.models.builder.synapse_equation_builder.print_synaptic_model(synapse_group)[source]
Function to print keywords of a synaptic model

Usefull to check the entire equation and parameter list

Args:

Synaptic group( Connections ) : Synaptic group

Note: Even if mismatch is added, the values that are shown and not subject

to mismatch

Module contents