The ConnectionMonitor class allows a user record weights from a particular connection. First, the method CARLsim::setConnectionMonitor must be called on a specific pair of pre-synaptic and post-synaptic group. This method then returns a pointer to a ConnectionMonitor object, which can be queried for connection data.
By default, a snapshot of all the weights will be taken once per second and dumped to file. The easiest way to use a ConnectionMonitor is to call CARLsim::setConnectionMonitor with file string "default". This will create a file with path "results/conn_{name of pre-group}_{name of post-group}.dat". It is also possible to specify a custom file string instead. Alternatively, the user may suppress creation of the binary file by using file string "null" instead.
Periodic storing can be disabled by calling ConnectionMonitor::setUpdateTimeInterval with argument intervalSec=-1.
Additionally, during a CARLsim simulation, the ConnectionMonitor object returned by CARLsim::setConnectionMonitor can be queried for connection data. The user may take a snapshot of the weights at any point in time using the method ConnectionMonitor::takeSnapshot. Note that a snapshot taken with this method will also be stored in the binary file. However, the binary file will never contain the same snapshot (captured with a certain timestamp) twice.
If at least two snapshots have been taken, the method ConnectionMonitor::calcWeightChanges will calculate the weight changes since the last snapshot. To make sure you are comparing the right snapshots, compare the timestamps returend by ConnectionMonitor::getTimeMsCurrentSnapshot and ConnectionMonitor::getTimeMsLastSnapshot.
Weights can be visualized in the Matlab Offline Analysis Toolbox (OAT) using the ConnectionMonitor utility. The OAT offers ways to plot 2D weight matrices, as well as receptive fields and response fields.
Weights can also be visualized in C++ using ConnectionMonitor::print and ConnectionMonitor::printSparse.
Example to store weights in binary every second:
Example that stores weight at the beginning and end of a simulation:
Example that periodically stores to binary and does some analysis on returned weight vector
printf("The weight from pre-neuron ID 3 to post-neuron ID 7 is: %f\n",wt[3][7]);
- Note
- A snapshot taken programmatically with ConnectionMonitor::takeSnapshot can be put in the binary file by setting an optional input flag
writeToFile
to true.
Definition at line 152 of file connection_monitor.h.
std::vector< std::vector< float > > calcWeightChanges |
( |
| ) |
|
This function calculates the difference between the current state of the weight matrix and what it was when taking the last snapshot. Weight change is reported for every synapse, in a 2D vector where the first dimension corresponds to pre-synaptic neuron ID and the second dimension corresponds to post-synaptic neuron ID. For example, element wtChange[3][8] of the return argumentr will indicate the signed weight change since the last snapshot for the synapse that connects preNeurId=3 to postNeurId=8. Synapses that are not allocated (i.e., that do not exist) are marked as float value NAN in the weight matrix. Synapses that do exist, but have zero weight, are marked as 0.0f in the weight matrix.
In order to get the current state of the weight matrix, this function will take a snapshot itself, but will not write it to file.
- Returns
- a 2D vector of weight changes, where the first dimension is pre-synaptic neuron ID and the second dimension is post-synaptic neuron ID. Non-existent synapses are marked with NAN.
- Since
- v3.0
Definition at line 68 of file connection_monitor.cpp.
double getMaxWeight |
( |
bool |
getCurrent = false | ) |
|
This function returns the maximum weight value of all synapses in the connection.
If getCurrent is set to true, then the function will return the currently largest weight value. In a plastic connection, this value might be different from the upper bound of the weight range specified when setting up the network (i.e., the max field of the RangeWeight struct). In order to get the current state of the weight matrix, this function will take a snapshot itself, but will not write it to file.
If getCurrent is set to false, then the upper bound of the configured weight range will be returned.
- Parameters
-
[in] | getCurrent | whether to return the currently largest weight value (true) or the upper bound of the weight range specified during setup (false). Default: false. |
- Since
- v3.1
Definition at line 107 of file connection_monitor.cpp.
double getMinWeight |
( |
bool |
getCurrent = false | ) |
|
This function returns the minimum weight value of all synapses in the connection.
If getCurrent is set to true, then the function will return the currently smallest weight value. In a plastic connection, this value might be different from the lower bound of the weight range specified when setting up the network (i.e., the min field of the RangeWeight struct). In order to get the current state of the weight matrix, this function will take a snapshot itself, but will not write it to file.
If getCurrent is set to false, then the lower bound of the configured weight range will be returned.
- Parameters
-
[in] | getCurrent | whether to return the currently smallest weight value (true) or the lower bound of the weight range specified during setup (false). Default: false. |
- Since
- v3.1
Definition at line 111 of file connection_monitor.cpp.
int getNumWeightsWithValue |
( |
double |
value | ) |
|
This function returns the number of synaptic weights that have exactly some specific value. It could be used to determine the sparsity of the connection matrix (wtValue==0.0f).
In order to get the current state of the weight matrix, this function will take a snapshot itself, but will not write it to file.
Machine epsilon (FLT_EPSILON) is used for floating point equality. That is, the weight value is considered equal to the input value if fabs(wt-value)<=FLT_EPSILON (inclusive).
This is a convenience function whose result is equivalent to getNumWeightsInRange(value-FLT_EPSILON,value+FLT_EPSILON).
- Parameters
-
[in] | value | the exact weight value to look for |
- See also
- ConnectionMonitor::getPercentWeightsWithValue
-
ConnectionMonitor::getNumWeightsInRange
- Since
- v3.1
Definition at line 131 of file connection_monitor.cpp.
double getPercentWeightsWithValue |
( |
double |
value | ) |
|
This function returns the percentage of synaptic weights that have exactly some specific value. It could be used to determine the sparsity of the connection matrix (wtValue==0.0f).
In order to get the current state of the weight matrix, this function will take a snapshot itself, but will not write it to file.
Machine epsilon (FLT_EPSILON) is used for floating point equality. That is, the weight value is considered equal to the input value if fabs(wt-value)<=FLT_EPSILON (inclusive).
This is a convenience function whose result is equivalent to getNumWeightsWithValue(value)*100.0/getNumSynapses().
- Parameters
-
[in] | value | the exact weight value to look for |
- See also
- ConnectionMonitor::getNumWeightsWithValue
-
ConnectionMonitor::getNumWeightsInRange
- Since
- v3.1
Definition at line 144 of file connection_monitor.cpp.