Skip to content

Dendrite#

A Dendrite is a sub-group of a Projection, gathering the synapses between the pre-synaptic population and a single post-synaptic neuron.

ANNarchy.core.Dendrite.Dendrite #

Bases: object

A Dendrite is a sub-group of a Projection, gathering the synapses between the pre-synaptic population and a single post-synaptic neuron.

It can not be created directly, only through a call to Projection.dendrite(rank):

dendrite = proj.dendrite(6)
Source code in /home/docs/checkouts/readthedocs.org/user_builds/annarchy/conda/latest/lib/python3.9/site-packages/ANNarchy/core/Dendrite.py
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
class Dendrite(object):
    """
    A ``Dendrite`` is a sub-group of a ``Projection``, gathering the synapses between the pre-synaptic population and a single post-synaptic neuron.

    It can not be created directly, only through a call to ``Projection.dendrite(rank)``:

    ```python
    dendrite = proj.dendrite(6)
    ```
    """
    def __init__(self, proj, post_rank, idx):

        self.post_rank = post_rank
        self.idx = idx
        self.proj = proj
        self.pre = proj.pre

        self.target = self.proj.target

        self.attributes = self.proj.attributes
        self.parameters = self.proj.parameters
        self.variables = self.proj.variables

    @property
    def size(self):
        """
        Number of synapses.
        """
        if self.proj.cyInstance:
            return self.proj.cyInstance.dendrite_size(self.idx)
        return 0

    @property
    def pre_ranks(self):
        """
        List of ranks of pre-synaptic neurons.
        """
        if self.proj.cyInstance:
            return self.proj.cyInstance.pre_rank(self.idx)
        return []

    def __len__(self):
        # Number of synapses.

        return self.size

    @property
    def synapses(self):
        """
        Iteratively returns the synapses corresponding to this dendrite.
        """
        for n in self.pre_ranks:
            yield IndividualSynapse(self, n)

    def synapse(self, pos):
        """
        Returns the synapse coming from the corresponding presynaptic neuron.

        :param pos: can be either the rank or the coordinates of the presynaptic neuron
        """
        if isinstance(pos, int):
            rank = pos
        else:
            rank = self.proj.pre.rank_from_coordinates(pos)

        if rank in self.pre_ranks:
            return IndividualSynapse(self, rank)
        else:
            Global._error(" The neuron of rank "+ str(rank) + " has no synapse in this dendrite.")
            return None

    # Iterators
    def __getitem__(self, *args, **kwds):
        # Returns the synapse of the given position in the presynaptic population.
        # If only one argument is given, it is a rank. If it is a tuple, it is coordinates.

        if len(args) == 1:
            return self.synapse(args[0])
        return self.synapse(args)

    def __iter__(self):
        # Returns iteratively each synapse in the dendrite in ascending pre-synaptic rank order.
        for n in self.pre_ranks:
            yield IndividualSynapse(self, n)

    #########################
    ### Access to attributes
    #########################
    def __getattr__(self, name):
        # Method called when accessing an attribute.
        if name == 'proj':
            return object.__getattribute__(self, name)
        elif hasattr(self, 'proj'):
            if name == 'rank': # TODO: remove 'rank' in a future version
                Global._warning("Dendrite.rank: the attribute is deprecated, use Dendrite.pre_ranks instead.")
                return self.proj.cyInstance.pre_rank(self.idx)

            elif name == 'pre_rank':
                return self.proj.cyInstance.pre_rank(self.idx)

            elif name == 'delay':
                if self.proj.uniform_delay == -1:
                    return [d*Global.config['dt'] for d in self.proj.cyInstance.get_dendrite_delay(self.idx)]
                else:
                    return self.proj.max_delay * Global.config['dt']

            elif name == "w" and self.proj._has_single_weight():
                return self.proj.cyInstance.get_global_attribute(name, Global.config["precision"])

            elif name in self.proj.attributes:
                # Determine C++ data type
                ctype = None
                for var in self.proj.synapse_type.description['variables']+self.proj.synapse_type.description['parameters']:
                    if var['name'] == name:
                        ctype = var['ctype']

                if name in self.proj.synapse_type.description['local']:
                    return self.proj.cyInstance.get_local_attribute_row(name, self.idx, ctype)
                elif name in self.proj.synapse_type.description['semiglobal']:
                    return self.proj.cyInstance.get_semiglobal_attribute(name, self.idx, ctype)
                else:
                    return self.proj.cyInstance.get_global_attribute(name, ctype)
            else:
                return object.__getattribute__(self, name)
        else:
            return object.__getattribute__(self, name)

    def __setattr__(self, name, value):
        # Method called when setting an attribute.
        if name == 'proj':
            object.__setattr__(self, 'proj', value)
        elif name == 'attributes':
            object.__setattr__(self, 'attributes', value)
        elif hasattr(self, 'proj'):
            if name in self.proj.attributes:
                # Determine C++ data type
                ctype = None
                for var in self.proj.synapse_type.description['variables']+self.proj.synapse_type.description['parameters']:
                    if var['name'] == name:
                        ctype = var['ctype']

                if name in self.proj.synapse_type.description['local']:
                    if isinstance(value, (np.ndarray, list)):
                        self.proj.cyInstance.set_local_attribute_row(name, self.idx, value, ctype)
                    else:
                        self.proj.cyInstance.set_local_attribute_row(name, self.idx, value * np.ones(self.size), ctype)

                elif name in self.proj.synapse_type.description['semiglobal']:
                    self.proj.cyInstance.set_semiglobal_attribute(name, self.idx, value, ctype)

                else:
                    raise Global._error("Projection attributes marked as *projection* should not be updated through dendrites.")
            else:
                object.__setattr__(self, name, value)
        else:
            object.__setattr__(self, name, value)

    def set(self, value):
        """
        Sets the value of a parameter/variable of all synapses.

        Example:

        ```python
        dendrite.set( { 'tau' : 20, 'w'= Uniform(0.0, 1.0) } )
        ```

        :param value: a dictionary containing the parameter/variable names as keys.
        """
        for key, value in value.items():
            # sanity check and then forward to __setattr__
            if key in self.attributes:
                setattr(self, key, value)
            else:
                Global._error("Dendrite has no parameter/variable called", key)

    def get(self, name):
        """
        Returns the value of a variable/parameter.

        Example:

        ```python
        dendrite.get('w')
        ```

        :param name: name of the parameter/variable.
        """
        if name == 'rank':
            Global._warning("Dendrite.get('rank'): the attribute is deprecated, use Dendrite.pre_ranks instead.")
            return self.proj.cyInstance.pre_rank(self.idx)
        elif name == 'pre_ranks':
            return self.proj.cyInstance.pre_rank(self.idx)
        elif name in self.attributes:
            return getattr(self, name)
        else:
            Global._error("Dendrite has no parameter/variable called", name)


    #########################
    ### Formatting
    #########################
    def receptive_field(self, variable='w', fill=0.0):
        """
        Returns the given variable as a receptive field.

        A Numpy array of the same geometry as the pre-synaptic population is returned. 
        Non-existing synapses are replaced by zeros (or the value ``fill``).

        :param variable: name of the variable (default = 'w')
        :param fill: value to use when a synapse does not exist (default: 0.0).
        """
        values = getattr(self.proj.cyInstance, 'get_dendrite_'+variable)(self.idx)
        pre_ranks = self.proj.cyInstance.pre_rank( self.idx )

        m = fill * np.ones( self.pre.size )
        m[pre_ranks] = values

        return m.reshape(self.pre.geometry)


    #########################
    ### Structural plasticity
    #########################
    def create_synapse(self, rank, w=0.0, delay=0):
        """
        Creates a synapse for this dendrite with the given pre-synaptic neuron.

        :param rank: rank of the pre-synaptic neuron
        :param w: synaptic weight (defalt: 0.0).
        :param delay: synaptic delay (default = dt)
        """
        if not Global.config['structural_plasticity']:
            Global._error('"structural_plasticity" has not been set to True in setup(), can not add the synapse.')
            return

        if self.proj.cyInstance.dendrite_index(self.post_rank, rank) != -1:
            Global._error('the synapse of rank ' + str(rank) + ' already exists.')
            return

        # Set default values for the additional variables
        extra_attributes = {}
        for var in self.proj.synapse_type.description['parameters'] + self.proj.synapse_type.description['variables']:
            if not var['name'] in ['w', 'delay'] and  var['name'] in self.proj.synapse_type.description['local']:
                if not isinstance(self.proj.init[var['name']], (int, float, bool)):
                    init = var['init']
                else:
                    init = self.proj.init[var['name']]
                extra_attributes[var['name']] = init

        try:
            self.proj.cyInstance.add_synapse(self.post_rank, rank, w, int(delay/Global.config['dt']), **extra_attributes)
        except Exception as e:
            Global._print(e)

    def prune_synapse(self, rank):
        """
        Removes the synapse with the given pre-synaptic neuron from the dendrite.

        :param rank: rank of the pre-synaptic neuron
        """
        if not Global.config['structural_plasticity']:
            Global._error('"structural_plasticity" has not been set to True in setup(), can not remove the synapse.')
            return

        if not rank in self.pre_ranks:
            Global._error('the synapse with the pre-synaptic neuron of rank ' + str(rank) + ' did not already exist.')
            return

        self.proj.cyInstance.remove_synapse(self.post_rank, rank)

pre_ranks property #

List of ranks of pre-synaptic neurons.

size property #

Number of synapses.

synapses property #

Iteratively returns the synapses corresponding to this dendrite.

create_synapse(rank, w=0.0, delay=0) #

Creates a synapse for this dendrite with the given pre-synaptic neuron.

Parameters:

  • rank

    rank of the pre-synaptic neuron

  • w

    synaptic weight (defalt: 0.0).

  • delay

    synaptic delay (default = dt)

Source code in /home/docs/checkouts/readthedocs.org/user_builds/annarchy/conda/latest/lib/python3.9/site-packages/ANNarchy/core/Dendrite.py
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def create_synapse(self, rank, w=0.0, delay=0):
    """
    Creates a synapse for this dendrite with the given pre-synaptic neuron.

    :param rank: rank of the pre-synaptic neuron
    :param w: synaptic weight (defalt: 0.0).
    :param delay: synaptic delay (default = dt)
    """
    if not Global.config['structural_plasticity']:
        Global._error('"structural_plasticity" has not been set to True in setup(), can not add the synapse.')
        return

    if self.proj.cyInstance.dendrite_index(self.post_rank, rank) != -1:
        Global._error('the synapse of rank ' + str(rank) + ' already exists.')
        return

    # Set default values for the additional variables
    extra_attributes = {}
    for var in self.proj.synapse_type.description['parameters'] + self.proj.synapse_type.description['variables']:
        if not var['name'] in ['w', 'delay'] and  var['name'] in self.proj.synapse_type.description['local']:
            if not isinstance(self.proj.init[var['name']], (int, float, bool)):
                init = var['init']
            else:
                init = self.proj.init[var['name']]
            extra_attributes[var['name']] = init

    try:
        self.proj.cyInstance.add_synapse(self.post_rank, rank, w, int(delay/Global.config['dt']), **extra_attributes)
    except Exception as e:
        Global._print(e)

get(name) #

Returns the value of a variable/parameter.

Example:

dendrite.get('w')

Parameters:

  • name

    name of the parameter/variable.

Source code in /home/docs/checkouts/readthedocs.org/user_builds/annarchy/conda/latest/lib/python3.9/site-packages/ANNarchy/core/Dendrite.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
def get(self, name):
    """
    Returns the value of a variable/parameter.

    Example:

    ```python
    dendrite.get('w')
    ```

    :param name: name of the parameter/variable.
    """
    if name == 'rank':
        Global._warning("Dendrite.get('rank'): the attribute is deprecated, use Dendrite.pre_ranks instead.")
        return self.proj.cyInstance.pre_rank(self.idx)
    elif name == 'pre_ranks':
        return self.proj.cyInstance.pre_rank(self.idx)
    elif name in self.attributes:
        return getattr(self, name)
    else:
        Global._error("Dendrite has no parameter/variable called", name)

prune_synapse(rank) #

Removes the synapse with the given pre-synaptic neuron from the dendrite.

Parameters:

  • rank

    rank of the pre-synaptic neuron

Source code in /home/docs/checkouts/readthedocs.org/user_builds/annarchy/conda/latest/lib/python3.9/site-packages/ANNarchy/core/Dendrite.py
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
def prune_synapse(self, rank):
    """
    Removes the synapse with the given pre-synaptic neuron from the dendrite.

    :param rank: rank of the pre-synaptic neuron
    """
    if not Global.config['structural_plasticity']:
        Global._error('"structural_plasticity" has not been set to True in setup(), can not remove the synapse.')
        return

    if not rank in self.pre_ranks:
        Global._error('the synapse with the pre-synaptic neuron of rank ' + str(rank) + ' did not already exist.')
        return

    self.proj.cyInstance.remove_synapse(self.post_rank, rank)

receptive_field(variable='w', fill=0.0) #

Returns the given variable as a receptive field.

A Numpy array of the same geometry as the pre-synaptic population is returned. Non-existing synapses are replaced by zeros (or the value fill).

Parameters:

  • variable

    name of the variable (default = 'w')

  • fill

    value to use when a synapse does not exist (default: 0.0).

Source code in /home/docs/checkouts/readthedocs.org/user_builds/annarchy/conda/latest/lib/python3.9/site-packages/ANNarchy/core/Dendrite.py
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def receptive_field(self, variable='w', fill=0.0):
    """
    Returns the given variable as a receptive field.

    A Numpy array of the same geometry as the pre-synaptic population is returned. 
    Non-existing synapses are replaced by zeros (or the value ``fill``).

    :param variable: name of the variable (default = 'w')
    :param fill: value to use when a synapse does not exist (default: 0.0).
    """
    values = getattr(self.proj.cyInstance, 'get_dendrite_'+variable)(self.idx)
    pre_ranks = self.proj.cyInstance.pre_rank( self.idx )

    m = fill * np.ones( self.pre.size )
    m[pre_ranks] = values

    return m.reshape(self.pre.geometry)

set(value) #

Sets the value of a parameter/variable of all synapses.

Example:

dendrite.set( { 'tau' : 20, 'w'= Uniform(0.0, 1.0) } )

Parameters:

  • value

    a dictionary containing the parameter/variable names as keys.

Source code in /home/docs/checkouts/readthedocs.org/user_builds/annarchy/conda/latest/lib/python3.9/site-packages/ANNarchy/core/Dendrite.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
def set(self, value):
    """
    Sets the value of a parameter/variable of all synapses.

    Example:

    ```python
    dendrite.set( { 'tau' : 20, 'w'= Uniform(0.0, 1.0) } )
    ```

    :param value: a dictionary containing the parameter/variable names as keys.
    """
    for key, value in value.items():
        # sanity check and then forward to __setattr__
        if key in self.attributes:
            setattr(self, key, value)
        else:
            Global._error("Dendrite has no parameter/variable called", key)

synapse(pos) #

Returns the synapse coming from the corresponding presynaptic neuron.

Parameters:

  • pos

    can be either the rank or the coordinates of the presynaptic neuron

Source code in /home/docs/checkouts/readthedocs.org/user_builds/annarchy/conda/latest/lib/python3.9/site-packages/ANNarchy/core/Dendrite.py
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def synapse(self, pos):
    """
    Returns the synapse coming from the corresponding presynaptic neuron.

    :param pos: can be either the rank or the coordinates of the presynaptic neuron
    """
    if isinstance(pos, int):
        rank = pos
    else:
        rank = self.proj.pre.rank_from_coordinates(pos)

    if rank in self.pre_ranks:
        return IndividualSynapse(self, rank)
    else:
        Global._error(" The neuron of rank "+ str(rank) + " has no synapse in this dendrite.")
        return None