====== The Sparse Connection Class ======
SparseConnections are used to connect neuron groups with static synapses that are generally initialized randomly with sparse entries. The connection can just as well be loaded from a [[wmat]] file or with some tinkering can be influenced directly from within the model file. The underlying connection matrix is stored in the [[SimpleMatrix]] format which allows efficient propagate on spikes. Since almost all connections in Auryn inherit from SparseConnection the basic functionally as how to connect and initalize any connection object remain the same throughout.
===== Initializing with random sparse connectivity =====
A standard call to the class might look like the following
SparseConnection(SpikingGroup * source,
NeuronGroup * destination,
AurynWeight weight,
AurynFloat sparseness=0.05,
TransmitterType transmitter=GLUT,
string name="SparseConnection");
where the ''source'' has to be a child of [[SpikingGroup]] and ''destination'' has to be derived from [[NeuronGroup]]. The third parameter (''weight'' in this case) represents the value of the synaptic strength in units of the leak conductance of the postsynaptic neuron. When initialized with a given weight and ''sparseness'' the constructor will connect the two groups in an all-to-all fashion with an overall connection probability which is given by ''sparseness''. The transmitter parameter (''GABA'' in the example) specifies the target state variable to act on. Allowed values are of [[TransmitterType]] such as GLUT (mostly a synonym for AMPA and NMDA depending on the neuron model), GABA for inhibitory conductances. It is also possible to only target NMDA channels or the membrane voltage directly (MEM), which allows to implement current based models. In the latter case the synaptic weight has to be interpreted in units of voltage. Finally, one can specify a connection ''name'' which alternatively can also be set via the ''set_name(string name)'' member function. Connection names are used in debug output, the [[wmat]] dump, and in the [[log]] file and help to identify connections.
===== Initializing connections from a file =====
SparseConnection has another constructor that allows to initialize the connection matrix directly from a file.
SparseConnection(SpikingGroup * source,
NeuronGroup * destination,
const char * filename,
TransmitterType transmitter=GLUT);
Instead of the arguments ''weight'' and ''sparseness'' you can pass the ''filename'' argument to specify a [[wmat]] file from which the connection will be initialized. Note that particularly when running simulations in parallel this file should only contain the elements of the connection matrix that are also stored on the respective rank where the code is issued. This is generally the case if the weight matrix has been saved during a run of the same model run on the equal amount of nodes/ranks. If this is not the case the creation of such matrices might require a more in depth understanding on how auryn distributes neurons and synapses over the existing computing resources (see also [[manual:load balancing]]).
===== Loading patterns =====
Patterns can be loaded from a [[pat]] file to an existing weight matrix. Here is an example:
SparseConnection * con_ee = new SparseConnection(neurons_e,neurons_e,wee,sparseness);
con_ee->load_patterns("2blocks.pat",lambda);
In this example first the connection object ''con_ee'' is instantiated and then a bunch patterns from the file ''2blocks.pat'' are added with the ''load_patterns'' command. By default the load patterns method will check if two respective neurons being part of one pattern have an existing connection between them. If that is the case, this connection will be augmented by the second parameter ''lambda'' which should be of type [[AurynWeight]].
The full method is the following
void load_patterns( string filename, AurynWeight strength, bool overwrite = false, bool chainmode = false);
void load_patterns( string filename, AurynWeight strength, int n, bool overwrite = false, bool chainmode = false);
where the filename always specifies the full path to the [[pat]] file. strength signifies the amount by which the weights (given the connections exists is increased) if ''overwrite == false''. If overwrite is set to ''true'' all connections are are set to exactly ''strength'' similar to the Willshaw model.
''chainmode'' when enabled will write a synfire chain to the weight matrix by consecutively connecting pattern ''n'' with ''n+1''. Finally the amount of patterns loaded from the file can be limited to number ''n'' by setting the corresponding parameter.