Sparse connectivity initialisation

Synaptic connectivity implemented using SynapseMatrixConnectivity::SPARSE and SynapseMatrixConnectivity::BITMASK can be automatically initialised.

This can be done using one of a number of predefined sparse connectivity initialisation snippets :

For example, to initialise synaptic connectivity with a 10% connection probability (allowing connections between neurons with the same id):

InitSparseConnectivitySnippet::FixedProbability::ParamValues fixedProb(0.1);

model.addSynapsePopulation<...>(
        ...
        initConnectivity<InitSparseConnectivitySnippet::FixedProbability>(fixedProb));

Defining a new sparse connectivity snippet

Similarly to variable initialisation snippets, sparse connectivity initialisation snippets can be created by simply defining a class in the model description.

For example, the following sparse connectivity initialisation snippet could be used to initialise a ‘ring’ of connectivity where each neuron is connected to a number of subsequent neurons specified using the numNeighbours parameter:

class Ring : public InitSparseConnectivitySnippet::Base
{
public:
    DECLARE_SNIPPET(Ring, 1);

    SET_ROW_BUILD_STATE_VARS({{"offset", {"unsigned int", 1}}}});
    SET_ROW_BUILD_CODE(
        "const unsigned int target = ($(id_pre) + offset) % $(num_post);\n"
        "$(addSynapse, target);\n"
        "offset++;\n"
        "if(offset > (unsigned int)$(numNeighbours)) {\n"
        "   $(endRow);\n"
        "}\n");

    SET_PARAM_NAMES({"numNeighbours"});
    SET_CALC_MAX_ROW_LENGTH_FUNC(
        [](unsigned int numPre, unsigned int numPost, const std::vector<double> &pars)
        {
            return (unsigned int)pars[0];
        });
    SET_CALC_MAX_COL_LENGTH_FUNC(
        [](unsigned int numPre, unsigned int numPost, const std::vector<double> &pars)
        {
            return (unsigned int)pars[0];
        });
};
IMPLEMENT_SNIPPET(Ring);

Each row of sparse connectivity is initialised independantly by running the snippet of code specified using the SET_ROW_BUILD_CODE() macro within a loop. The $(num_post) variable can be used to access the number of neurons in the postsynaptic population and the $(id_pre) variable can be used to access the index of the presynaptic neuron associated with the row being generated. The SET_ROW_BUILD_STATE_VARS() macro can be used to initialise state variables outside of the loop - in this case offset which is used to count the number of synapses created in each row. Synapses are added to the row using the $(addSynapse, target) function and iteration is stopped using the $(endRow) function. To avoid having to manually call SynapseGroup::setMaxConnections and SynapseGroup::setMaxSourceConnections, sparse connectivity snippets can also provide code to calculate the maximum row and column lengths this connectivity will result in using the SET_CALC_MAX_ROW_LENGTH_FUNC() and SET_CALC_MAX_COL_LENGTH_FUNC() macros. Alternatively, if the maximum row or column length is constant, the SET_MAX_ROW_LENGTH() and SET_MAX_COL_LENGTH() shorthand macros can be used.

Sparse connectivity locations

Once you have defined how sparse connectivity is going to be initialised, similarly to variables, you can control where it is allocated. This is controlled using the same VarLocations options described in section Variable locations and can either be set using the model default specifiued with ModelSpec::setDefaultSparseConnectivityLocation or on a per-synapse group basis using SynapseGroup::setSparseConnectivityLocation.

Previous | Top | Next