3.16. Weight Sharing
Shared projections (either using the same set of weights for all postsynaptic 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 postsynaptic 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 maxpooling or similar..
Parameters:
 pre: presynaptic population (either its name or a
Population
object).
 post: postsynaptic 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 presynaptic population of the center of the kernel corresponding to the postsynaptic with the given rank or coordinates.
Parameters
 rank: rank or coordinates of the postsynaptic 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 presynaptic population.
Depending on the number of dimensions of the pre and postsynaptic populations, as well as the kernel, the convolution can be implemented differentely.
 If the pre and postpopulations have the same dimension as the kernel, the convolution is regular.
 If the postpopulation has one dimension less than the presynaptic one, the last dimension of the kernel must match the last one of the presynaptic 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 presynaptic 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 presynaptic population, this means a bank of different filters will be applied on the presynaptic population. Attention: the first index of
weights
corresponds to the different filters, while the result will be accessible in the last dimension of the postsynaptic population. You must set the multiple
argument to True.
Subsampling will be automatically performed according to the populations’ geometry. If these geometries do not match, an error will be thrown. You can force subsampling by providing a list subsampling
as argument, defining for each postsynaptic neuron the coordinates of the presynaptic 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 filterbased (dotproduct between the filter and subregion: ‘filter’) or kernelbased (regular convolution: ‘convolution’).. Default: ‘convolution’.
 keep_last_dimension: defines if the last dimension of the pre and postsynaptic will be convolved in parallel. The weights matrix must have one dimension less than the presynaptic population, and the number of neurons in the last dimension of the pre and postsynaptic 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 presynaptic populations, and the number of neurons in the last dimension of the postsynaptic population must be equal to the number of filters.
 padding: value to be used for the rates outside the presynaptic population. If it is a floating value, the presynaptic 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 postsynaptic neuron of coordinates in the presynaptic 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 alreadydefined 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 postsynaptic 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 presynaptic population.
Each postsynaptic neuron is associated to a region of the presynaptic 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 maxpooling, 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 presynaptic population. In each dimension, the product of this extent with the number of neurons in the postsynaptic population must be equal to the number of presynaptic neurons.
 overlap: TODO, not implemented yet.