Auryn simulator
v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
|
Template for a sparse matrix with row major ordering and fast access of rows and capability to store float values per matrix entry. More...
#include <ComplexMatrix.h>
Public Member Functions | |
ComplexMatrix () | |
Empty constructor. More... | |
ComplexMatrix (ComplexMatrix *mat) | |
Copy constructor. More... | |
ComplexMatrix (NeuronID rows, NeuronID cols, AurynLong size=256, StateID n_values=1) | |
Default constructor. More... | |
virtual | ~ComplexMatrix () |
Default destructor. More... | |
void | clear () |
Clears matrix. More... | |
AurynVector< T, AurynLong > * | get_synaptic_state_vector (StateID z=0) |
Returns pointer to statevector which is an AurynVector of specified synaptic state. More... | |
AurynVector< T, AurynLong > * | get_state_vector (StateID z=0) |
Sames as get_synaptic_state_vector(StateID z) More... | |
void | resize_buffers (AurynLong size) |
Resize buffer. More... | |
void | resize_buffer_and_clear (AurynLong size) |
Resizes buffer and clears the matrix. This saves to copy all the data. More... | |
void | prune () |
Prunes the reserved memory such that datasize=get_nonzero() Note that this is an expensive operation because it uses resize_buffers(size) and it should be used sparsely. More... | |
void | push_back (const NeuronID i, const NeuronID j, const T value) |
void | copy (ComplexMatrix *mat) |
Copies complex matrix mat. More... | |
void | set_element (AurynLong data_index, T value, StateID z=0) |
void | set_data (AurynLong i, T value, StateID z=0) |
void | scale_element (AurynLong data_index, T value, StateID z=0) |
void | scale_data (AurynLong i, T value, StateID z=0) |
T | get_data (AurynLong i, StateID z=0) |
T * | get_data_ptr (const AurynLong data_index, const StateID z=0) |
Gets the matching data ptr for a given index i and state z. More... | |
T * | get_data_ptr (const NeuronID *ind_ptr, const StateID z=0) |
Gets the matching data ptr for a given index pointer and state z. More... | |
T | get_data (const NeuronID *ind_ptr, StateID z=0) |
Gets the matching data value for a given index pointer and state z. More... | |
void | fill_na () |
Pads non-existing elements for the remaining elements to a matrix. More... | |
void | fill_zeros () |
Same as fill_na but deprecated because of bad name. More... | |
AurynDouble | get_fill_level () |
Returns the fill level of the matrix element buffer. More... | |
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. More... | |
bool | exists (const NeuronID i, const NeuronID j, const StateID z=0) |
Returns true if the matrix element exists. More... | |
T * | get_ptr (const NeuronID i, const NeuronID j, const StateID z=0) |
Returns the pointer to a particular element. More... | |
T * | get_ptr (const AurynLong data_index, const StateID z=0) |
Same as get_data_ptr. Returns the pointer to a particular element given its position in the data array. More... | |
T | get_element (const AurynLong data_index, const StateID z) |
Returns a particular element given its position in the data array. More... | |
AurynLong | ind_ptr_to_didx (const NeuronID *ind_ptr) |
Returns data index to a particular element specifed by an index pointer. More... | |
AurynLong | get_data_index (const NeuronID *ind_ptr) |
Returns data index to a particular element specifed by an index pointer. More... | |
AurynLong | get_data_index (const NeuronID i, const NeuronID j) |
AurynLong | data_ptr_to_didx (const T *ptr) |
Returns data index to a particular element specifed by a data pointer. More... | |
AurynLong | get_data_index (const T *ptr) |
Returns data index to a particular element specifed by a data pointer. More... | |
void | set_num_synaptic_states (const StateID zsize) |
Sets number of synaptic states (z-value) More... | |
void | set_num_synapse_states (const StateID zsize) |
Sets number of synaptic states (z-value) More... | |
StateID | get_num_synaptic_states () |
Returns number of synaptic states (z-value) More... | |
StateID | get_num_z_values () |
Returns number of synaptic states (z-value) More... | |
StateID | get_num_synapse_states () |
Synonymous to get_num_synaptic_states. More... | |
T * | get_state_begin (const StateID z=0) |
Gets pointer for the first element of a given synaptic state vector. More... | |
T * | get_state_end (const StateID z=0) |
Gets pointer for the element behind the last of a given synaptic state vector. More... | |
void | state_set_all (T *x, const T value) |
Sets all values in state x to value. More... | |
void | state_saxpy (const T a, T *x, T *y) |
Computes a*x + y and stores result in y. More... | |
void | state_mul (T *x, T *y) |
Multiplies x and y and stores result in y. More... | |
void | state_add (T *x, T *y) |
Adds x and y and stores result in y. More... | |
void | state_sub (T *x, T *y) |
Computes x-y and stores result in y. More... | |
void | state_sub (T *x, T *y, T *res) |
Computes x-y and stores result in res. More... | |
void | state_scale (const T a, T *x) |
Scale state x by a. More... | |
void | state_add_const (const T a, T *x) |
Adds constant a to all values in x. More... | |
void | state_clip (T *x, const T a, const T b) |
Clips state values to interval [a,b]. More... | |
T * | state_get_data_ptr (T *x, NeuronID i) |
Get data pointer for that state. More... | |
void | add_value (const AurynLong data_index, T value) |
NeuronID | get_colind (const AurynLong data_index) |
bool | set (const NeuronID i, const NeuronID j, T value) |
void | set_all (const T value, const StateID z=0) |
Sets all non-zero elements to value. More... | |
void | set_row (const NeuronID i, const T value) |
Sets all non-zero elements in row i to value. More... | |
void | scale_row (const NeuronID i, const T value) |
Scales all non-zero elements in row i to value. More... | |
void | scale_all (const T value) |
Scales all non-zero elements. More... | |
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 functions is discouraged. More... | |
void | scale_col (const NeuronID j, const T value) |
Scales all non-zero elements in col j to value. Due to ordering this is slow and the use of this functions is discouraged. More... | |
double | sum_col (const NeuronID j) |
AurynLong | get_datasize () |
Returns datasize: number of possible entries. More... | |
AurynLong | get_statesize () |
Same as datasize : number of possible entries. More... | |
AurynLong | get_memsize () |
Returns statesize multiplied by number of states. More... | |
AurynLong | get_nonzero () |
Returns number of non-zero elements. More... | |
void | print () |
stdout dump of all elements – for testing only. More... | |
double | mean () |
Return mean value of elements for the first complex state (z=0). More... | |
NeuronID * | get_ind_begin () |
NeuronID * | get_row_begin (NeuronID i) |
AurynLong | get_row_begin_index (NeuronID i) |
NeuronID * | get_row_end (NeuronID i) |
AurynLong | get_row_end_index (NeuronID i) |
NeuronID | get_m_rows () |
NeuronID | get_n_cols () |
NeuronID ** | get_rowptrs () |
T * | get_data_begin (const StateID z=0) |
Returns pointer to data value corresponding to the first element. More... | |
T * | get_data_end (const StateID z=0) |
Returns pointer to data value corresponding to the element behind the last nonzero element. More... | |
T | get_value (const AurynLong data_index) |
Returns the data value to an item that is i-th in the colindex array. More... | |
T | get_value (NeuronID *r) |
Returns the data value to an item that for pointer r pointing to the respective element in the index array. More... | |
T * | get_value_ptr (const NeuronID i) |
Returns pointer to the the data value to an item that is i-th in the colindex array. More... | |
T * | get_value_ptr (NeuronID *r) |
Returns the pointer to the data value to an item that for pointer r pointing to the respective element in the index array. More... | |
NeuronID | get_data_offset (NeuronID *r) |
Public Attributes | |
std::vector< AurynVector< T, AurynLong > *> | statevectors |
Vector that holds pointers to the state vectors storing the synaptic states. More... | |
Protected Member Functions | |
AurynVector< T, AurynLong > * | alloc_synaptic_state_vector () |
Returns a synaptic state vector. More... | |
void | prepare_state_vectors () |
Matches size of statevectors to number of synaptic states. More... | |
void | init (NeuronID m, NeuronID n, AurynLong size, NeuronID z) |
Default initializiation called by the constructor. More... | |
void | free () |
Protected Attributes | |
NeuronID ** | rowptrs |
Array that holds the begin addresses of column indices. More... | |
NeuronID * | colinds |
Array that holds the column indices of non-zero elements. More... | |
Friends | |
class | boost::serialization::access |
Template for a sparse matrix with row major ordering and fast access of rows and capability to store float values per matrix entry.
This matrix class implements a sparse matrix that allows fast access of all elements of one row. It provides row interators to efficiently propagate spikes. Memory has to be reserved when the class is defined and elements can only be inserted row by row starting from "left to right". This scheme enables related data fields to reside in memory next to each other.
ComplexMatrix generalizes SimpleMatrix to a rank 3 tensor in which each synaptic connection can have more than one value (third tensor mode – corresponding to a synaptic state). This allows to efficiently implement state based complex synaptic models which have their own internal dynamics.
Instead of storing all synaptic data values in one long array the synaptic state values are stored in multiple state vectors which can be manipulated efficiently in a vector based manner.
For instance, suppose w holds your instance of ComplexMatris in which you have set_num_synapse_states(3) which makes it a connectivity matrix which reserves three state variables of type AurynWeight per synaptic connection. Now, decaying all elements of, say, state 3 by a factor "foo" is as simple as w->get_state_vector(2)->scale(foo). Adding two of the states for all synapses becomes w->get_state_vector(2)->add(w->get_state_vector(3)).
Because these expressions become quickly rather lenghty it is nice to declare shortcuts in your plastic Connection class such as: AurynSynStateVector * w_val = w->get_state_vector(0); AurynSynStateVector * tagging_val = w->get_state_vector(1); AurynSynStateVector * scaffold_val = w->get_state_vector(2);
You can now work with these as you are used with AurynVector or AurynStateVector instances w_val->saxpy(foo,tagging_val)
auryn::ComplexMatrix< T >::ComplexMatrix | ( | ) |
Empty constructor.
auryn::ComplexMatrix< T >::ComplexMatrix | ( | ComplexMatrix< T > * | mat | ) |
Copy constructor.
auryn::ComplexMatrix< T >::ComplexMatrix | ( | NeuronID | rows, |
NeuronID | cols, | ||
AurynLong | size = 256 , |
||
StateID | n_values = 1 |
||
) |
Default constructor.
|
virtual |
Default destructor.
void auryn::ComplexMatrix< T >::add_value | ( | const AurynLong | data_index, |
T | value | ||
) |
|
protected |
Returns a synaptic state vector.
void auryn::ComplexMatrix< T >::clear | ( | ) |
Clears matrix.
void auryn::ComplexMatrix< T >::copy | ( | ComplexMatrix< T > * | mat | ) |
Copies complex matrix mat.
AurynLong auryn::ComplexMatrix< T >::data_ptr_to_didx | ( | const T * | ptr | ) |
Returns data index to a particular element specifed by a data pointer.
bool auryn::ComplexMatrix< T >::exists | ( | const NeuronID | i, |
const NeuronID | j, | ||
const StateID | z = 0 |
||
) |
Returns true if the matrix element exists.
void auryn::ComplexMatrix< T >::fill_na | ( | ) |
Pads non-existing elements for the remaining elements to a matrix.
This function has to be called after filling the matrix with elements e.g. random sparse and before using it in a simulation. It is typically called by the finalize function in SparseConnection.
void auryn::ComplexMatrix< T >::fill_zeros | ( | ) |
Same as fill_na but deprecated because of bad name.
|
protected |
T auryn::ComplexMatrix< 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.
NeuronID auryn::ComplexMatrix< T >::get_colind | ( | const AurynLong | data_index | ) |
T auryn::ComplexMatrix< T >::get_data | ( | AurynLong | i, |
StateID | z = 0 |
||
) |
Gets the matching data entry for a given index i and state z
T auryn::ComplexMatrix< T >::get_data | ( | const NeuronID * | ind_ptr, |
StateID | z = 0 |
||
) |
Gets the matching data value for a given index pointer and state z.
T * auryn::ComplexMatrix< T >::get_data_begin | ( | const StateID | z = 0 | ) |
Returns pointer to data value corresponding to the first element.
T * auryn::ComplexMatrix< T >::get_data_end | ( | const StateID | z = 0 | ) |
Returns pointer to data value corresponding to the element behind the last nonzero element.
AurynLong auryn::ComplexMatrix< T >::get_data_index | ( | const NeuronID * | ind_ptr | ) |
Returns data index to a particular element specifed by an index pointer.
AurynLong auryn::ComplexMatrix< T >::get_data_index | ( | const NeuronID | i, |
const NeuronID | j | ||
) |
Returns data index to a particular element specifed by i and j
|
inline |
Returns data index to a particular element specifed by a data pointer.
NeuronID auryn::ComplexMatrix< T >::get_data_offset | ( | NeuronID * | r | ) |
T * auryn::ComplexMatrix< T >::get_data_ptr | ( | const AurynLong | data_index, |
const StateID | z = 0 |
||
) |
Gets the matching data ptr for a given index i and state z.
T * auryn::ComplexMatrix< T >::get_data_ptr | ( | const NeuronID * | ind_ptr, |
const StateID | z = 0 |
||
) |
Gets the matching data ptr for a given index pointer and state z.
AurynLong auryn::ComplexMatrix< T >::get_datasize | ( | ) |
Returns datasize: number of possible entries.
T auryn::ComplexMatrix< T >::get_element | ( | const AurynLong | data_index, |
const StateID | z | ||
) |
Returns a particular element given its position in the data array.
AurynDouble auryn::ComplexMatrix< T >::get_fill_level | ( | ) |
Returns the fill level of the matrix element buffer.
A fill level of 1.0 corresponds to the sparse matrix element buffer being full.
NeuronID * auryn::ComplexMatrix< T >::get_ind_begin | ( | ) |
NeuronID auryn::ComplexMatrix< T >::get_m_rows | ( | ) |
AurynLong auryn::ComplexMatrix< T >::get_memsize | ( | ) |
NeuronID auryn::ComplexMatrix< T >::get_n_cols | ( | ) |
AurynLong auryn::ComplexMatrix< T >::get_nonzero | ( | ) |
NeuronID auryn::ComplexMatrix< T >::get_num_synapse_states | ( | ) |
Synonymous to get_num_synaptic_states.
StateID auryn::ComplexMatrix< T >::get_num_synaptic_states | ( | ) |
NeuronID auryn::ComplexMatrix< T >::get_num_z_values | ( | ) |
Returns number of synaptic states (z-value)
T * auryn::ComplexMatrix< T >::get_ptr | ( | const NeuronID | i, |
const NeuronID | j, | ||
const StateID | z = 0 |
||
) |
Returns the pointer to a particular element.
T * auryn::ComplexMatrix< T >::get_ptr | ( | const AurynLong | data_index, |
const StateID | z = 0 |
||
) |
Same as get_data_ptr. Returns the pointer to a particular element given its position in the data array.
NeuronID * auryn::ComplexMatrix< T >::get_row_begin | ( | NeuronID | i | ) |
AurynLong auryn::ComplexMatrix< T >::get_row_begin_index | ( | NeuronID | i | ) |
NeuronID * auryn::ComplexMatrix< T >::get_row_end | ( | NeuronID | i | ) |
AurynLong auryn::ComplexMatrix< T >::get_row_end_index | ( | NeuronID | i | ) |
NeuronID ** auryn::ComplexMatrix< T >::get_rowptrs | ( | ) |
T * auryn::ComplexMatrix< T >::get_state_begin | ( | const StateID | z = 0 | ) |
Gets pointer for the first element of a given synaptic state vector.
T * auryn::ComplexMatrix< T >::get_state_end | ( | const StateID | z = 0 | ) |
Gets pointer for the element behind the last of a given synaptic state vector.
AurynVector< T, AurynLong > * auryn::ComplexMatrix< T >::get_state_vector | ( | StateID | z = 0 | ) |
Sames as get_synaptic_state_vector(StateID z)
AurynLong auryn::ComplexMatrix< T >::get_statesize | ( | ) |
AurynVector< T, AurynLong > * auryn::ComplexMatrix< T >::get_synaptic_state_vector | ( | StateID | z = 0 | ) |
Returns pointer to statevector which is an AurynVector of specified synaptic state.
T auryn::ComplexMatrix< T >::get_value | ( | const AurynLong | data_index | ) |
Returns the data value to an item that is i-th in the colindex array.
T auryn::ComplexMatrix< T >::get_value | ( | NeuronID * | r | ) |
Returns the data value to an item that for pointer r pointing to the respective element in the index array.
T * auryn::ComplexMatrix< T >::get_value_ptr | ( | const NeuronID | i | ) |
Returns pointer to the the data value to an item that is i-th in the colindex array.
T * auryn::ComplexMatrix< T >::get_value_ptr | ( | NeuronID * | r | ) |
Returns the pointer to the data value to an item that for pointer r pointing to the respective element in the index array.
AurynLong auryn::ComplexMatrix< T >::ind_ptr_to_didx | ( | const NeuronID * | ind_ptr | ) |
Returns data index to a particular element specifed by an index pointer.
|
protected |
Default initializiation called by the constructor.
double auryn::ComplexMatrix< T >::mean | ( | ) |
Return mean value of elements for the first complex state (z=0).
Warning: Note that ComplexMatrix can only compute the mean of all the subset of elements stored on thank it runs on.
|
protected |
Matches size of statevectors to number of synaptic states.
void auryn::ComplexMatrix< T >::print | ( | ) |
stdout dump of all elements – for testing only.
void auryn::ComplexMatrix< T >::prune | ( | ) |
Prunes the reserved memory such that datasize=get_nonzero() Note that this is an expensive operation because it uses resize_buffers(size) and it should be used sparsely.
void auryn::ComplexMatrix< T >::push_back | ( | const NeuronID | i, |
const NeuronID | j, | ||
const T | value | ||
) |
Add non-zero element in row/col order.
i | row index where to insert element |
j | col index where to insert element |
value | to insert |
AurynMatrixBufferException |
void auryn::ComplexMatrix< T >::resize_buffer_and_clear | ( | AurynLong | size | ) |
Resizes buffer and clears the matrix. This saves to copy all the data.
void auryn::ComplexMatrix< T >::resize_buffers | ( | AurynLong | size | ) |
Resize buffer.
Allocates a new buffer of size and copies the old buffers before freeing the memory
void auryn::ComplexMatrix< T >::scale_all | ( | const T | value | ) |
Scales all non-zero elements.
void auryn::ComplexMatrix< T >::scale_col | ( | const NeuronID | j, |
const T | value | ||
) |
Scales all non-zero elements in col j to value. Due to ordering this is slow and the use of this functions is discouraged.
void auryn::ComplexMatrix< T >::scale_data | ( | AurynLong | i, |
T | value, | ||
StateID | z = 0 |
||
) |
void auryn::ComplexMatrix< T >::scale_element | ( | AurynLong | data_index, |
T | value, | ||
StateID | z = 0 |
||
) |
void auryn::ComplexMatrix< T >::scale_row | ( | const NeuronID | i, |
const T | value | ||
) |
Scales all non-zero elements in row i to value.
bool auryn::ComplexMatrix< T >::set | ( | const NeuronID | i, |
const NeuronID | j, | ||
T | value | ||
) |
void auryn::ComplexMatrix< T >::set_all | ( | const T | value, |
const StateID | z = 0 |
||
) |
Sets all non-zero elements to value.
void auryn::ComplexMatrix< T >::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 functions is discouraged.
void auryn::ComplexMatrix< T >::set_data | ( | AurynLong | i, |
T | value, | ||
StateID | z = 0 |
||
) |
void auryn::ComplexMatrix< T >::set_element | ( | AurynLong | data_index, |
T | value, | ||
StateID | z = 0 |
||
) |
void auryn::ComplexMatrix< T >::set_num_synapse_states | ( | const StateID | zsize | ) |
Sets number of synaptic states (z-value)
void auryn::ComplexMatrix< T >::set_num_synaptic_states | ( | const StateID | zsize | ) |
Sets number of synaptic states (z-value)
void auryn::ComplexMatrix< T >::set_row | ( | const NeuronID | i, |
const T | value | ||
) |
Sets all non-zero elements in row i to value.
void auryn::ComplexMatrix< T >::state_add | ( | T * | x, |
T * | y | ||
) |
Adds x and y and stores result in y.
void auryn::ComplexMatrix< T >::state_add_const | ( | const T | a, |
T * | x | ||
) |
Adds constant a to all values in x.
void auryn::ComplexMatrix< T >::state_clip | ( | T * | x, |
const T | a, | ||
const T | b | ||
) |
Clips state values to interval [a,b].
T * auryn::ComplexMatrix< T >::state_get_data_ptr | ( | T * | x, |
NeuronID | i | ||
) |
void auryn::ComplexMatrix< T >::state_mul | ( | T * | x, |
T * | y | ||
) |
Multiplies x and y and stores result in y.
void auryn::ComplexMatrix< T >::state_saxpy | ( | const T | a, |
T * | x, | ||
T * | y | ||
) |
Computes a*x + y and stores result in y.
void auryn::ComplexMatrix< T >::state_scale | ( | const T | a, |
T * | x | ||
) |
Scale state x by a.
void auryn::ComplexMatrix< T >::state_set_all | ( | T * | x, |
const T | value | ||
) |
Sets all values in state x to value.
void auryn::ComplexMatrix< T >::state_sub | ( | T * | x, |
T * | y | ||
) |
Computes x-y and stores result in y.
void auryn::ComplexMatrix< T >::state_sub | ( | T * | x, |
T * | y, | ||
T * | res | ||
) |
Computes x-y and stores result in res.
double auryn::ComplexMatrix< T >::sum_col | ( | const NeuronID | j | ) |
|
friend |
|
protected |
Array that holds the column indices of non-zero elements.
|
protected |
Array that holds the begin addresses of column indices.
std::vector< AurynVector<T,AurynLong> * > auryn::ComplexMatrix< T >::statevectors |
Vector that holds pointers to the state vectors storing the synaptic states.