3.16. Weight Sharing

Shared projections (either using the same set of weights for all post-synaptic neurons, or sharing its weight with another projection) are provided in the module ANNarchy.extensions.weightsharing. They must be explicitely imported:

from ANNarchy import *
from ANNarchy.extensions.weightsharing import *

3.16.1. Class SharedProjection

class ANNarchy.extensions.weightsharing.SharedProjection(pre, post, target, psp='w * pre.r', operation='sum')[source]

Projection based on shared weights: each post-synaptic neuron uses the same weights, so they need to be instantiated only once to save memory.

Learning is not possible for now. The synapse argument is removed, replaced by a single psp argument to modified what is summed and operation to replace the summation operation by max-pooling or similar..

Parameters:

  • pre: pre-synaptic population (either its name or a Population object).
  • post: post-synaptic population (either its name or a Population object).
  • target: type of the connection.
  • psp: function to be summed. By default: w * pre.r
  • operation: function applied on psp (“sum”, “max”, “min”, “mean”). “sum” is the default.
center(*args, **kwds)[source]

Returns the coordinates in the pre-synaptic population of the center of the kernel corresponding to the post-synaptic with the given rank or coordinates.

Parameters

  • rank: rank or coordinates of the post-synaptic neuron. If only one argument is given, it is a rank. If it is a tuple, it is coordinates.
convolve(weights, delays=0.0, method='convolution', keep_last_dimension=False, multiple=False, padding=0.0, subsampling=None)[source]

Builds the shared connection pattern that will perform a convolution of the weights kernel on the pre-synaptic population.

Depending on the number of dimensions of the pre- and post-synaptic populations, as well as the kernel, the convolution can be implemented differentely.

  • If the pre- and post-populations have the same dimension as the kernel, the convolution is regular.
  • If the post-population has one dimension less than the pre-synaptic one, the last dimension of the kernel must match the last one of the pre-synaptic population. For example, filtering a N*M*3 image with a 3D filter (3 elements in the third dimension) results into a 2D population.
  • If the kernel has less dimensions than the two populations, the number of neurons in the last dimension of the populations must be the same. The convolution will be calculated for each position in the last dimension (parallel convolution, useful if the pre-synaptic population is a stack of feature maps, for example). In this case, you must set keep_last_dimension to True.
  • If the kernel has more dimensions than the pre-synaptic population, this means a bank of different filters will be applied on the pre-synaptic population. Attention: the first index of weights corresponds to the different filters, while the result will be accessible in the last dimension of the post-synaptic population. You must set the multiple argument to True.

Sub-sampling will be automatically performed according to the populations’ geometry. If these geometries do not match, an error will be thrown. You can force sub-sampling by providing a list subsampling as argument, defining for each post-synaptic neuron the coordinates of the pre-synaptic neuron which will be the center of the filter/kernel.

Parameters:

  • weights: Numpy array or list of lists representing the matrix of weights for the filter/kernel.
  • delays: delay in synaptic transmission (default: dt). Can only be the same value for all neurons.
  • method: defines if the given weights are filter-based (dot-product between the filter and sub-region: ‘filter’) or kernel-based (regular convolution: ‘convolution’).. Default: ‘convolution’.
  • keep_last_dimension: defines if the last dimension of the pre- and post-synaptic will be convolved in parallel. The weights matrix must have one dimension less than the pre-synaptic population, and the number of neurons in the last dimension of the pre- and post-synaptic populations must match. Default: False.
  • multiple: defines if the weights matrix describes a bank of filters which have to applied in parallel. The weights matrix must have one dimension more than the pre-synaptic populations, and the number of neurons in the last dimension of the post-synaptic population must be equal to the number of filters.
  • padding: value to be used for the rates outside the pre-synaptic population. If it is a floating value, the pre-synaptic population is virtually extended with this value above its boundaries. If it is equal to ‘border’, the values on the boundaries are repeated. Default: 0.0.
  • subsampling: list for each post-synaptic neuron of coordinates in the pre-synaptic population defining the center of the kernel/filter. Default: None.
copy(projection)[source]

Creates a virtual connection pattern reusing the weights and delays of an already-defined projection.

Although the original projection can be learnable, this one can not. Changes in the original weights will be reflected in this projection. The only possible modifications are psp and operation.

The pre- and post-synaptic populations of each projection must have the same geometry.

Parameters:

  • projection: the projection to reuse.
pooling(delays=0.0, extent=None, overlap=None)[source]

Builds the shared connection pattern that will perform a pooling operation over the pre-synaptic population.

Each post-synaptic neuron is associated to a region of the pre-synaptic one, over which the result of the operation on firing rates will be assigned to sum(target).

If the SharedProjection does not define an operation, the default is “sum”. If you want max-pooling, you should set it to “max”.

Parameters:

  • delays: delays (in ms) in synaptic transmission. Must be a single value for all neurons.
  • extent: Extent of the pooling area expressed in the geometry of the pre-synaptic population. In each dimension, the product of this extent with the number of neurons in the post-synaptic population must be equal to the number of pre-synaptic neurons.
  • overlap: TODO, not implemented yet.