CARLsim  6.1.0
CARLsim: a GPU-accelerated SNN simulator
SimpleWeightTuner Class Reference

Class SimpleWeightTuner. More...

#include <simple_weight_tuner.h>

Classes

class  Impl
 Private implementation of the Stopwatch Utility. More...
 

Public Member Functions

 SimpleWeightTuner (CARLsim *sim, double errorMargin=1e-3, int maxIter=100, double stepSizeFraction=0.5)
 Creates a new instance of class SimpleWeightTuner. More...
 
 ~SimpleWeightTuner ()
 Destructor. More...
 
bool done (bool printMessage=false)
 Determines whether a termination criterion has been met. More...
 
void iterate (int runDurationMs=1000, bool printStatus=true)
 Performs an iteration step of the tuning algorithm. More...
 
void reset ()
 Resets the algorithm to initial conditions. More...
 
void setConnectionToTune (short int connId, double initWt=-1.0, bool adjustRange=true)
 Sets up the connection to tune. More...
 
void setTargetFiringRate (int grpId, double targetRate)
 Sets up the target firing rate of a specific group. More...
 

Detailed Description

The SimpleWeightTuner utility is a class that implements a simple search algorithm inspired by the bisection method.

The usage scenario is to tune the weights of a specific connection (collection of synapses) so that a specific neuron group fires at a predefined target firing rate—without having to recompile the network. A complete code example can be found in the Tutorial subfolder 12_advanced_topics/simple_weight_tuner.

Example usage:

// assume CARLsim object exists with the following components:
int gOut=sim->createGroup("out", nNeur, EXCITATORY_NEURON);
sim->setNeuronParameters(gOut, 0.02f, 0.2f, -65.0f, 8.0f);
int gIn=sim->createSpikeGeneratorGroup("in", nNeur, EXCITATORY_NEURON);
int c0=sim->connect(gIn, gOut, "random", RangeWeight(initWt), 0.1f, RangeDelay(1,10));
// etc.
sim->setupNetwork();
// use weight tuner to find the weights that give 27.4 Hz spiking in gOut
SimpleWeightTuner SWT(sim, 0.01, 100);
SWT.setConnectionToTune(c0, 0.0);
SWT.setTargetFiringRate(gOut, 27.4);
while (!SWT.done()) {
SWT.iterate();
}
See also
Tutorial: 12.4.1 Simple Weight Tuner
Code example: tutorial/12_advanced_topics/simple_weight_tuner/main_simple_weight_tuner.cpp
Since
v3.0

Definition at line 92 of file simple_weight_tuner.h.

Constructor & Destructor Documentation

◆ SimpleWeightTuner()

SimpleWeightTuner ( CARLsim sim,
double  errorMargin = 1e-3,
int  maxIter = 100,
double  stepSizeFraction = 0.5 
)

This method creates a new instance of class SimpleWeightTuner. A SimpleWeightTuner can be used to tune weights on the fly; that is, without having to recompile and build a network. This is useful especially for tuning feedforward weights in large-scale networks that would otherwise take a long time to repeatedly build. For tuning in more complex situations please refer to ECJ (Parameter Tuning Interface).

Parameters
[in]simpointer to CARLsim object
[in]errorMargintermination condition for error margin on target firing rate
[in]maxItertermination condition for max number of iterations
[in]stepSizeFractionstep size for increasing/decreasing weights per iteration
Since
v3.0
See also
ch10_ecj

Definition at line 302 of file simple_weight_tuner.cpp.

◆ ~SimpleWeightTuner()

Cleans up all objects related to SimpleWeightTuner.

Since
v3.0

Definition at line 304 of file simple_weight_tuner.cpp.

Member Function Documentation

◆ done()

bool done ( bool  printMessage = false)

This method checks whether a termination criterion has been met, in which case true is returned.

The algorithm will terminate if any of the following criteria have been met:

  • The firing rate is close enough to the target: `currentFiring - targetFiring < errorMargin'
  • The maximum number of iteration step has been reached: numberOfIter > maxIter
Parameters
[in]printMessageflag whether to print message upon termination
Since
v3.0

Definition at line 313 of file simple_weight_tuner.cpp.

Here is the call graph for this function:

◆ iterate()

void iterate ( int  runDurationMs = 1000,
bool  printStatus = true 
)

This method runs the CARLsim network for a time period of runDurationMs milliseconds, throughout which a SpikeMonitor is recording the firing rate of the group ID specified in setTargetFiringRate.

At the end of the iteration step the recorded firing rate is compared to the target firing rate, and the relative error is computed. If the error is smaller than the specified error margin, the algorithm terminates. If the maximum number of iteration steps is reached, the algorithm terminates. Otherwise the weights of the connection ID specified in setConnectionToTune() are updated, and the next iteration step is ready to be performed.

Parameters
[in]runDurationMstime to run the CARLsim network (ms)
[in]printStatuswhether to print stats at the end of the iteration
Since
v3.0
See also
CARLsim::runNetwork

Definition at line 312 of file simple_weight_tuner.cpp.

Here is the call graph for this function:

◆ reset()

void reset ( )

This method resets the algorithm to the initial conditions. It is implicitly called at the beginning and whenever setTargetFiringRate or setConnectionToTune has been called.

Since
v3.0

Definition at line 314 of file simple_weight_tuner.cpp.

Here is the call graph for this function:

◆ setConnectionToTune()

void setConnectionToTune ( short int  connId,
double  initWt = -1.0,
bool  adjustRange = true 
)

This method sets up the connection ID to tune. The algorithm will repeatedely change the synaptic weights of this connection until the firing rate of a group (speficied via setTargetFiringRate) matches a certain target firing rate (specified in SimpleWeightTuner).

If the initial weight is set to a negative value, the algorithm will start with whatever weights have been specified when setting up the connection in CARLsim::connect. Otherwise a bias will be applied to all weights such that initWt matches the field initWt of the connection's RangeWeight struct.

If adjustRange is set to true, the [minWt,maxWt] ranges will be adjusted automatically should the weight go out of bounds.

See also
CARLsim::connect
RangeWeight
CARLsim::biasWeights
Since
v3.0

Definition at line 306 of file simple_weight_tuner.cpp.

Here is the call graph for this function:

◆ setTargetFiringRate()

void setTargetFiringRate ( int  grpId,
double  targetRate 
)

This method sets up the target firing rate (Hz) of a specific group to achieve via changing the weights of the connection specified in setConnectionToTune.

A SpikeMonitor will be set up for the group if it does not already exist. SpikeMonitor::getPopMeanFiringRate will be used to determine the group's firing activity, and compare it to targetRate in order to compute the error margin.

Parameters
[in]grpIdthe group ID
[in]targetRatetarget firing rate (Hz) of the group
Attention
If a SpikeMonitor already exists for this group, SimpleWeightTuner will use the same one and turn PersistentMode off.
Since
v3.0
See also
SpikeMonitor

Definition at line 309 of file simple_weight_tuner.cpp.

Here is the call graph for this function:

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