#include <SparseMsg.h>
Public Member Functions | |
SparseMsg (Element *e1, Element *e2, unsigned int msgIndex) | |
~SparseMsg () | |
Eref | firstTgt (const Eref &src) const |
void | sources (vector< vector< Eref > > &v) const |
void | targets (vector< vector< Eref > > &v) const |
unsigned int | randomConnect (double probability) |
Id | managerId () const |
ObjId | findOtherEnd (ObjId end) const |
Msg * | copy (Id origSrc, Id newSrc, Id newTgt, FuncId fid, unsigned int b, unsigned int n) const |
void | setMatrix (const SparseMatrix< unsigned int > &m) |
SparseMatrix< unsigned int > & | getMatrix () |
void | setRandomConnectivity (double probability, long seed) |
double | getProbability () const |
void | setProbability (double value) |
long | getSeed () const |
void | setSeed (long value) |
void | setEntry (unsigned int row, unsigned int column, unsigned int value) |
void | unsetEntry (unsigned int row, unsigned int column) |
unsigned int | getNumRows () const |
unsigned int | getNumColumns () const |
unsigned int | getNumEntries () const |
void | clear () |
void | transpose () |
void | pairFill (vector< unsigned int > src, vector< unsigned int > dest) |
void | tripletFill (vector< unsigned int > src, vector< unsigned int > dest, vector< unsigned int > field) |
void | updateAfterFill () |
Static Public Member Functions | |
static unsigned int | numMsg () |
Msg lookup functions. | |
static char * | lookupMsg (unsigned int index) |
Static function for Msg access. | |
static const Cinfo * | initCinfo () |
Friends | |
unsigned int | Msg::initMsgManagers () |
This is a parallelized sparse message. It is a general message type optimized for sparse matrix like projection patterns. For each source object[DataId] there can be a target object[DataId]. For parallel/multithreaded use, we need to guarantee that all requests to the same target object (and all its synapses) are on the same queue. So it builds up a separate SparseMatrix for each thread.
It has a function to do the node/thread decomposition to generate an equivalent of the original sparse matrix, but using only the appropriate RNG seed.
A typical case is from an array of IntFire objects to an array of Synapses, which are array fields of IntFire objects. The sparse connectivity maps between the source IntFire and target Synapses. The location of the entry in the sparse matrix provides the index of the target IntFire. The data value in the sparse matrix provides the index of the Synapse at that specific connection. This assumes that only one Synapse mediates a given connection between any two IntFire objects.
It is optimized for input coming on Element e1, and going to Element e2. If you expect any significant backward data flow, please use BiSparseMsg. It can be modified after creation to add or remove message entries.
References Element::numData(), and SparseMatrix< T >::setSize().
Referenced by copy().
SparseMsg::~SparseMsg | ( | ) |
References ObjId::dataIndex, and Msg::mid_.
void SparseMsg::clear | ( | ) |
References SparseMatrix< T >::clear().
Referenced by initCinfo().
Msg * SparseMsg::copy | ( | Id | origSrc, | |
Id | newSrc, | |||
Id | newTgt, | |||
FuncId | fid, | |||
unsigned int | b, | |||
unsigned int | n | |||
) | const [virtual] |
Make a copy of this Msg. The original msg was on origSrc. The new Msg should go from newSrc to newTgt, and have the function fid, on bindIndex b. The copy may have to be a higher-order Msg type to handle arrays if n > 1. Note that n is not the number of msgs, but the multiplier by which numData will be scaled.
Implements Msg.
References Element::addMsgAndFunc(), Msg::e1(), Msg::e2(), Id::element(), Msg::mid(), setMatrix(), and SparseMsg().
Find the other end of this Msg. In most cases this is a straightforward return of e1 or e2, plus perhaps a DataId. But in some complex msgs we need to figure out DataIds that match with the target. In many-to-one cases we just return the first entry. If no Element match, return ObjId( Id(), DataId::bad() ) If Element e matches but not DataId, return ObjId( e.id(), DataId::bad() )
Implements Msg.
References BADINDEX, ObjId::dataIndex, Msg::e1(), Msg::e2(), ObjId::element(), SparseMatrix< T >::getColumn(), SparseMatrix< T >::getRow(), and rowIndex().
Obtain the first target Eref for the specified Src Eref It is really meant only to work with messages with a single target ObjId for each given src, typically OneToOne.
Implements Msg.
References Eref::dataIndex(), Msg::e1_, Msg::e2_, Eref::element(), SparseMatrix< T >::getRow(), and SparseMatrix< T >::nEntries().
SparseMatrix< unsigned int > & SparseMsg::getMatrix | ( | ) |
Returns the connection matrix
unsigned int SparseMsg::getNumColumns | ( | ) | const |
References SparseMatrix< T >::nColumns().
Referenced by initCinfo().
unsigned int SparseMsg::getNumEntries | ( | ) | const |
References SparseMatrix< T >::nEntries().
Referenced by initCinfo().
unsigned int SparseMsg::getNumRows | ( | ) | const |
References SparseMatrix< T >::nRows().
Referenced by initCinfo().
double SparseMsg::getProbability | ( | ) | const |
Referenced by initCinfo().
long SparseMsg::getSeed | ( | ) | const |
Referenced by initCinfo().
const Cinfo * SparseMsg::initCinfo | ( | ) | [static] |
Set up the Msg to be accessed like an Element Although the bare Msg class is never seen, we will use it as a base class and set up some common fields here.
Reimplemented from Msg.
References clear(), getNumColumns(), getNumEntries(), getNumRows(), getProbability(), getSeed(), Msg::initCinfo(), pairFill(), setEntry(), setProbability(), setRandomConnectivity(), setSeed(), transpose(), tripletFill(), and unsetEntry().
Referenced by Msg::initMsgManagers().
char * SparseMsg::lookupMsg | ( | unsigned int | index | ) | [static] |
Static function for Msg access.
Referenced by Msg::clearAllMsgs(), and Msg::initMsgManagers().
Id SparseMsg::managerId | ( | ) | const |
unsigned int SparseMsg::numMsg | ( | ) | [static] |
Msg lookup functions.
Static function for Msg access.
Referenced by Msg::clearAllMsgs(), and Msg::initMsgManagers().
void SparseMsg::pairFill | ( | vector< unsigned int > | src, | |
vector< unsigned int > | dest | |||
) |
Fills up the entire message based on pairs of src,dest (i.e., row,column) values. All filled entries are set to zero.
Referenced by initCinfo().
unsigned int SparseMsg::randomConnect | ( | double | probability | ) |
Returns number of synapses formed. Fills it in transpose form, because we need to count and index the number of synapses on the target, so we need to iterate over the sources in the inner loop. Once full, does the transpose. Should really have a seed argument for the random number. Later need a way to fast-forward mtrand to just the entries we need to fill.
References SparseMatrix< T >::addRow(), SparseMatrix< T >::clear(), Msg::e1(), Msg::e2(), Msg::e2_, Element::localDataStart(), Element::markRewired(), mtrand(), SparseMatrix< T >::nColumns(), SparseMatrix< T >::nRows(), Element::numData(), Element::numLocalData(), Element::resizeField(), and SparseMatrix< T >::transpose().
Referenced by setProbability(), setRandomConnectivity(), setSeed(), and testSparseMsg().
void SparseMsg::setEntry | ( | unsigned int | row, | |
unsigned int | column, | |||
unsigned int | value | |||
) |
References SparseMatrix< T >::set().
Referenced by initCinfo().
void SparseMsg::setMatrix | ( | const SparseMatrix< unsigned int > & | m | ) |
Assigns the whole connection matrix
Referenced by copy().
void SparseMsg::setProbability | ( | double | value | ) |
References mtseed(), and randomConnect().
Referenced by initCinfo().
void SparseMsg::setRandomConnectivity | ( | double | probability, | |
long | seed | |||
) |
References mtseed(), and randomConnect().
Referenced by initCinfo().
void SparseMsg::setSeed | ( | long | value | ) |
References mtseed(), and randomConnect().
Referenced by initCinfo().
void SparseMsg::sources | ( | vector< vector< Eref > > & | v | ) | const [virtual] |
Return all the sources of e2 from e1, that is, all the msgs coming into specified entries on e2 from e1.
ALLDATA used when the sources include all data entries on a source. Indexing is v[dataId in range e2.numData][src list]
Implements Msg.
void SparseMsg::targets | ( | vector< vector< Eref > > & | v | ) | const [virtual] |
Return all the targets of e1 on e2, that is, all the msgs going from specified entries on e1 to e2. ALLDATA used when the targets include all data entries on a target. Indexing is v[dataId in range e1.numData][tgt list]
Implements Msg.
void SparseMsg::transpose | ( | ) |
References Msg::e1(), Msg::e2(), Element::markRewired(), and SparseMatrix< T >::transpose().
Referenced by initCinfo().
void SparseMsg::tripletFill | ( | vector< unsigned int > | src, | |
vector< unsigned int > | dest, | |||
vector< unsigned int > | field | |||
) |
Fills up the entire message based on triplets of src,destDataIndex,destFieldIndex
Referenced by initCinfo().
void SparseMsg::unsetEntry | ( | unsigned int | row, | |
unsigned int | column | |||
) |
References SparseMatrix< T >::unset().
Referenced by initCinfo().
void SparseMsg::updateAfterFill | ( | ) |
Utility function to update all sorts of values after we've rebuilt the matrix.
References Msg::e1(), Msg::e2(), Msg::e2_, SparseMatrix< T >::getRow(), Element::localDataStart(), Element::markRewired(), SparseMatrix< T >::nRows(), Element::numLocalData(), and Element::resizeField().
unsigned int Msg::initMsgManagers | ( | ) | [friend] |