CARLsim
5.0.0
CARLsim: a GPU-accelerated SNN simulator
|
Go to the documentation of this file.
72 Impl(
CARLsim *sim,
double errorMargin,
int maxIter,
double stepSizeFraction) {
74 assert(errorMargin>0);
76 assert(stepSizeFraction>0.0f && stepSizeFraction<=1.0f);
81 errorMargin_ = errorMargin;
82 stepSizeFraction_ = stepSizeFraction;
95 wtShouldIncrease_ =
true;
98 needToInitConnection_ =
true;
99 needToInitTargetFiring_ =
true;
101 needToInitAlgo_ =
true;
112 needToInitAlgo_ =
true;
118 if (needToInitConnection_ || needToInitTargetFiring_ || needToInitAlgo_)
122 if (fabs(currentError_) < errorMargin_) {
124 printf(
"SimpleWeightTuner successful: Error margin reached in %d iterations.\n",cntIter_);
130 if (cntIter_ >= maxIter_) {
132 printf(
"SimpleWeightTuner failed: Max number of iterations (%d) reached.\n",maxIter_);
142 assert(connId>=0 && connId<sim_->getNumConnections());
146 adjustRange_ = adjustRange;
148 needToInitConnection_ =
false;
149 needToInitAlgo_ =
true;
154 targetRate_ = targetRate;
155 currentError_ = targetRate;
164 needToInitTargetFiring_ =
false;
165 needToInitAlgo_ =
true;
168 void iterate(
int runDurationMs,
bool printStatus) {
169 assert(runDurationMs>0);
172 if (
done(printStatus)) {
177 assert(!needToInitConnection_);
178 assert(!needToInitTargetFiring_);
188 sim_->
runNetwork(runDurationMs/1000, runDurationMs%1000,
false);
193 printf(
"#%d: rate=%.4fHz, target=%.4fHz, error=%.7f, errorMargin=%.7f\n", cntIter_, thisRate, targetRate_,
194 thisRate-targetRate_, errorMargin_);
197 currentError_ = thisRate - targetRate_;
201 if (
done(printStatus)) {
206 if (wtStepSize_>0 && thisRate>targetRate_ || wtStepSize_<0 && thisRate<targetRate_) {
211 wtStepSize_ = -wtStepSize_/2.0;
215 sim_->
biasWeights(connId_, wtStepSize_, adjustRange_);
224 if (!needToInitAlgo_)
228 assert(!needToInitConnection_);
229 assert(!needToInitTargetFiring_);
236 wtShouldIncrease_ =
true;
237 wtStepSize_ = stepSizeFraction_ * (wtRange_->
max - wtRange_->
min);
238 #if defined(WIN32) || defined(WIN64)
239 currentError_ = DBL_MAX;
241 currentError_ = std::numeric_limits<double>::max();
251 if (wt.
init != wtInit_) {
258 needToInitAlgo_ =
false;
267 bool needToInitConnection_;
268 bool needToInitTargetFiring_;
269 bool needToInitAlgo_;
286 bool wtShouldIncrease_;
287 double currentError_;
292 double stepSizeFraction_;
302 _impl( new
Impl(sim, errorMargin, maxIter, stepSizeFraction) ) {}
@ RUN_STATE
run state, where the model is stepped
void setTargetFiringRate(int grpId, double targetRate)
Impl(CARLsim *sim, double errorMargin, int maxIter, double stepSizeFraction)
a range struct for synaptic weight magnitudes
void setConnectionToTune(short int connId, double initWt=-1.0, bool adjustRange=true)
Sets up the connection to tune.
void setPersistentData(bool persistentData)
Sets PersistentMode either on (true) or off (false)
int runNetwork(int nSec, int nMsec=0, bool printRunSummary=true)
run the simulation for time=(nSec*seconds + nMsec*milliseconds)
void biasWeights(short int connId, float bias, bool updateWeightRange=false)
Adds a constant bias to the weight of every synapse in the connection.
void stopRecording()
Ends a recording period.
void setConnectionToTune(short int connId, double initWt, bool adjustRange)
void iterate(int runDurationMs, bool printStatus)
~SimpleWeightTuner()
Destructor.
Private implementation of the Stopwatch Utility.
float getPopMeanFiringRate()
Returns the mean firing rate of the entire neuronal population.
void setTargetFiringRate(int grpId, double targetRate)
Sets up the target firing rate of a specific group.
void reset()
Resets the algorithm to initial conditions.
SimpleWeightTuner(CARLsim *sim, double errorMargin=1e-3, int maxIter=100, double stepSizeFraction=0.5)
Creates a new instance of class SimpleWeightTuner.
bool done(bool printMessage=false)
Determines whether a termination criterion has been met.
SpikeMonitor * getSpikeMonitor(int grpId)
Returns the number of spikes per neuron for a certain group.
CARLsim User Interface This class provides a user interface to the public sections of CARLsimCore sou...
RangeWeight getWeightRange(short int connId)
returns the RangeWeight struct for a specific connection ID
void startRecording()
Starts a new recording period.
CARLsimState getCARLsimState()
Writes population weights from gIDpre to gIDpost to file fname in binary.
void iterate(int runDurationMs=1000, bool printStatus=true)
Performs an iteration step of the tuning algorithm.
SpikeMonitor * setSpikeMonitor(int grpId, const std::string &fileName)
Sets a Spike Monitor for a groups, prints spikes to binary file.
bool done(bool printMessage)