Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
auryn::SparseConnection Class Reference

The base class to create sparse random connections. More...

#include <SparseConnection.h>

Inheritance diagram for auryn::SparseConnection:
Inheritance graph
[legend]
Collaboration diagram for auryn::SparseConnection:
Collaboration graph
[legend]

Public Member Functions

 SparseConnection ()
 Empty constructor which should not be used – TODO should be deprecated at some point. More...
 
 SparseConnection (const char *filename)
 Load from wmat file constructor which should not be used – TODO should be deprecated at some point. More...
 
 SparseConnection (NeuronID rows, NeuronID cols)
 Deprecated constructor for manual filling. More...
 
 SparseConnection (SpikingGroup *source, NeuronGroup *destination, const char *filename, TransmitterType transmitter=GLUT)
 Deprecated constructor for loading from file. More...
 
 SparseConnection (SpikingGroup *source, NeuronGroup *destination, TransmitterType transmitter=GLUT, string name="SparseConnection")
 Constructor for manual filling. More...
 
 SparseConnection (SpikingGroup *source, NeuronGroup *destination, AurynWeight weight, AurynDouble sparseness=0.05, TransmitterType transmitter=GLUT, string name="SparseConnection")
 Default constructor which sets up a random sparse matrix with fixed weight between the source and destination group. More...
 
 SparseConnection (SpikingGroup *source, NeuronGroup *destination, SparseConnection *con, string name="SparseConnection")
 This constructor tries to clone a connection by guessing all parameters except source and destination from another connection instance. More...
 
 SparseConnection (SpikingGroup *source, NeuronGroup *destination, AurynWeight weight, AurynDouble sparseness, NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, TransmitterType transmitter=GLUT)
 Sparse block constructor. More...
 
virtual ~SparseConnection ()
 The default destructor. More...
 
void allocate_manually (AurynLong expected_size)
 Is used whenever memory has to be allocated manually. Automatically adjusts for number of ranks and for security margin. More...
 
AurynLong estimate_required_nonzero_entires (AurynLong nonzero, double sigma=5.)
 This function estimates the required size of the nonzero entry buffer. More...
 
void seed (NeuronID randomseed)
 This function seeds the pseudo random number generator for all random fill operatios. More...
 
virtual AurynWeight get (NeuronID i, NeuronID j)
 Returns weight value of a given element if it exists. More...
 
virtual AurynWeightget_ptr (NeuronID i, NeuronID j)
 Returns pointer to given weight element if it exists. Returns NULL if element does not exist. More...
 
virtual AurynWeight get_data (NeuronID i)
 Returns weight value of a given element referenced by index in the data array. More...
 
virtual void set_data (NeuronID i, AurynWeight value)
 Sets weight value of a given element referenced by its index in the data array. More...
 
virtual void set (NeuronID i, NeuronID j, AurynWeight value)
 Sets a single connection to value if it exists. More...
 
virtual void set (std::vector< neuron_pair > element_list, AurynWeight value)
 Sets a list of connection to value if they exists. More...
 
void random_data (AurynWeight mean, AurynWeight sigma)
 Synonym for random_data. More...
 
void random_data_normal (AurynWeight mean, AurynWeight sigma)
 Set weights of all existing connections randomly using a normal distrubtion. More...
 
void random_data_lognormal (AurynWeight m, AurynWeight s)
 Set weights of all existing connections randomly using a lognormal distribution. More...
 
void init_random_binary (AurynFloat prob=0.5, AurynWeight wlo=0.0, AurynWeight whi=1.0)
 Initialize with random binary at wlo and whi. More...
 
void random_col_data (AurynWeight mean, AurynWeight sigma)
 Sets weights in cols to the same value drewn from a Gaussian distribution. More...
 
void set_block (NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, AurynWeight weight)
 Sets all weights of existing connections in a block spanned by the first 4 parameters to the value given. More...
 
void scale_block (NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, AurynWeight alpha)
 Scale all weights of existing connections in a block spanned by the first 4 parameters to the value given. More...
 
virtual void set_all (AurynWeight weight)
 Sets all weights of existing connections to the given value. More...
 
virtual void scale_all (AurynFloat value)
 Scales all weights in the weight matrix with the given value. More...
 
virtual void clip (AurynWeight lo, AurynWeight hi)
 Clip weights. More...
 
void set_upper_triangular (AurynWeight weight)
 Sets weights in a upper triangular matrix. More...
 
virtual void sparse_set_data (AurynDouble sparseness, AurynWeight value)
 Sets a sparse random subset of connection elements wight the given value. More...
 
void connect_random (AurynWeight weight=1.0, AurynDouble sparseness=0.05, bool skip_diag=false)
 Connect src and dst SpikingGroup and NeuronGroup randomly with given sparseness. More...
 
void connect_block_random (AurynWeight weight, AurynDouble sparseness, NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, bool skip_diag=false)
 Underlying sparse fill method. More...
 
virtual void finalize ()
 Finalizes connection after random or manual initialization of the weights. More...
 
bool push_back (NeuronID i, NeuronID j, AurynWeight weight)
 Pushes a single element to the ComplexMatrix. More...
 
AurynLong get_nonzero ()
 Returns number of nonzero elements in this SparseConnection. More...
 
void put_pattern (type_pattern *pattern, AurynWeight strength, bool overwrite)
 Puts cell assembly to existing sparse weights. More...
 
void put_pattern (type_pattern *pattern1, type_pattern *pattern2, AurynWeight strength, bool overwrite)
 Puts cell assembly or synfire pattern to existing sparse weights. More...
 
void load_patterns (string filename, AurynWeight strength, int nb_max_patterns=10000, bool overwrite=false, bool chainmode=false)
 Reads first n patterns from a .pat file and adds them as Hebbian assemblies onto an existing weight matrix. More...
 
void load_pre_post_patterns (std::string pre_file, std::string post_file, AurynWeight strength, int nb_max_patterns=10000, bool overwrite=false)
 Reads patterns from two files and connects them. More...
 
virtual void propagate ()
 Internally used propagate method. More...
 
void sanity_check ()
 Quick an dirty function that checks if all units on the local rank are connected. More...
 
virtual AurynDouble sum ()
 Computes sum of all weight elements in the Connection. More...
 
virtual void stats (AurynDouble &mean, AurynDouble &std)
 Computes mean and variance of weights in default weight matrix. More...
 
virtual void stats (AurynDouble &mean, AurynDouble &std, NeuronID zid)
 Computes mean and variance of weights for matrix state zid. More...
 
bool write_to_file (ForwardMatrix *m, string filename)
 Writes rank specific weight matrix on the same rank to a file. More...
 
virtual bool write_to_file (string filename)
 Writes rank specific default weight matrix on the same rank to a file. More...
 
virtual bool load_from_complete_file (string filename)
 Loads weight matrix from a single file. More...
 
virtual bool load_from_file (string filename)
 Loads weight matrix from Matrix Market (wmat) file. More...
 
bool load_from_file (ForwardMatrix *m, string filename, AurynLong data_size=0)
 Loads weight matrix from Matrix Market (wmat) file to specified weight matrix. More...
 
virtual void set_min_weight (AurynWeight minimum_weight)
 Sets minimum weight (for plastic connections). More...
 
AurynWeight get_min_weight ()
 Gets minimum weight (for plastic connections). More...
 
virtual void set_max_weight (AurynWeight maximum_weight)
 Sets maximum weight (for plastic connections). More...
 
AurynWeight get_max_weight ()
 Gets maximum weight (for plastic connections). More...
 
std::vector< neuron_pairget_block (NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col)
 Returns a vector of ConnectionsID of a block specified by the arguments. More...
 
std::vector< neuron_pairget_post_partners (NeuronID i)
 Returns a vector of ConnectionsID of postsynaptic parterns of neuron i. More...
 
std::vector< neuron_pairget_pre_partners (NeuronID j)
 Returns a vector of ConnectionsID of presynaptic parterns of neuron i. More...
 
- Public Member Functions inherited from auryn::Connection
 Connection ()
 
 Connection (NeuronID rows, NeuronID cols)
 
 Connection (SpikingGroup *source, NeuronGroup *destination, TransmitterType transmitter=GLUT, std::string name="Connection")
 
virtual ~Connection ()
 
void set_size (NeuronID i, NeuronID j)
 
void set_name (std::string name)
 Set name of connection. More...
 
std::string get_name ()
 Returns name of connection. More...
 
std::string get_file_name ()
 Extracts the class name of the connection from the file name. More...
 
std::string get_log_name ()
 Returns a string which is the combination of file and connection name for logging. More...
 
AurynStateVectorget_target_vector ()
 Returns target state vector if one is defined. More...
 
NeuronID get_m_rows ()
 Get number of rows (presynaptic) in connection. More...
 
NeuronID get_n_cols ()
 Get number of columns (postsynaptic) in connection. More...
 
TransmitterType get_transmitter ()
 Returns transmitter type. More...
 
void set_target (AurynWeight *ptr)
 Sets target state of this connection directly via a pointer. More...
 
void set_target (AurynStateVector *ptr)
 Sets target state of this connection directly via a StateVector. More...
 
void set_receptor (AurynStateVector *ptr)
 Same as set_target. More...
 
void set_transmitter (AurynStateVector *ptr)
 Same as set_target. More...
 
void set_transmitter (TransmitterType transmitter)
 Sets target state of this connection for a given receptor as one of Auryn's default transmitter types. More...
 
void set_receptor (string state_name)
 Sets target state of this connection directly the name of a state vector. More...
 
void set_target (string state_name)
 Same as set_receptor. More...
 
void set_transmitter (string state_name)
 Same as set_receptor, but DEPRECATED. More...
 
void set_source (SpikingGroup *source)
 Sets source SpikingGroup of this connection. More...
 
SpikingGroupget_source ()
 Returns pointer to the presynaptic group. More...
 
void set_destination (NeuronGroup *source)
 Sets destination SpikingGroup of this connection. More...
 
NeuronGroupget_destination ()
 Returns pointer to the postsynaptic group. More...
 
virtual void evolve ()
 Evolve method to update internal connection state. Called by System run method. More...
 
void conditional_propagate ()
 DEPRECATED. (Such connections should not be registered in the first place) Calls propagate only if the postsynaptic NeuronGroup exists on the local rank. More...
 
Traceget_pre_trace (const AurynDouble tau)
 Returns a pointer to a presynaptic trace object. More...
 
Traceget_post_trace (const AurynDouble tau)
 Returns a pointer to a postsynaptic trace object. More...
 
Traceget_post_state_trace (const string state_name, const AurynDouble tau, const AurynDouble jump_size=0.0)
 Returns a pointer to a postsynaptic state trace object. More...
 
void transmit (const NeuronID id, const AurynWeight amount)
 Default way to transmit a spike to a postsynaptic partner. More...
 
void targeted_transmit (SpikingGroup *target_group, AurynStateVector *target_state, const NeuronID id, const AurynWeight amount)
 Transmits a spike to a given target group and state. More...
 
void safe_transmit (NeuronID id, AurynWeight amount)
 Same as transmit but first checks if the target neuron exists and avoids segfaults that way (but it's also slower). More...
 
SpikeContainerget_pre_spikes ()
 Supplies pointer to SpikeContainer of all presynaptic spikes. More...
 
SpikeContainerget_post_spikes ()
 Returns pointer to SpikeContainer for postsynaptic spikes on this node. More...
 
void add_number_of_spike_attributes (int x)
 Set up spike delay to accomodate x additional spike attributes. More...
 
AurynFloat get_spike_attribute (const NeuronID i, const int attribute_id=0)
 Returns spike attribute belonging to the spike at position i in the get_spikes() SpikeContainer. More...
 

Public Attributes

bool patterns_ignore_gamma
 Switch that toggles for the load_patterns function whether or not to use the intensity (gamma) value. Default is false. More...
 
NeuronID patterns_every_pre
 The every_pre parameter allows to skip presynaptically over pattern IDs when loading patterns. Default is 1. This can be useful to when loading patterns into the exc->inh connections and there significantly less inhibitory cells than exc ones. More...
 
NeuronID patterns_every_post
 The every_post parameter allows to skip postsynaptically over pattern IDs when loading patterns. Default is 1. This can be useful to when loading patterns into the exc->inh connections and there significantly less inhibitory cells than exc ones. More...
 
bool wrap_patterns
 Switch that toggles the behavior when loading a pattern to wrap neuron IDs back onto existing cells via the modulo function. More...
 
ForwardMatrixw
 A pointer that points per default to the ComplexMatrix that stores the connectinos. More...
 
- Public Attributes inherited from auryn::Connection
SpikingGroupsrc
 Pointer to the source group of this connection. More...
 
NeuronGroupdst
 Pointer to the destination group of this connection. More...
 

Protected Member Functions

void virtual_serialize (boost::archive::binary_oarchive &ar, const unsigned int version)
 
void virtual_serialize (boost::archive::binary_iarchive &ar, const unsigned int version)
 
void free ()
 
void allocate (AurynLong bufsize)
 
std::vector< type_patternload_pattern_file (string filename, int nb_max_patterns)
 Reads patterns from a .pat file and returns a vector with the patterns. More...
 
- Protected Member Functions inherited from auryn::Connection
void init (TransmitterType transmitter=GLUT)
 

Protected Attributes

AurynWeight wmin
 
AurynWeight wmax
 
bool skip_diagonal
 
- Protected Attributes inherited from auryn::Connection
TransmitterType trans
 
AurynStateVectortarget_state_vector
 
AurynFloattarget
 A more direct reference on the first element of the target_state_vector. More...
 
NeuronID number_of_spike_attributes
 Number of spike attributes to expect with each spike transmitted through this connection. More...
 
NeuronID spike_attribute_offset
 Stores spike attribute offset in attribute array. More...
 

Static Protected Attributes

static boost::mt19937 sparse_connection_gen = boost::mt19937()
 

Detailed Description

The base class to create sparse random connections.

This direct derivative of the virtual Connection type is the most commonly used class to create connections in Auryn. It makes use of the ComplexMatrix container to memory efficiently store synaptic weights and to make them easily accessible in a feed-forward manner for spike propagation.

Most plastic connection types such as TripletConnection inherit from SparseConnecion via the intermediate Duplexconnection.

Constructor & Destructor Documentation

◆ SparseConnection() [1/8]

auryn::SparseConnection::SparseConnection ( )

Empty constructor which should not be used – TODO should be deprecated at some point.

◆ SparseConnection() [2/8]

SparseConnection::SparseConnection ( const char *  filename)

Load from wmat file constructor which should not be used – TODO should be deprecated at some point.

35  : Connection()
36 {
37  init();
38  if (! init_from_file(filename) )
39  throw AurynMMFileException();
40 }
Definition: auryn_definitions.h:216
Connection()
Definition: Connection.cpp:30

◆ SparseConnection() [3/8]

SparseConnection::SparseConnection ( NeuronID  rows,
NeuronID  cols 
)

Deprecated constructor for manual filling.

Deprecated:
49  : Connection(rows,cols)
50 {
51  init();
52 }
Connection()
Definition: Connection.cpp:30

◆ SparseConnection() [4/8]

SparseConnection::SparseConnection ( SpikingGroup source,
NeuronGroup destination,
const char *  filename,
TransmitterType  transmitter = GLUT 
)

Deprecated constructor for loading from file.

Deprecated:
42  : Connection(source, destination, transmitter)
43 {
44  init();
45  if (! init_from_file(filename) )
46  throw AurynMMFileException();
47 }
Definition: auryn_definitions.h:216
Connection()
Definition: Connection.cpp:30

◆ SparseConnection() [5/8]

SparseConnection::SparseConnection ( SpikingGroup source,
NeuronGroup destination,
TransmitterType  transmitter = GLUT,
std::string  name = "SparseConnection" 
)

Constructor for manual filling.

59  : Connection(source,destination,transmitter,name)
60 {
61  init();
62  std::stringstream oss;
63  oss << get_log_name() << "Setting up SparseConnection without connecting it. Needs to be manually connected!";
64  auryn::logger->msg(oss.str(),VERBOSE);
65 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Connection()
Definition: Connection.cpp:30
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

◆ SparseConnection() [6/8]

SparseConnection::SparseConnection ( SpikingGroup source,
NeuronGroup destination,
AurynWeight  weight,
AurynDouble  sparseness = 0.05,
TransmitterType  transmitter = GLUT,
std::string  name = "SparseConnection" 
)

Default constructor which sets up a random sparse matrix with fixed weight between the source and destination group.

The constructor takes the weight and sparseness as secondary arguments. The latter allows Auryn to allocate the approximately right amount of memory inadvance. It is good habit to specify at time of initialization also a connection name and the transmitter type. Both can be set separately with set_transmitter and set_name if the function call gets too long and ugly. A connection name is often handy during debugging and the transmitter type is a crucial for obvious resons ...

74  : Connection(source,destination,transmitter,name)
75 {
76  init();
77  std::stringstream oss;
78 
79  AurynLong anticipatedsize = (AurynLong) (estimate_required_nonzero_entires ( sparseness*src->get_pre_size()*dst->get_post_size() ) );
80  oss << get_log_name() << "Assuming memory demand for pre #" << src->get_pre_size() << " and post #" << dst->get_post_size()
81  << std::scientific << std::setprecision(4) << " ( total " << anticipatedsize << ")";
82  auryn::logger->msg(oss.str(),VERBOSE);
83  allocate(anticipatedsize);
84  connect_random(weight,sparseness,skip_diagonal);
85 }
bool skip_diagonal
Definition: SparseConnection.h:107
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Connection()
Definition: Connection.cpp:30
SpikingGroup * src
Pointer to the source group of this connection.
Definition: Connection.h:108
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
AurynLong estimate_required_nonzero_entires(AurynLong nonzero, double sigma=5.)
This function estimates the required size of the nonzero entry buffer.
Definition: SparseConnection.cpp:164
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void allocate(AurynLong bufsize)
Definition: SparseConnection.cpp:175
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
NeuronID get_post_size()
Returns the size on this rank.
Definition: SpikingGroup.cpp:314
void connect_random(AurynWeight weight=1.0, AurynDouble sparseness=0.05, bool skip_diag=false)
Connect src and dst SpikingGroup and NeuronGroup randomly with given sparseness.
Definition: SparseConnection.cpp:487
NeuronID get_pre_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:309
Here is the call graph for this function:

◆ SparseConnection() [7/8]

SparseConnection::SparseConnection ( SpikingGroup source,
NeuronGroup destination,
SparseConnection con,
std::string  name = "SparseConnection" 
)

This constructor tries to clone a connection by guessing all parameters except source and destination from another connection instance.

113  : Connection(source,destination)
114 {
116  AurynDouble sparseness = get_nonzero()/(con->get_m_rows()*con->get_n_cols());
117  AurynDouble mean,std; con->stats(mean,std);
118  AurynLong anticipatedsize = (AurynLong) (estimate_required_nonzero_entires ( sparseness*src->get_pre_size()*dst->get_post_size() ) );
119  allocate(anticipatedsize);
120  connect_random(mean,sparseness,con->skip_diagonal);
121 }
TransmitterType get_transmitter()
Returns transmitter type.
Definition: Connection.cpp:106
bool skip_diagonal
Definition: SparseConnection.h:107
Connection()
Definition: Connection.cpp:30
STL namespace.
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
SpikingGroup * src
Pointer to the source group of this connection.
Definition: Connection.h:108
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
AurynLong estimate_required_nonzero_entires(AurynLong nonzero, double sigma=5.)
This function estimates the required size of the nonzero entry buffer.
Definition: SparseConnection.cpp:164
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
virtual void stats(AurynDouble &mean, AurynDouble &std)
Computes mean and variance of weights in default weight matrix.
Definition: SparseConnection.cpp:618
void allocate(AurynLong bufsize)
Definition: SparseConnection.cpp:175
AurynLong get_nonzero()
Returns number of nonzero elements in this SparseConnection.
Definition: SparseConnection.cpp:949
NeuronID get_post_size()
Returns the size on this rank.
Definition: SpikingGroup.cpp:314
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
void set_transmitter(AurynStateVector *ptr)
Same as set_target.
void connect_random(AurynWeight weight=1.0, AurynDouble sparseness=0.05, bool skip_diag=false)
Connect src and dst SpikingGroup and NeuronGroup randomly with given sparseness.
Definition: SparseConnection.cpp:487
NeuronID get_pre_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:309
Here is the call graph for this function:

◆ SparseConnection() [8/8]

SparseConnection::SparseConnection ( SpikingGroup source,
NeuronGroup destination,
AurynWeight  weight,
AurynDouble  sparseness,
NeuronID  lo_row,
NeuronID  hi_row,
NeuronID  lo_col,
NeuronID  hi_col,
TransmitterType  transmitter = GLUT 
)

Sparse block constructor.

This constructor initializes the connection with random sparse weights, but only fills a "block" as specified instead of the entire matrix.

96  : Connection(source,destination,transmitter)
97 {
98  NeuronID rows = hi_row - lo_row;
99  NeuronID cols = hi_col - lo_col;
100  init();
101  allocate((AurynLong) ( estimate_required_nonzero_entires( sparseness*rows*cols ) ));
102  w->clear();
103  connect_block_random(weight,sparseness,lo_row,hi_row,lo_col,hi_col,skip_diagonal);
104  finalize();
105 }
bool skip_diagonal
Definition: SparseConnection.h:107
Connection()
Definition: Connection.cpp:30
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
void connect_block_random(AurynWeight weight, AurynDouble sparseness, NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, bool skip_diag=false)
Underlying sparse fill method.
Definition: SparseConnection.cpp:360
AurynLong estimate_required_nonzero_entires(AurynLong nonzero, double sigma=5.)
This function estimates the required size of the nonzero entry buffer.
Definition: SparseConnection.cpp:164
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void clear()
Clears matrix.
Definition: ComplexMatrix.h:460
void allocate(AurynLong bufsize)
Definition: SparseConnection.cpp:175
virtual void finalize()
Finalizes connection after random or manual initialization of the weights.
Definition: SparseConnection.cpp:499
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ ~SparseConnection()

SparseConnection::~SparseConnection ( )
virtual

The default destructor.

124 {
125  free();
126 }
void free()
Definition: SparseConnection.cpp:169
Here is the call graph for this function:

Member Function Documentation

◆ allocate()

void SparseConnection::allocate ( AurynLong  bufsize)
protected

Allocates memory for a given sparse connectivity matrix. Usually ComplexMatrix or ComplexMatrix

176 {
177  NeuronID m = get_m_rows();
178  NeuronID n = get_n_cols();
179 
180  std::stringstream oss;
181  oss << get_log_name() << "Allocating sparse matrix (" << m << ", " << n << ") with space for " << std::scientific << std::setprecision(4) << (double) bufsize << " nonzero elements ";
182 
183  auryn::logger->msg(oss.str(),VERBOSE);
184 
185  AurynLong maxsize = m*n;
186 
187  w = new ForwardMatrix ( m, n , std::min(maxsize,bufsize) );
188 
189  has_been_allocated = true;
190 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
int n
Definition: mkpat.py:5
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
ComplexMatrix< AurynWeight > ForwardMatrix
Definition: SparseConnection.h:52
Here is the call graph for this function:

◆ allocate_manually()

void SparseConnection::allocate_manually ( AurynLong  expected_size)

Is used whenever memory has to be allocated manually. Automatically adjusts for number of ranks and for security margin.

193 {
195  allocate( estimate_required_nonzero_entires ( dilution*expected_size ) );
196 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
AurynLong estimate_required_nonzero_entires(AurynLong nonzero, double sigma=5.)
This function estimates the required size of the nonzero entry buffer.
Definition: SparseConnection.cpp:164
void allocate(AurynLong bufsize)
Definition: SparseConnection.cpp:175
NeuronID get_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:304
Here is the call graph for this function:

◆ clip()

void SparseConnection::clip ( AurynWeight  lo,
AurynWeight  hi 
)
virtual

Clip weights.

1148 {
1149  for ( AurynWeight * ptr = w->get_data_begin() ; ptr != w->get_data_end() ; ++ptr ) {
1150  if ( *ptr < lo )
1151  *ptr = lo;
1152  else
1153  if ( *ptr > hi )
1154  *ptr = hi;
1155  }
1156 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
T * get_data_end(const StateID z=0)
Returns pointer to data value corresponding to the element behind the last nonzero element...
Definition: ComplexMatrix.h:977
Here is the call graph for this function:

◆ connect_block_random()

void SparseConnection::connect_block_random ( AurynWeight  weight,
AurynDouble  sparseness,
NeuronID  lo_row,
NeuronID  hi_row,
NeuronID  lo_col,
NeuronID  hi_col,
bool  skip_diag = false 
)

Underlying sparse fill method.

Set dist_optimized to false and seed all ranks the same to get the same matrix independent of the number of ranks. Called internally or when you know what you are doing.

367 {
368  // do some sanity checks
369  if ( sparseness <= 0.0 ) {
370  auryn::logger->msg("Trying to set up a SparseConnection with sparseness smaller or equal to zero, which doesn't make sense",ERROR);
371  throw AurynGenericException();
372  }
373  if ( sparseness > 1.0 ) {
374  auryn::logger->msg("Sparseness larger than 1 not allowed. Setting to 1.",WARNING);
375  sparseness = 1.0;
376  }
377 
378  if ( weight < get_min_weight() ) {
379  auryn::logger->msg("Weight smaller than minimal weight. Updating minimal weight and proceeding.",WARNING);
380  set_min_weight(weight);
381  }
382 
383  int r = 0; // these variables are used to speed up building the matrix if the destination is distributed
384  int s = 1;
385 
386  r = sys->mpi_rank()-dst->get_locked_rank();
387  s = dst->get_locked_range();
388 
389  // correction for "refractoriness"
390  double lambda = 1.0/(1.0/sparseness-1.0);
391  boost::exponential_distribution<> dist(lambda);
392  boost::variate_generator<boost::mt19937&, boost::exponential_distribution<> > die(SparseConnection::sparse_connection_gen, dist);
393 
394  if (!has_been_allocated)
396 
397  AurynLong idim = (hi_row-lo_row);
398  AurynLong jdim = (hi_col-lo_col)/s;
399  if ( (hi_col-lo_col)%s > r ) { // some ranks have one more "carry" neuron
400  jdim += 1;
401  }
402 
403  // we keep track of the real valued jump size ...
404  AurynDouble jump = 0.0;
405  // ... and the discretized position along the weight matrix
406  AurynLong x = (AurynLong) die();
407 
408  if ( sparseness == 1.0 ) x = 0; // for dense matrices
409  AurynLong stop = idim*jdim;
410  AurynLong count = 0;
411  NeuronID i = 0;
412  NeuronID j = 0;
413  while ( x < stop ) {
414  i = lo_row+x/jdim;
415  j = lo_col + s*(x%jdim) + r; // be carfule with this line ... it already was the cause of a lot of headaches
416  if ( (j >= lo_col) && (!skip_diag || i!=j)) {
417  try {
418  if ( push_back(i,j,weight) )
419  count++;
420  }
422  {
423  std::stringstream oss;
424  oss << get_log_name()
425  <<"Trying to add elements outside of matrix (i="
426  << i
427  << "j="
428  << j
429  << ", "
430  << count
431  << "th element) ";
432  auryn::logger->msg(oss.str(),ERROR);
433  return;
434  }
436  {
437  std::stringstream oss;
438  oss << get_log_name()
439  << "Failed pushing back element. Maybe due to out of order pushing? "
440  << " (" << i << "," << j << ") "
441  << " with count=" << count
442  << " in connect_block_random ( fill_level= " << w->get_fill_level() << " )";
443  auryn::logger->msg(oss.str(),ERROR);
444  return;
445  }
447  {
448  std::stringstream oss;
449  oss << get_log_name()
450  <<"Buffer full after pushing "
451  << count
452  << " elements."
453  << " There are pruned connections!";
454  auryn::logger->msg(oss.str(),ERROR);
455  return;
456  }
457  }
458 
459  if ( sparseness < 1.0 ) {
460  // here we add our random exponential jump which was corrected
461  // for the 1.0 "refractory period" to account for the fact that
462  // we can have only one connection per "slot"
463  jump += die()+1.0;
464 
465  // here we discretize this jump
466  AurynLong discrete_jump = jump;
467 
468  // but keep the rest for the next jump to avoid discretization biases
469  jump -= discrete_jump;
470 
471  // now we added discrete_jump to x and we are ready for the next connection
472  x += discrete_jump;
473  } else { // dense matrices
474  x += 1 ;
475  }
476  }
477 
478  std::stringstream oss;
479  oss << get_log_name() << "Finished connect_block_random ["
480  << lo_row << ", " << hi_row << ", " << lo_col << ", " << hi_col << "] " << " (stop count "
481  << std::scientific << std::setprecision(4) << (double) stop
482  << ") and successfully pushed " << (double) count << " entries. "
483  << "Resulting overall sparseness " << 1.*get_nonzero()/src->get_pre_size()/dst->get_post_size();
484  auryn::logger->msg(oss.str(),VERBOSE);
485 }
r
Definition: mkpat.py:9
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
AurynDouble get_fill_level()
Returns the fill level of the matrix element buffer.
Definition: ComplexMatrix.h:984
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
unsigned int mpi_rank()
Returns current rank.
Definition: System.cpp:1009
Definition: auryn_definitions.h:297
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
SpikingGroup * src
Pointer to the source group of this connection.
Definition: Connection.h:108
Definition: Logger.h:41
bool push_back(NeuronID i, NeuronID j, AurynWeight weight)
Pushes a single element to the ComplexMatrix.
Definition: SparseConnection.cpp:515
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
AurynWeight get_min_weight()
Gets minimum weight (for plastic connections).
Definition: SparseConnection.h:412
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
Definition: Logger.h:41
Definition: auryn_definitions.h:240
virtual void set_min_weight(AurynWeight minimum_weight)
Sets minimum weight (for plastic connections).
Definition: SparseConnection.cpp:198
Definition: auryn_definitions.h:256
unsigned int get_locked_range()
Returns locked range of ranks for SpikingGroups which are not distributed across all ranks...
Definition: SpikingGroup.cpp:334
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: auryn_definitions.h:224
AurynLong get_nonzero()
Returns number of nonzero elements in this SparseConnection.
Definition: SparseConnection.cpp:949
NeuronID get_post_size()
Returns the size on this rank.
Definition: SpikingGroup.cpp:314
static boost::mt19937 sparse_connection_gen
Definition: SparseConnection.h:91
Definition: auryn_definitions.h:248
unsigned int get_locked_rank()
Returns locked rank for SpikingGroups which are not distributed across all ranks. ...
Definition: SpikingGroup.cpp:329
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID get_pre_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:309
Here is the call graph for this function:

◆ connect_random()

void SparseConnection::connect_random ( AurynWeight  weight = 1.0,
AurynDouble  sparseness = 0.05,
bool  skip_diag = false 
)

Connect src and dst SpikingGroup and NeuronGroup randomly with given sparseness.

This function should be usually called from the constructor directly.

488 {
489  if ( dst->evolve_locally() ) { // if there are no local units there is no need for synapses
490  std::stringstream oss;
491  oss << get_log_name() <<"Randomfill with weight "<< weight << " and sparseness " << sparseness;
492  auryn::logger->msg(oss.str(),VERBOSE);
493  w->clear();
494  connect_block_random(weight,sparseness,0,get_m_rows(),0,get_n_cols(),skip_diag);
495  }
496  finalize();
497 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
void connect_block_random(AurynWeight weight, AurynDouble sparseness, NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, bool skip_diag=false)
Underlying sparse fill method.
Definition: SparseConnection.cpp:360
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
void clear()
Clears matrix.
Definition: ComplexMatrix.h:460
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
virtual void finalize()
Finalizes connection after random or manual initialization of the weights.
Definition: SparseConnection.cpp:499
Here is the call graph for this function:

◆ estimate_required_nonzero_entires()

AurynLong SparseConnection::estimate_required_nonzero_entires ( AurynLong  nonzero,
double  sigma = 5. 
)

This function estimates the required size of the nonzero entry buffer.

It's typicall used internally or when you know what you are doing.

165 {
166  return std::min( (AurynLong)( nonzero + sigma*sqrt(1.0*nonzero) ), (AurynLong)(get_m_rows()*get_n_cols()) ) ;
167 }
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
Here is the call graph for this function:

◆ finalize()

void SparseConnection::finalize ( )
virtual

Finalizes connection after random or manual initialization of the weights.

Essentially pads zeros or non-existing elements at the end of ComplexMatrix. Called interally or after manually filling matrices.

Implements auryn::Connection.

Reimplemented in auryn::TripletConnection, auryn::LPTripletConnection, auryn::MinimalTripletConnection, auryn::STDPwdConnection, auryn::TripletScalingConnection, auryn::STDPConnection, and auryn::DuplexConnection.

500 {
501  w->fill_na();
502  if ( dst->evolve_locally() ) {
503  std::stringstream oss;
504  oss << get_log_name() << "Finalized with fill level " << w->get_fill_level();
505  auryn::logger->msg(oss.str(),VERBOSE);
507  {
508  std::stringstream oss2;
509  oss2 << get_log_name() <<"Wasteful fill level (" << w->get_fill_level() << ")! Make sure everything is in order!";
510  auryn::logger->msg(oss2.str(),WARNING);
511  }
512  }
513 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
AurynDouble get_fill_level()
Returns the fill level of the matrix element buffer.
Definition: ComplexMatrix.h:984
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
Definition: Logger.h:41
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
void fill_na()
Pads non-existing elements for the remaining elements to a matrix.
Definition: ComplexMatrix.h:676
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
#define WARN_FILL_LEVEL
Definition: SparseConnection.h:48
Here is the call graph for this function:

◆ free()

void SparseConnection::free ( )
protected
170 {
171  delete w;
172 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147

◆ get()

AurynWeight SparseConnection::get ( NeuronID  i,
NeuronID  j 
)
virtual

Returns weight value of a given element if it exists.

Implements auryn::Connection.

667 {
668  return w->get(i,j);
669 }
T get(const NeuronID i, const NeuronID j, const NeuronID z=0)
Value of synaptic state variable i,j,z returns zero if the element is zero or does not exist...
Definition: ComplexMatrix.h:824
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
Here is the call graph for this function:

◆ get_block()

std::vector< neuron_pair > SparseConnection::get_block ( NeuronID  lo_row,
NeuronID  hi_row,
NeuronID  lo_col,
NeuronID  hi_col 
)

Returns a vector of ConnectionsID of a block specified by the arguments.

1101 {
1102  std::vector<neuron_pair> clist;
1103  for ( NeuronID i = 0 ; i < get_m_rows() ; ++i )
1104  {
1105  for ( NeuronID * j = w->get_row_begin(i) ; j != w->get_row_end(i) ; ++j )
1106  {
1107  if (i >= lo_row && i < hi_row && *j >= lo_col && *j < hi_col ) {
1108  neuron_pair a;
1109  a.i = i;
1110  a.j = *j;
1111  clist.push_back( a );
1112  }
1113  }
1114  }
1115  return clist;
1116 }
Struct that defines a pair of neurons in SparseConnection.
Definition: auryn_definitions.h:167
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
NeuronID i
Definition: auryn_definitions.h:168
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID j
Definition: auryn_definitions.h:168
Here is the call graph for this function:

◆ get_data()

AurynWeight SparseConnection::get_data ( NeuronID  i)
virtual

Returns weight value of a given element referenced by index in the data array.

Implements auryn::Connection.

657 {
658  return w->get_data(i);
659 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
T get_data(AurynLong i, StateID z=0)
Definition: ComplexMatrix.h:408
Here is the call graph for this function:

◆ get_max_weight()

AurynWeight auryn::SparseConnection::get_max_weight ( )
inline

Gets maximum weight (for plastic connections).

420  {
421  return wmax;
422  };
AurynWeight wmax
Definition: SparseConnection.h:103
Here is the call graph for this function:

◆ get_min_weight()

AurynWeight auryn::SparseConnection::get_min_weight ( )
inline

Gets minimum weight (for plastic connections).

412  {
413  return wmin;
414  };
AurynWeight wmin
Definition: SparseConnection.h:97
Here is the call graph for this function:

◆ get_nonzero()

AurynLong SparseConnection::get_nonzero ( )
virtual

Returns number of nonzero elements in this SparseConnection.

Implements auryn::Connection.

950 {
951  return w->get_nonzero();
952 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Here is the call graph for this function:

◆ get_post_partners()

std::vector< neuron_pair > SparseConnection::get_post_partners ( NeuronID  i)

Returns a vector of ConnectionsID of postsynaptic parterns of neuron i.

1119 {
1120  std::vector<neuron_pair> clist;
1121  for ( NeuronID * j = w->get_row_begin(i) ; j != w->get_row_end(i) ; ++j )
1122  {
1123  neuron_pair a;
1124  a.i = i;
1125  a.j = *j;
1126  clist.push_back( a );
1127  }
1128  return clist;
1129 }
Struct that defines a pair of neurons in SparseConnection.
Definition: auryn_definitions.h:167
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
NeuronID i
Definition: auryn_definitions.h:168
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID j
Definition: auryn_definitions.h:168
Here is the call graph for this function:

◆ get_pre_partners()

std::vector< neuron_pair > SparseConnection::get_pre_partners ( NeuronID  j)

Returns a vector of ConnectionsID of presynaptic parterns of neuron i.

1132 {
1133  std::vector<neuron_pair> clist;
1134  for ( NeuronID i = 0 ; i < get_m_rows() ; ++i )
1135  {
1136  if ( get_ptr(i,j) != NULL ) {
1137  neuron_pair a;
1138  a.i = i;
1139  a.j = j;
1140  clist.push_back( a );
1141  }
1142  }
1143  return clist;
1144 }
Struct that defines a pair of neurons in SparseConnection.
Definition: auryn_definitions.h:167
NeuronID i
Definition: auryn_definitions.h:168
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
virtual AurynWeight * get_ptr(NeuronID i, NeuronID j)
Returns pointer to given weight element if it exists. Returns NULL if element does not exist...
Definition: SparseConnection.cpp:671
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID j
Definition: auryn_definitions.h:168
Here is the call graph for this function:

◆ get_ptr()

AurynWeight * SparseConnection::get_ptr ( NeuronID  i,
NeuronID  j 
)
virtual

Returns pointer to given weight element if it exists. Returns NULL if element does not exist.

Implements auryn::Connection.

672 {
673  return w->get_ptr(i,j);
674 }
T * get_ptr(const NeuronID i, const NeuronID j, const StateID z=0)
Returns the pointer to a particular element.
Definition: ComplexMatrix.h:814
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
Here is the call graph for this function:

◆ init_random_binary()

void SparseConnection::init_random_binary ( AurynFloat  prob = 0.5,
AurynWeight  wlo = 0.0,
AurynWeight  whi = 1.0 
)

Initialize with random binary at wlo and whi.

Parameters
wloThe lower weight value.
whiThe higher weight value.
probthe probability for the higher value.
251 {
252  std::stringstream oss;
253  oss << get_log_name() << "randomizing non-zero connections (gaussian) with binary weights between "
254  << wlo << " and " << whi ;
255  auryn::logger->msg(oss.str(),NOTIFICATION);
256 
257  boost::uniform_real<> dist(0.0, 1.0);
258  boost::variate_generator<boost::mt19937&, boost::uniform_real<> > die(SparseConnection::sparse_connection_gen, dist);
259  AurynWeight rv;
260 
261  for ( AurynLong i = 0 ; i<w->get_nonzero() ; ++i ) {
262  rv = die();
263  if ( rv<prob ) {
264  w->set_data(i,whi);
265  } else {
266  w->set_data(i,wlo);
267  }
268  }
269 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
Definition: Logger.h:41
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void set_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:441
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
static boost::mt19937 sparse_connection_gen
Definition: SparseConnection.h:91
Here is the call graph for this function:

◆ load_from_complete_file()

bool SparseConnection::load_from_complete_file ( std::string  filename)
virtual

Loads weight matrix from a single file.

Since a single file might contain a lot more elements than memory required this function performs a dry run during which it counts the required number of elements. This function should be optimized to avoid on large clusters the complete hammering of the fileserver. An idea would be to let one rank do all the work and distribute the established file-counts to all the stations

922 {
923  AurynLong datasize = dryrun_from_file(filename);
924  std::stringstream oss;
925  oss << "Loading from complete wmat file "
926  << "(all ranks in the same file). Element count: "
927  << datasize
928  << ".";
929  auryn::logger->msg(oss.str(),NOTIFICATION);
930  bool returnvalue = load_from_file(w,filename,datasize);
931  finalize();
932  return returnvalue;
933 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
Definition: Logger.h:41
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
virtual bool load_from_file(string filename)
Loads weight matrix from Matrix Market (wmat) file.
Definition: SparseConnection.cpp:935
virtual void finalize()
Finalizes connection after random or manual initialization of the weights.
Definition: SparseConnection.cpp:499
Here is the call graph for this function:

◆ load_from_file() [1/2]

bool SparseConnection::load_from_file ( std::string  filename)
virtual

Loads weight matrix from Matrix Market (wmat) file.

This function expects an Auryn readable Matrix Market file such as generated by write_to_file methods which only includes weight elements which belong on this very rank. To load wmat files containing all weights indepent of rank use the load_from_complete_file method. Note that these methods only store information of the first element of a ComplexMatrix. To store all informtion of a ComplexMatrix use the mechanisms in place to save the network state which are implemented in the System class.

Implements auryn::Connection.

Reimplemented in auryn::RateModulatedConnection.

936 {
937  bool result = load_from_file(w,filename);
938  finalize();
939  return result;
940 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
virtual bool load_from_file(string filename)
Loads weight matrix from Matrix Market (wmat) file.
Definition: SparseConnection.cpp:935
virtual void finalize()
Finalizes connection after random or manual initialization of the weights.
Definition: SparseConnection.cpp:499
Here is the call graph for this function:

◆ load_from_file() [2/2]

bool SparseConnection::load_from_file ( ForwardMatrix m,
std::string  filename,
AurynLong  data_size = 0 
)

Loads weight matrix from Matrix Market (wmat) file to specified weight matrix.

This function expects an Auryn readable Matrix Market file such as generated by write_to_file methods which only includes weight elements which belong on this very rank. To load wmat files containing all weights indepent of rank use the load_from_complete_file method.

784 {
785  if ( !dst->evolve_locally() ) return true;
786 
787  char buffer[256];
788  std::ifstream infile (filename.c_str());
789  if (!infile) {
790  std::stringstream oss;
791  oss << get_log_name() << "Can't open input file " << filename;
792  auryn::logger->msg(oss.str(),ERROR);
793  throw AurynOpenFileException();
794  }
795 
796  set_name(filename);
797 
798  NeuronID i,j;
799  AurynLong k;
800  unsigned int count = 0;
801  unsigned int pushback_count = 0;
802  float val;
803 
804  // read connection details
805  infile.getline (buffer,256); count++;
806  std::string header("%%MatrixMarket matrix coordinate real general");
807  if (header.compare(buffer)!=0)
808  {
809  std::stringstream oss;
810  oss << get_log_name() << "Input format not recognized.";
811  auryn::logger->msg(oss.str(),ERROR);
812  return false;
813  }
814  while ( buffer[0]=='%' ) {
815  infile.getline (buffer,256);
816  count++;
817  }
818 
819  sscanf (buffer,"%u %u %lu",&i,&j,&k);
820  set_size(i,j);
821 
822  if ( data_size ) {
823  k = data_size;
824  }
825 
826  if ( m->get_datasize() >= k ) {
827  m->clear();
828  } else {
829  std::stringstream oss;
830  oss << get_log_name() << "Buffer too small ("
831  << m->get_datasize()
832  << " -> "
833  << k
834  << " elements). Reallocating.";
835  auryn::logger->msg(oss.str() ,NOTIFICATION);
837  }
838 
839  std::stringstream oss;
840  oss << get_name()
841  << ": Reading from file ("
842  << get_m_rows()<<"x"<<get_n_cols()
843  << " @ "<<1.*k/(src->get_size()*dst->get_rank_size())<<")";
844  auryn::logger->msg(oss.str(),NOTIFICATION);
845 
846 
847  while ( infile.getline (buffer,255) )
848  {
849  count++;
850  sscanf (buffer,"%u %u %e",&i,&j,&val);
851  try {
852  if ( dst->localrank(j-1) ) {
853  m->push_back(i-1,j-1,val);
854  pushback_count++;
855  }
856  }
858  {
859  std::stringstream oss;
860  oss << get_log_name() << "Push back failed. Error in line=" << count << ", "
861  << " i=" << i
862  << " j=" << j
863  << " v=" << val << ". "
864  << " After pushing " << pushback_count << " elements. "
865  << " Bad row major order?";
866  auryn::logger->msg(oss.str(),ERROR);
867  throw AurynMMFileException();
868  return false;
869  }
871  {
872  std::stringstream oss;
873  oss << get_name()
874  << ": Buffer full after pushing "
875  << count << " elements."
876  << " There are pruned connections!";
877  auryn::logger->msg(oss.str(),ERROR);
878  return false;
879  }
881  {
882  std::stringstream oss;
883  oss << get_log_name()
884  <<"Trying to add elements outside of matrix (i="
885  << i
886  << ", j="
887  << j
888  << ", "
889  << count
890  << "th element) ";
891  auryn::logger->msg(oss.str(),ERROR);
892  return false;
893  }
894  }
895 
896 
897  infile.close();
898 
899  if ( pushback_count != m->get_nonzero() ) { // this should never happen without an exception above, but better be save than sorry
900  oss.str("");
901  oss << get_log_name()
902  << pushback_count
903  << " elements pushed, but only "
904  << m->get_nonzero()
905  << " in matrix matrix.";
906  auryn::logger->msg(oss.str(),ERROR);
907  } else {
908  oss.str("");
909  oss << get_log_name() << "OK, "
910  << pushback_count
911  << " elements pushed.";
912  auryn::logger->msg(oss.str(),VERBOSE);
913  }
914 
915  m->fill_na();
916  // finalize(); // commented this line out because it only acts on w
917 
918  return true;
919 }
NeuronID get_rank_size()
Returns the size on this rank.
Definition: SpikingGroup.h:450
Definition: auryn_definitions.h:216
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
SpikingGroup * src
Pointer to the source group of this connection.
Definition: Connection.h:108
Definition: Logger.h:41
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Definition: auryn_definitions.h:208
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
void fill_na()
Pads non-existing elements for the remaining elements to a matrix.
Definition: ComplexMatrix.h:676
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void clear()
Clears matrix.
Definition: ComplexMatrix.h:460
Definition: Logger.h:41
void resize_buffer_and_clear(AurynLong size)
Resizes buffer and clears the matrix. This saves to copy all the data.
Definition: ComplexMatrix.h:555
Definition: auryn_definitions.h:240
void push_back(const NeuronID i, const NeuronID j, const T value)
Definition: ComplexMatrix.h:627
NeuronID get_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:304
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: auryn_definitions.h:224
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
Definition: auryn_definitions.h:248
std::string get_name()
Returns name of connection.
Definition: Connection.cpp:87
void set_size(NeuronID i, NeuronID j)
Definition: Connection.cpp:71
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
void set_name(std::string name)
Set name of connection.
Definition: Connection.cpp:82
Here is the call graph for this function:

◆ load_pattern_file()

std::vector< type_pattern > SparseConnection::load_pattern_file ( string  filename,
int  nb_max_patterns 
)
protected

Reads patterns from a .pat file and returns a vector with the patterns.

Parameters
filenameThe file to load
nb_max_patternsThe maximum number of patterns to load.
Returns
A vector with elements of type_pattern. Returns an empty vector on file error.
993 {
994  std::vector<type_pattern> patterns;
995 
996  std::ifstream fin (filename.c_str());
997  if (!fin) {
998  std::stringstream oss2;
999  oss2 << get_log_name() << "There was a problem opening file " << filename << " for reading.";
1000  auryn::logger->msg(oss2.str(),WARNING);
1001  return patterns;
1002  } else {
1003  std::stringstream oss;
1004  oss << get_log_name() << "Loading patterns from " << filename << " ...";
1005  auryn::logger->msg(oss.str(),NOTIFICATION);
1006  }
1007 
1008  unsigned int patcount = 0 ;
1009 
1010  NeuronID mindimension = std::min( get_m_rows()*patterns_every_pre, get_n_cols()*patterns_every_post );
1011  bool istoolarge = false;
1012 
1013 
1014  type_pattern pattern;
1015  char buffer[256];
1016  std::string line;
1017 
1018  while(!fin.eof()) {
1019  line.clear();
1020  fin.getline (buffer,255);
1021  line = buffer;
1022 
1023  if(line[0] == '#') continue;
1024  if ( patcount >= nb_max_patterns ) break;
1025  if (line == "") {
1026  if ( pattern.size() > 0 ) {
1027  // put_pattern( &pattern, strength, overwrite );
1028  patterns.push_back(pattern);
1029  patcount++;
1030  pattern.clear();
1031  }
1032  continue;
1033  }
1034 
1035  pattern_member pm;
1036  std::stringstream iss (line);
1037  pm.gamma = 1 ;
1038  iss >> pm.i ;
1039  if ( !wrap_patterns && !istoolarge && pm.i > mindimension ) {
1040  std::stringstream oss;
1041  oss << get_log_name() << "Some elements of pattern " << patcount << " are larger than the underlying NeuronGroups!";
1042  auryn::logger->msg(oss.str(),WARNING);
1043  istoolarge = true;
1044  }
1045  iss >> pm.gamma ;
1046  if ( patterns_ignore_gamma )
1047  pm.gamma = 1;
1048  pattern.push_back(pm) ;
1049  }
1050 
1051  fin.close();
1052 
1053  return patterns;
1054 }
NeuronID i
Definition: auryn_definitions.h:173
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Definition: Logger.h:41
bool patterns_ignore_gamma
Switch that toggles for the load_patterns function whether or not to use the intensity (gamma) value...
Definition: SparseConnection.h:126
Definition: Logger.h:41
NeuronID patterns_every_post
The every_post parameter allows to skip postsynaptically over pattern IDs when loading patterns...
Definition: SparseConnection.h:138
std::vector< pattern_member > type_pattern
Definition: auryn_definitions.h:177
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
bool wrap_patterns
Switch that toggles the behavior when loading a pattern to wrap neuron IDs back onto existing cells v...
Definition: SparseConnection.h:143
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
AurynDouble gamma
Definition: auryn_definitions.h:174
NeuronID patterns_every_pre
The every_pre parameter allows to skip presynaptically over pattern IDs when loading patterns...
Definition: SparseConnection.h:132
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Struct used to define neuronal assembly patterns in SparseConnection.
Definition: auryn_definitions.h:172
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ load_patterns()

void SparseConnection::load_patterns ( std::string  filename,
AurynWeight  strength,
int  nb_max_patterns = 10000,
bool  overwrite = false,
bool  chainmode = false 
)

Reads first n patterns from a .pat file and adds them as Hebbian assemblies onto an existing weight matrix.

Parameters
filenameThe file to read the patterns from
strengthThe strength to set or add to connections within a pattern (depending on setting of overwrite)
nb_max_patternsThe maximum number of patterns to load (default 10000)
overwriteWhether to add strength to each connection in the pattern or whether to set the connection to he value specified (default false)
chainmodeIf set to true the function does not create cell assemblies but a synfire chain architecture in which each pattern is connected to the next as a chain.
1058 {
1059  std::vector<type_pattern> patterns = load_pattern_file( filename, nb_max_patterns );
1060 
1061  if ( chainmode ) {
1062  for ( int i = 0 ; i < patterns.size()-1 ; ++i ) {
1063  put_pattern( &(patterns[i]), &(patterns[i+1]), strength, overwrite );
1064  }
1065  } else {
1066  for ( int i = 0 ; i < patterns.size() ; ++i ) {
1067  put_pattern( &(patterns[i]), strength, overwrite );
1068  }
1069  }
1070 
1071  // put_pattern( &pattern, strength );
1072 
1073  std::stringstream oss;
1074  oss << get_log_name() << "Added " << patterns.size() << " patterns";
1075  auryn::logger->msg(oss.str(),NOTIFICATION);
1076 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Definition: Logger.h:41
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
void put_pattern(type_pattern *pattern, AurynWeight strength, bool overwrite)
Puts cell assembly to existing sparse weights.
Definition: SparseConnection.cpp:954
std::vector< type_pattern > load_pattern_file(string filename, int nb_max_patterns)
Reads patterns from a .pat file and returns a vector with the patterns.
Definition: SparseConnection.cpp:992
Here is the call graph for this function:

◆ load_pre_post_patterns()

void SparseConnection::load_pre_post_patterns ( std::string  pre_file,
std::string  post_file,
AurynWeight  strength,
int  nb_max_patterns = 10000,
bool  overwrite = false 
)

Reads patterns from two files and connects them.

Parameters
pre_fileFile containint the presynaptic patterns
post_fileFile containint the postsynaptic patterns
strengthSynaptic strength value of a connection
nb_max_patternsThe maximum number of patterns to load (default 10000)
overwriteWhether to add or set strength to each connection (default false)

This function can be used to connect a bunch of populations in one group to different populations in another group. The two pattern files must have the same number of patterns stored.

1080 {
1081  std::vector<type_pattern> pre_patterns = load_pattern_file( pre_file, nb_max_patterns );
1082  std::vector<type_pattern> post_patterns = load_pattern_file( post_file, nb_max_patterns );
1083 
1084  // check if both files supplied the same number of patterns
1085  if ( pre_patterns.size() != post_patterns.size() ) {
1086  auryn::logger->error("Error loading patterns. Number of patterns in prefile and postfile does not match. Aborting.");
1087  return;
1088  }
1089 
1090  for ( int i = 0 ; i < pre_patterns.size() ; ++i ) {
1091  put_pattern( &(pre_patterns[i]), &(post_patterns[i]), strength, overwrite );
1092  }
1093 
1094  std::stringstream oss;
1095  oss << get_log_name() << "Added " << pre_patterns.size() << " patterns";
1096  auryn::logger->msg(oss.str(),NOTIFICATION);
1097 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Definition: Logger.h:41
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
void error(std::string text)
Definition: Logger.cpp:141
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
void put_pattern(type_pattern *pattern, AurynWeight strength, bool overwrite)
Puts cell assembly to existing sparse weights.
Definition: SparseConnection.cpp:954
std::vector< type_pattern > load_pattern_file(string filename, int nb_max_patterns)
Reads patterns from a .pat file and returns a vector with the patterns.
Definition: SparseConnection.cpp:992
Here is the call graph for this function:

◆ propagate()

void SparseConnection::propagate ( )
virtual

Internally used propagate method.

This method propagates spikes in the main simulation loop. Should usually not be called directly by the user.

Implements auryn::Connection.

Reimplemented in auryn::TripletConnection, auryn::LPTripletConnection, auryn::MinimalTripletConnection, auryn::STPConnection, auryn::TripletScalingConnection, auryn::STDPwdConnection, auryn::RateModulatedConnection, auryn::PairInteractionConnection, auryn::SymmetricSTDPConnection, auryn::DelayConnection, auryn::STDPConnection, auryn::ABSConnection, and auryn::TripletDecayConnection.

525 {
526  for (SpikeContainer::const_iterator spike = src->get_spikes()->begin() ;
527  spike != src->get_spikes()->end() ;
528  ++spike ) {
529  for ( AurynLong c = w->get_row_begin_index(*spike) ;
530  c < w->get_row_end_index(*spike) ;
531  ++c ) {
532  transmit( w->get_colind(c) , w->get_value(c) );
533  }
534  }
535 }
void transmit(const NeuronID id, const AurynWeight amount)
Default way to transmit a spike to a postsynaptic partner.
Definition: Connection.h:294
AurynLong get_row_begin_index(NeuronID i)
Definition: ComplexMatrix.h:946
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
SpikeContainer * get_spikes()
Returns pointer to a spike container that contains spikes which arrive in this timestep from all neur...
Definition: SpikingGroup.cpp:245
T get_value(const AurynLong data_index)
Returns the data value to an item that is i-th in the colindex array.
Definition: ComplexMatrix.h:841
SpikingGroup * src
Pointer to the source group of this connection.
Definition: Connection.h:108
AurynLong get_row_end_index(NeuronID i)
Definition: ComplexMatrix.h:958
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
NeuronID get_colind(const AurynLong data_index)
Definition: ComplexMatrix.h:853
Here is the call graph for this function:

◆ push_back()

bool SparseConnection::push_back ( NeuronID  i,
NeuronID  j,
AurynWeight  weight 
)

Pushes a single element to the ComplexMatrix.

Note that Auryn sparse matrices need to be filled row by row in column increasing order (similar to writing in a text document). Hence, usually this function is called internally during weight initialization through a connect_random method. However, it can also be invoked manually to build custum weight matrices on the fly. The recommended method however is to build specific weight matrices in another high level programming language such as Python and to save the in the Auryn specific Matrix Market format which can then be loaded using load_from_file or load_from_complete_file methods.

516 {
517  if ( dst->localrank(j) ) {
518  w->push_back(i,j,weight);
519  return true;
520  }
521  return false;
522 }
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
void push_back(const NeuronID i, const NeuronID j, const T value)
Definition: ComplexMatrix.h:627
Here is the call graph for this function:

◆ put_pattern() [1/2]

void SparseConnection::put_pattern ( type_pattern pattern,
AurynWeight  strength,
bool  overwrite 
)

Puts cell assembly to existing sparse weights.

TODO add more explanation here.

955 {
956  std::stringstream oss;
957  oss << get_log_name() << "Putting assembly ( size " << pattern->size() << " )";
958  auryn::logger->msg(oss.str(),VERBOSE);
959 
960  put_pattern( pattern, pattern, strength, overwrite );
961 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
void put_pattern(type_pattern *pattern, AurynWeight strength, bool overwrite)
Puts cell assembly to existing sparse weights.
Definition: SparseConnection.cpp:954
Here is the call graph for this function:

◆ put_pattern() [2/2]

void SparseConnection::put_pattern ( type_pattern pattern1,
type_pattern pattern2,
AurynWeight  strength,
bool  overwrite 
)

Puts cell assembly or synfire pattern to existing sparse weights.

TODO add more explanation here.

964 {
965  type_pattern::iterator iter_pre,iter_post;
966  for ( iter_post = pattern2->begin() ; iter_post != pattern2->end() ; ++iter_post ) {
967  if ( (*iter_post).i%patterns_every_post != 0 ) continue;
968  NeuronID j = (*iter_post).i/patterns_every_post;
969  if ( wrap_patterns )
970  j = j % get_n_cols();
971  if ( j < dst->get_size() && dst->localrank( j ) ) {
972  for ( iter_pre = pattern1->begin() ; iter_pre != pattern1->end() ; ++iter_pre ) {
973  if ( (*iter_pre).i%patterns_every_pre != 0 ) continue;
974  NeuronID i = (*iter_pre).i/patterns_every_pre;
975  if ( wrap_patterns )
976  i = i % get_m_rows();
977  if ( i < src->get_size() && w->exists( i, j ) ) {
978  if ( overwrite ) {
979  set( i, j, (*iter_post).gamma*strength);
980  } else {
981  AurynWeight current_weight = get( i, j );
982  set( i, j, current_weight + (*iter_post).gamma*strength);
983  }
984  }
985  }
986  }
987  }
988 }
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
NeuronID patterns_every_post
The every_post parameter allows to skip postsynaptically over pattern IDs when loading patterns...
Definition: SparseConnection.h:138
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
bool wrap_patterns
Switch that toggles the behavior when loading a pattern to wrap neuron IDs back onto existing cells v...
Definition: SparseConnection.h:143
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
bool exists(const NeuronID i, const NeuronID j, const StateID z=0)
Returns true if the matrix element exists.
Definition: ComplexMatrix.h:692
NeuronID patterns_every_pre
The every_pre parameter allows to skip presynaptically over pattern IDs when loading patterns...
Definition: SparseConnection.h:132
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ random_col_data()

void SparseConnection::random_col_data ( AurynWeight  mean,
AurynWeight  sigma 
)

Sets weights in cols to the same value drewn from a Gaussian distribution.

290 {
291  std::stringstream oss;
292  oss << get_log_name() << "Randomly scaling cols (gaussian) with mean=" << mean << " sigma=" << sigma ;
293  auryn::logger->msg(oss.str(),VERBOSE);
294 
295  boost::normal_distribution<> dist((double)mean, (double)sigma);
296  boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > die(SparseConnection::sparse_connection_gen, dist);
297  AurynWeight rv;
298 
299  for ( NeuronID i = 0 ; i<get_n_cols() ; ++i ) {
300  rv = die();
301  if ( rv<0 ) rv = 0;
302  w->set_col(i,rv);
303  }
304 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
void set_col(const NeuronID j, const T value)
Sets all non-zero elements in col j to value. Due to ordering this is slow and the use of this functi...
Definition: ComplexMatrix.h:926
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
static boost::mt19937 sparse_connection_gen
Definition: SparseConnection.h:91
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ random_data()

void SparseConnection::random_data ( AurynWeight  mean,
AurynWeight  sigma 
)

Synonym for random_data.

209 {
210  random_data_normal(mean, sigma);
211 }
void random_data_normal(AurynWeight mean, AurynWeight sigma)
Set weights of all existing connections randomly using a normal distrubtion.
Definition: SparseConnection.cpp:213
Here is the call graph for this function:

◆ random_data_lognormal()

void SparseConnection::random_data_lognormal ( AurynWeight  m,
AurynWeight  s 
)

Set weights of all existing connections randomly using a lognormal distribution.

232 {
233  std::stringstream oss;
234  oss << get_log_name() << "randomizing non-zero connections (lognormal) with mean="
235  << mean << " sigma=" << sigma ;
236  auryn::logger->msg(oss.str(),NOTIFICATION);
237 
238  boost::lognormal_distribution<> dist((double)mean, (double)sigma);
239  boost::variate_generator<boost::mt19937&, boost::lognormal_distribution<> > die(SparseConnection::sparse_connection_gen, dist);
240  AurynWeight rv;
241 
242  for ( AurynLong i = 0 ; i<w->get_nonzero() ; ++i ) {
243  rv = die();
244  w->set_data(i,rv);
245  }
246 
248 }
AurynWeight get_max_weight()
Gets maximum weight (for plastic connections).
Definition: SparseConnection.h:420
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
Definition: Logger.h:41
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
virtual void clip(AurynWeight lo, AurynWeight hi)
Clip weights.
Definition: SparseConnection.cpp:1147
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
AurynWeight get_min_weight()
Gets minimum weight (for plastic connections).
Definition: SparseConnection.h:412
void set_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:441
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
static boost::mt19937 sparse_connection_gen
Definition: SparseConnection.h:91
Here is the call graph for this function:

◆ random_data_normal()

void SparseConnection::random_data_normal ( AurynWeight  mean,
AurynWeight  sigma 
)

Set weights of all existing connections randomly using a normal distrubtion.

214 {
215  std::stringstream oss;
216  oss << get_log_name() << "randomizing non-zero connections (gaussian) with mean=" << mean << " sigma=" << sigma ;
217  auryn::logger->msg(oss.str(),NOTIFICATION);
218 
219  boost::normal_distribution<> dist((double)mean, (double)sigma);
220  boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > die(SparseConnection::sparse_connection_gen, dist);
221  AurynWeight rv;
222 
223  for ( AurynLong i = 0 ; i<w->get_nonzero() ; ++i ) {
224  rv = die();
225  if ( rv<get_min_weight() ) rv = get_min_weight();
226  if ( rv>get_max_weight() ) rv = get_max_weight();
227  w->set_data(i,rv);
228  }
229 }
AurynWeight get_max_weight()
Gets maximum weight (for plastic connections).
Definition: SparseConnection.h:420
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
Definition: Logger.h:41
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
AurynWeight get_min_weight()
Gets minimum weight (for plastic connections).
Definition: SparseConnection.h:412
void set_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:441
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
static boost::mt19937 sparse_connection_gen
Definition: SparseConnection.h:91
Here is the call graph for this function:

◆ sanity_check()

void SparseConnection::sanity_check ( )

Quick an dirty function that checks if all units on the local rank are connected.

538 {
539  if ( dst->evolve_locally() == false ) return;
540 
541  AurynFloat * sum = new AurynFloat[dst->get_size()];
542  for ( NeuronID i = 0 ; i < dst->get_size() ; ++i ) sum[i] = 0.0;
543 
544  NeuronID * ind = w->get_ind_begin(); // first element of index array
545  AurynWeight * data = w->get_data_begin();
546  for ( NeuronID i = 0 ; i < src->get_size() ; ++i ) {
547  for (NeuronID * c = w->get_row_begin(i) ;
548  c < w->get_row_end(i) ;
549  ++c ) {
550  AurynWeight value = data[c-ind];
551  sum[*c] += value;
552  }
553  }
554 
555  NeuronID unconnected_count = 0 ;
556  double total_weight = 0;
557  for ( NeuronID i = 0 ; i < dst->get_size() ; ++i ) {
558  total_weight += sum[i];
559  if ( sum[i] == 0 && dst->localrank(i) ) {
560  unconnected_count++;
561  std::stringstream oss;
562  oss << "Sanity check: Neuron "
563  << i
564  << " local ("
565  << dst->global2rank(i)
566  << ") has no inputs." ;
567  auryn::logger->msg(oss.str(),WARNING);
568  }
569  }
570 
571  auryn::logger->parameter("sanity_check:total weight",total_weight);
572 
573  if ( unconnected_count ) {
574  std::stringstream oss;
575  oss << "Sanity check failed ("
576  << get_name()
577  << "). Found "
578  << unconnected_count
579  << " unconnected neurons.";
580  auryn::logger->msg(oss.str(),WARNING);
581  }
582 
583  delete [] sum;
584 
585  // row count - outputs
586 
587  AurynFloat * sum_rows = new AurynFloat[src->get_size()];
588  for ( NeuronID i = 0 ; i < src->get_size() ; ++i ) sum_rows[i] = 0.0;
589 
590  for ( NeuronID i = 0 ; i < src->get_size() ; ++i ) {
591  for (NeuronID * c = w->get_row_begin(i) ;
592  c != w->get_row_end(i) ;
593  ++c ) {
594  AurynWeight value = data[c-ind];
595  sum_rows[i] += value;
596  }
597  }
598 
599  for ( NeuronID i = 0 ; i < src->get_size() ; ++i ) {
600  if ( sum_rows[i] == 0 ) {
601  std::stringstream oss;
602  oss << "Sanity check: Neuron "
603  << i
604  << " local ("
605  << src->global2rank(i)
606  << ") has no outputs on this rank. This might be normal when run distributed." ;
607  auryn::logger->msg(oss.str(),VERBOSE);
608  if ( w->get_row_begin(i) != w->get_row_end(i) ) {
609  auryn::logger->msg("wmat inconsistency",ERROR);
610  }
611  }
612  }
613 
614 
615  delete [] sum_rows;
616 }
bool localrank(NeuronID i)
Checks if the global NeuronID i is integrated on this MPI rank.
Definition: SpikingGroup.cpp:531
NeuronID global2rank(NeuronID i)
Converts global NeuronID within the SpikingGroup to the local NeuronID on this rank.
Definition: SpikingGroup.h:446
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
NeuronID * get_ind_begin()
Definition: ComplexMatrix.h:934
void parameter(std::string name, T value)
Definition: Logger.h:90
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
SpikingGroup * src
Pointer to the source group of this connection.
Definition: Connection.h:108
Definition: Logger.h:41
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
Definition: Logger.h:41
NeuronID get_size()
Returns the size of the group.
Definition: SpikingGroup.cpp:304
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
std::string get_name()
Returns name of connection.
Definition: Connection.cpp:87
virtual AurynDouble sum()
Computes sum of all weight elements in the Connection.
Definition: SparseConnection.cpp:645
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ scale_all()

void SparseConnection::scale_all ( AurynFloat  value)
virtual

Scales all weights in the weight matrix with the given value.

341 {
342  w->scale_all( value );
343 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
void scale_all(const T value)
Scales all non-zero elements.
Definition: ComplexMatrix.h:883
Here is the call graph for this function:

◆ scale_block()

void SparseConnection::scale_block ( NeuronID  lo_row,
NeuronID  hi_row,
NeuronID  lo_col,
NeuronID  hi_col,
AurynWeight  alpha 
)

Scale all weights of existing connections in a block spanned by the first 4 parameters to the value given.

322 {
323  for ( NeuronID i = 0 ; i < get_m_rows() ; ++i )
324  {
325  for ( NeuronID * j = w->get_row_begin(i) ; j != w->get_row_end(i) ; ++j )
326  {
327  if (i >= lo_row && i < hi_row && *j >= lo_col && *j < hi_col )
328  w->get_data_begin()[j-w->get_row_begin(0)] *= alpha;
329  }
330  }
331 
333 }
AurynWeight get_max_weight()
Gets maximum weight (for plastic connections).
Definition: SparseConnection.h:420
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
virtual void clip(AurynWeight lo, AurynWeight hi)
Clip weights.
Definition: SparseConnection.cpp:1147
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
AurynWeight get_min_weight()
Gets minimum weight (for plastic connections).
Definition: SparseConnection.h:412
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ seed()

void SparseConnection::seed ( NeuronID  randomseed)

This function seeds the pseudo random number generator for all random fill operatios.

156 {
157  std::stringstream oss;
158  oss << get_log_name() << "Seeding with " << randomseed;
159  auryn::logger->msg(oss.str(),VERBOSE);
160  SparseConnection::sparse_connection_gen.seed(randomseed);
161  has_been_seeded = true;
162 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
static boost::mt19937 sparse_connection_gen
Definition: SparseConnection.h:91
Here is the call graph for this function:

◆ set() [1/2]

void SparseConnection::set ( NeuronID  i,
NeuronID  j,
AurynWeight  value 
)
virtual

Sets a single connection to value if it exists.

Implements auryn::Connection.

685 {
686  value = std::max(value,get_min_weight());
687  w->set(i,j,value);
688 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
bool set(const NeuronID i, const NeuronID j, T value)
Definition: ComplexMatrix.h:859
AurynWeight get_min_weight()
Gets minimum weight (for plastic connections).
Definition: SparseConnection.h:412
Here is the call graph for this function:

◆ set() [2/2]

void SparseConnection::set ( std::vector< neuron_pair element_list,
AurynWeight  value 
)
virtual

Sets a list of connection to value if they exists.

677 {
678  for (std::vector<neuron_pair>::iterator iter = element_list.begin() ; iter != element_list.end() ; ++iter)
679  {
680  w->set((*iter).i, (*iter).j,value);
681  }
682 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
bool set(const NeuronID i, const NeuronID j, T value)
Definition: ComplexMatrix.h:859
Here is the call graph for this function:

◆ set_all()

void SparseConnection::set_all ( AurynWeight  weight)
virtual

Sets all weights of existing connections to the given value.

336 {
337  w->set_all( weight );
338 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
void set_all(const T value, const StateID z=0)
Sets all non-zero elements to value.
Definition: ComplexMatrix.h:901
Here is the call graph for this function:

◆ set_block()

void SparseConnection::set_block ( NeuronID  lo_row,
NeuronID  hi_row,
NeuronID  lo_col,
NeuronID  hi_col,
AurynWeight  weight 
)

Sets all weights of existing connections in a block spanned by the first 4 parameters to the value given.

308 {
309  AurynWeight temp = std::max(weight,get_min_weight());
310  for ( NeuronID i = 0 ; i < get_m_rows() ; ++i )
311  {
312  for ( NeuronID * j = w->get_row_begin(i) ; j != w->get_row_end(i) ; ++j )
313  {
314  if (i >= lo_row && i < hi_row && *j >= lo_col && *j < hi_col )
315  w->get_data_begin()[j-w->get_row_begin(0)] = temp;
316  }
317  }
318 }
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
AurynWeight get_min_weight()
Gets minimum weight (for plastic connections).
Definition: SparseConnection.h:412
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ set_data()

void SparseConnection::set_data ( NeuronID  i,
AurynWeight  value 
)
virtual

Sets weight value of a given element referenced by its index in the data array.

662 {
663  w->set_data(i,value);
664 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
void set_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:441
Here is the call graph for this function:

◆ set_max_weight()

void SparseConnection::set_max_weight ( AurynWeight  maximum_weight)
virtual

Sets maximum weight (for plastic connections).

Reimplemented in auryn::TripletScalingConnection, and auryn::STDPwdConnection.

204 {
205  wmax = maximum_weight;
206 }
AurynWeight wmax
Definition: SparseConnection.h:103

◆ set_min_weight()

void SparseConnection::set_min_weight ( AurynWeight  minimum_weight)
virtual

Sets minimum weight (for plastic connections).

Reimplemented in auryn::TripletScalingConnection.

199 {
200  wmin = minimum_weight;
201 }
AurynWeight wmin
Definition: SparseConnection.h:97

◆ set_upper_triangular()

void SparseConnection::set_upper_triangular ( AurynWeight  weight)

Sets weights in a upper triangular matrix.

346 {
347  w->set_all( 0.0 );
348  AurynWeight temp = std::max(weight,get_min_weight());
349  for ( NeuronID i = 0 ; i < get_m_rows() ; ++i )
350  {
351  for ( NeuronID * j = w->get_row_begin(i) ; j != w->get_row_end(i) ; ++j )
352  {
353  if ( i <= *j )
354  w->get_data_begin()[j-w->get_row_begin(0)] = temp;
355  }
356  }
357 }
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
void set_all(const T value, const StateID z=0)
Sets all non-zero elements to value.
Definition: ComplexMatrix.h:901
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
AurynWeight get_min_weight()
Gets minimum weight (for plastic connections).
Definition: SparseConnection.h:412
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ sparse_set_data()

void SparseConnection::sparse_set_data ( AurynDouble  sparseness,
AurynWeight  value 
)
virtual

Sets a sparse random subset of connection elements wight the given value.

272 {
273  std::stringstream oss;
274  oss << get_log_name() << ": setting data sparsely with sparseness=" << sparseness << " value=" << value ;
275  auryn::logger->msg(oss.str(),VERBOSE);
276 
277  boost::exponential_distribution<> dist(sparseness);
278  boost::variate_generator<boost::mt19937&, boost::exponential_distribution<> > die(SparseConnection::sparse_connection_gen, dist);
279 
280  AurynLong x = (AurynLong) die();
281  AurynLong stop = w->get_datasize();
282 
283  while ( x < stop ) {
284  set_data(x,value);
285  x += die();
286  }
287 }
std::string get_log_name()
Returns a string which is the combination of file and connection name for logging.
Definition: Connection.cpp:98
virtual void set_data(NeuronID i, AurynWeight value)
Sets weight value of a given element referenced by its index in the data array.
Definition: SparseConnection.cpp:661
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
static boost::mt19937 sparse_connection_gen
Definition: SparseConnection.h:91
Here is the call graph for this function:

◆ stats() [1/2]

void SparseConnection::stats ( AurynDouble mean,
AurynDouble std 
)
virtual

Computes mean and variance of weights in default weight matrix.

Returns mean and variance of default weight matrix (typically referenced as w in a given SparseConnection

Reimplemented in auryn::RateModulatedConnection.

619 {
620  stats(mean, std, 0);
621 }
STL namespace.
virtual void stats(AurynDouble &mean, AurynDouble &std)
Computes mean and variance of weights in default weight matrix.
Definition: SparseConnection.cpp:618

◆ stats() [2/2]

void SparseConnection::stats ( AurynDouble mean,
AurynDouble std,
NeuronID  zid 
)
virtual

Computes mean and variance of weights for matrix state zid.

Implements auryn::Connection.

624 {
625  double sum = 0; // needs double here -- machine precision really matters here
626  double sum2 = 0;
627 
628  for ( AurynWeight * iter = w->get_data_begin(zid) ; iter != w->get_data_end(zid) ; ++iter ) {
629  sum += *iter;
630  sum2 += (*iter * *iter);
631  }
632 
633  NeuronID count = w->get_nonzero();
634 
635  if ( count <= 1 ) {
636  mean = sum;
637  std = 0;
638  return;
639  }
640 
641  mean = sum/count;
642  std = sqrt((sum2-sum*sum/count)/(count-1));
643 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
STL namespace.
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
T * get_data_end(const StateID z=0)
Returns pointer to data value corresponding to the element behind the last nonzero element...
Definition: ComplexMatrix.h:977
virtual AurynDouble sum()
Computes sum of all weight elements in the Connection.
Definition: SparseConnection.cpp:645
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ sum()

AurynDouble SparseConnection::sum ( )
virtual

Computes sum of all weight elements in the Connection.

646 {
647  AurynFloat sum = 0;
648 
649  for ( AurynWeight * iter = w->get_data_begin() ; iter != w->get_data_end() ; ++iter ) {
650  sum += *iter;
651  }
652 
653  return sum;
654 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
T * get_data_end(const StateID z=0)
Returns pointer to data value corresponding to the element behind the last nonzero element...
Definition: ComplexMatrix.h:977
virtual AurynDouble sum()
Computes sum of all weight elements in the Connection.
Definition: SparseConnection.cpp:645
Here is the call graph for this function:

◆ virtual_serialize() [1/2]

void auryn::SparseConnection::virtual_serialize ( boost::archive::binary_oarchive &  ar,
const unsigned int  version 
)
inlineprotectedvirtual

Serialization function for saving the Connection state. Implement in derived classes to save additional information.

Reimplemented from auryn::Connection.

79  {
81  ar & *w;
82  }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
virtual void virtual_serialize(boost::archive::binary_oarchive &ar, const unsigned int version)
Definition: Connection.h:71
Here is the call graph for this function:

◆ virtual_serialize() [2/2]

void auryn::SparseConnection::virtual_serialize ( boost::archive::binary_iarchive &  ar,
const unsigned int  version 
)
inlineprotectedvirtual

Serialization function for loading the Connection state. Implement in derived classes to save additional information.

Reimplemented from auryn::Connection.

85  {
87  ar & *w;
88  }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
virtual void virtual_serialize(boost::archive::binary_oarchive &ar, const unsigned int version)
Definition: Connection.h:71
Here is the call graph for this function:

◆ write_to_file() [1/2]

bool SparseConnection::write_to_file ( ForwardMatrix m,
std::string  filename 
)

Writes rank specific weight matrix on the same rank to a file.

This function writes all synaptic weights from the specified weight matrix which are stored on the same rank to a Matrix Market file in real coordinate format. The file can later be read with load_from_file to continue a simulation or can be processed offline using standard tools such as MATLAB or Python.

691 {
692  if ( !dst->evolve_locally() ) return true;
693 
694  std::ofstream outfile;
695  outfile.open(filename.c_str(),std::ios::out);
696  if (!outfile) {
697  std::stringstream oss;
698  oss << "Can't open output file " << filename;
699  auryn::logger->msg(oss.str(),ERROR);
700  throw AurynOpenFileException();
701  }
702 
703  outfile << "%%MatrixMarket matrix coordinate real general\n"
704  << "% Auryn weight matrix. Has to be kept in row major order for load operation.\n"
705  << "% Connection name: " << get_name() << "\n"
706  << "% Locked range: " << dst->get_locked_range() << "\n"
707  << "%\n"
708  << get_m_rows() << " " << get_n_cols() << " " << m->get_nonzero() << std::endl;
709 
710  AurynLong count = 0;
711  for ( NeuronID i = 0 ; i < get_m_rows() ; ++i )
712  {
713  outfile << std::setprecision(7);
714  for ( NeuronID * j = m->get_row_begin(i) ; j != m->get_row_end(i) ; ++j )
715  {
716  outfile << i+1 << " " << *j+1 << " " << std::scientific << m->get_data_begin()[j-m->get_row_begin(0)] << std::fixed << "\n";
717  ++count;
718  }
719  }
720 
721  if ( count != m->get_nonzero() ) {
722  logger->msg("SparseConnection:: count inconsistency while writing MatrixMarket to file.", WARNING);
723  }
724 
725  outfile.close();
726  return true;
727 }
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
Definition: Logger.h:41
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
NeuronGroup * dst
Pointer to the destination group of this connection.
Definition: Connection.h:111
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Definition: auryn_definitions.h:208
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
bool evolve_locally()
Returns true if the calling instance has units which are integrated on the current rank...
Definition: SpikingGroup.cpp:323
NeuronID get_n_cols()
Get number of columns (postsynaptic) in connection.
Definition: Connection.cpp:183
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
Definition: Logger.h:41
unsigned int get_locked_range()
Returns locked range of ranks for SpikingGroups which are not distributed across all ranks...
Definition: SpikingGroup.cpp:334
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
NeuronID get_m_rows()
Get number of rows (presynaptic) in connection.
Definition: Connection.cpp:178
std::string get_name()
Returns name of connection.
Definition: Connection.cpp:87
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ write_to_file() [2/2]

bool SparseConnection::write_to_file ( std::string  filename)
virtual

Writes rank specific default weight matrix on the same rank to a file.

This call is a shortcut for write_to_file(w, filename) where w is the default weight matrix of the underlying SparseConnectoin.

Implements auryn::Connection.

Reimplemented in auryn::RateModulatedConnection.

730 {
731  return write_to_file(w,filename.c_str());
732 }
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
bool write_to_file(ForwardMatrix *m, string filename)
Writes rank specific weight matrix on the same rank to a file.
Definition: SparseConnection.cpp:690
Here is the call graph for this function:

Member Data Documentation

◆ patterns_every_post

NeuronID auryn::SparseConnection::patterns_every_post

The every_post parameter allows to skip postsynaptically over pattern IDs when loading patterns. Default is 1. This can be useful to when loading patterns into the exc->inh connections and there significantly less inhibitory cells than exc ones.

◆ patterns_every_pre

NeuronID auryn::SparseConnection::patterns_every_pre

The every_pre parameter allows to skip presynaptically over pattern IDs when loading patterns. Default is 1. This can be useful to when loading patterns into the exc->inh connections and there significantly less inhibitory cells than exc ones.

◆ patterns_ignore_gamma

bool auryn::SparseConnection::patterns_ignore_gamma

Switch that toggles for the load_patterns function whether or not to use the intensity (gamma) value. Default is false.

◆ skip_diagonal

bool auryn::SparseConnection::skip_diagonal
protected

Switch that specifies whether or not to skip diagonal elemens during random connect. This is usefull for random connects to exclude autapses from the connections.

◆ sparse_connection_gen

boost::mt19937 SparseConnection::sparse_connection_gen = boost::mt19937()
staticprotected

/brief Static random number generator used for random connect

◆ w

ForwardMatrix* auryn::SparseConnection::w

A pointer that points per default to the ComplexMatrix that stores the connectinos.

◆ wmax

AurynWeight auryn::SparseConnection::wmax
protected

/brief Maximum allowed weight value

This property is stored for Connection objects with plasticity. The value can be set and accessed with the setters get_max_weight() and set_max_weight(x)

◆ wmin

AurynWeight auryn::SparseConnection::wmin
protected

/brief Minimum allowed weight value

This property is stored for Connection objects with plasticity. The value can be set and accessed with the setters get_min_weight() and set_min_weight(x)

◆ wrap_patterns

bool auryn::SparseConnection::wrap_patterns

Switch that toggles the behavior when loading a pattern to wrap neuron IDs back onto existing cells via the modulo function.


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