GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement Class Reference

#include <initSparseConnectivitySnippet.h>

Inheritance diagram for InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement:
InitSparseConnectivitySnippet::Base Snippet::Base

Public Member Functions

 DECLARE_SNIPPET (InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement, 1)
 
 SET_ROW_BUILD_CODE ("if(c == 0) {\ " $(endRow);\" "}\" "const scalar u=$(gennrand_uniform);\" "x+=(1.0 - x) *(1.0 - pow(u, 1.0/(scalar) c));\" "unsigned int postIdx=(unsigned int)(x *$(num_post));\" "postIdx=(postIdx< $(num_post)) ? postIdx :($(num_post) - 1);\" "$(addSynapse, postIdx+$(id_post_begin));\" "c--;\")
 
 SET_ROW_BUILD_STATE_VARS ({{"x", "scalar", 0.0},{"c", "unsigned int", "$(preCalcRowLength)[($(id_pre) * $(num_threads)) + $(id_thread)]"}})
 
virtual StringVec getParamNames () const override
 Gets names of of (independent) model parameters. More...
 
virtual EGPVec getExtraGlobalParams () const override
 
 SET_HOST_INIT_CODE ("// Allocate pre-calculated row length array\ "$(allocatepreCalcRowLength, $(num_pre) *$(num_threads));\" "//Calculate row lengths\" "const size_t numPostPerThread=($(num_post)+$(num_threads) - 1)/$(num_threads);\" "const size_t leftOverNeurons=$(num_post) % numPostPerThread;\" "size_t remainingConnections=$(total);\" "size_t matrixSize=(size_t)$(num_pre) *(size_t)$(num_post);\" "uint16_t *subRowLengths=$(preCalcRowLength);\" "//Loop through rows\" "for(size_t i=0;i< $(num_pre);i++) {\" " const bool lastPre=(i==($(num_pre) - 1));\" "//Loop through subrows\" " for(size_t j=0;j< $(num_threads);j++) {\" " const bool lastSubRow=(j==($(num_threads) - 1));\" "//If this isn 't the last sub-row of the matrix\" " if(!lastPre||! lastSubRow) {\" "//Get length of this subrow\" " const unsigned int numSubRowNeurons=(leftOverNeurons !=0 &&lastSubRow) ? leftOverNeurons :numPostPerThread;\" "//Calculate probability\" " const double probability=(double) numSubRowNeurons/(double) matrixSize;\" "//Create distribution to sample row length\" " std::binomial_distribution< size_t > rowLengthDist(remainingConnections, probability);\" "//Sample row length;\" " const size_t subRowLength=rowLengthDist($(rng));\" "//Update counters\" " remainingConnections -=subRowLength;\" " matrixSize -=numSubRowNeurons;\" "//Add row length to array\" " assert(subRowLength< std::numeric_limits< uint16_t >::max());\" " *subRowLengths++=(uint16_t) subRowLength;\" " }\" " }\" "}\" "//Insert remaining connections into last sub-row\" " *subRowLengths=(uint16_t) remainingConnections;\" "//Push populated row length array\" "$(pushpreCalcRowLength, $(num_pre) *$(num_threads));\")
 
 SET_CALC_MAX_ROW_LENGTH_FUNC ([](unsigned int numPre, unsigned int numPost, const std::vector< double > &pars) { const double quantile=pow(0.9999, 1.0/(double) numPre);return binomialInverseCDF(quantile,(unsigned int) pars[0],(double) numPost/((double) numPre *(double) numPost));})
 
 SET_CALC_MAX_COL_LENGTH_FUNC ([](unsigned int numPre, unsigned int numPost, const std::vector< double > &pars) { const double quantile=pow(0.9999, 1.0/(double) numPost);return binomialInverseCDF(quantile,(unsigned int) pars[0],(double) numPre/((double) numPre *(double) numPost));})
 
- Public Member Functions inherited from InitSparseConnectivitySnippet::Base
virtual std::string getRowBuildCode () const
 
virtual ParamValVec getRowBuildStateVars () const
 
virtual std::string getColBuildCode () const
 
virtual ParamValVec getColBuildStateVars () const
 
virtual std::string getHostInitCode () const
 
virtual CalcMaxLengthFunc getCalcMaxRowLengthFunc () const
 Get function to calculate the maximum row length of this connector based on the parameters and the size of the pre and postsynaptic population. More...
 
virtual CalcMaxLengthFunc getCalcMaxColLengthFunc () const
 Get function to calculate the maximum column length of this connector based on the parameters and the size of the pre and postsynaptic population. More...
 
virtual CalcKernelSizeFunc getCalcKernelSizeFunc () const
 Get function to calculate kernel size required for this conenctor based on its parameters. More...
 
boost::uuids::detail::sha1::digest_type getHashDigest () const
 Update hash from snippet. More...
 
void validate () const
 Validate names of parameters etc. More...
 
- Public Member Functions inherited from Snippet::Base
virtual ~Base ()
 
virtual DerivedParamVec getDerivedParams () const
 
size_t getExtraGlobalParamIndex (const std::string &paramName) const
 Find the index of a named extra global parameter. More...
 

Additional Inherited Members

- Public Types inherited from InitSparseConnectivitySnippet::Base
typedef std::function< unsigned int(unsigned int, unsigned int, const std::vector< double > &)> CalcMaxLengthFunc
 
typedef std::function< std::vector< unsigned int >const std::vector< double > &)> CalcKernelSizeFunc
 
- Public Types inherited from Snippet::Base
typedef std::vector< std::string > StringVec
 
typedef std::vector< EGPEGPVec
 
typedef std::vector< ParamValParamValVec
 
typedef std::vector< DerivedParamDerivedParamVec
 
- Protected Member Functions inherited from Snippet::Base
void updateHash (boost::uuids::detail::sha1 &hash) const
 
void validate () const
 Validate names of parameters etc. More...
 
- Static Protected Member Functions inherited from Snippet::Base
template<typename T >
static size_t getNamedVecIndex (const std::string &name, const std::vector< T > &vec)
 

Detailed Description

Initialises connectivity with a total number of random synapses. The first stage in using this connectivity is to determine how many of the total synapses end up in each row. This can be determined by sampling from the multinomial distribution. However, this operation cannot be efficiently parallelised so must be performed on the host and the result passed as an extra global parameter array.

Once the length of each row is determined, the postsynaptic targets of the synapses can be initialised in parallel by sampling from the discrete uniform distribution. However, to sample connections in ascending order, we sample from the 1st order statistic of the uniform distribution – Beta[1, Npost] – essentially the next smallest value. In this special case this is equivalent to the exponential distribution which can be sampled in constant time using the inversion method.

Member Function Documentation

◆ DECLARE_SNIPPET()

InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::DECLARE_SNIPPET ( InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement  ,
 
)

◆ getExtraGlobalParams()

virtual EGPVec InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::getExtraGlobalParams ( ) const
inlineoverridevirtual

Gets names and types (as strings) of additional per-population parameters for the snippet

Reimplemented from Snippet::Base.

◆ getParamNames()

virtual StringVec InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::getParamNames ( ) const
inlineoverridevirtual

Gets names of of (independent) model parameters.

Reimplemented from Snippet::Base.

◆ SET_CALC_MAX_COL_LENGTH_FUNC()

InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::SET_CALC_MAX_COL_LENGTH_FUNC ( [] (unsigned int numPre, unsigned int numPost, const std::vector< double > &pars) { const double quantile=pow(0.9999, 1.0/(double) numPost);return binomialInverseCDF(quantile,(unsigned int) pars[0],(double) numPre/((double) numPre *(double) numPost));}  )

◆ SET_CALC_MAX_ROW_LENGTH_FUNC()

InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::SET_CALC_MAX_ROW_LENGTH_FUNC ( [] (unsigned int numPre, unsigned int numPost, const std::vector< double > &pars) { const double quantile=pow(0.9999, 1.0/(double) numPre);return binomialInverseCDF(quantile,(unsigned int) pars[0],(double) numPost/((double) numPre *(double) numPost));}  )

◆ SET_HOST_INIT_CODE()

InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::SET_HOST_INIT_CODE ( )

◆ SET_ROW_BUILD_CODE()

InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::SET_ROW_BUILD_CODE ( )

◆ SET_ROW_BUILD_STATE_VARS()

InitSparseConnectivitySnippet::FixedNumberTotalWithReplacement::SET_ROW_BUILD_STATE_VARS ( {{"x", "scalar", 0.0},{"c", "unsigned int", "$(preCalcRowLength)[($(id_pre) * $(num_threads)) + $(id_thread)]"}}  )

The documentation for this class was generated from the following file: