CARLsim
4.1.0
CARLsim: a GPU-accelerated SNN simulator
|
Go to the documentation of this file.
71 Impl(
CARLsim *sim,
double errorMargin,
int maxIter,
double stepSizeFraction) {
73 assert(errorMargin>0);
75 assert(stepSizeFraction>0.0f && stepSizeFraction<=1.0f);
80 errorMargin_ = errorMargin;
81 stepSizeFraction_ = stepSizeFraction;
94 wtShouldIncrease_ =
true;
97 needToInitConnection_ =
true;
98 needToInitTargetFiring_ =
true;
100 needToInitAlgo_ =
true;
111 needToInitAlgo_ =
true;
117 if (needToInitConnection_ || needToInitTargetFiring_ || needToInitAlgo_)
121 if (fabs(currentError_) < errorMargin_) {
123 printf(
"SimpleWeightTuner successful: Error margin reached in %d iterations.\n",cntIter_);
129 if (cntIter_ >= maxIter_) {
131 printf(
"SimpleWeightTuner failed: Max number of iterations (%d) reached.\n",maxIter_);
141 assert(connId>=0 && connId<sim_->getNumConnections());
145 adjustRange_ = adjustRange;
147 needToInitConnection_ =
false;
148 needToInitAlgo_ =
true;
153 targetRate_ = targetRate;
154 currentError_ = targetRate;
163 needToInitTargetFiring_ =
false;
164 needToInitAlgo_ =
true;
167 void iterate(
int runDurationMs,
bool printStatus) {
168 assert(runDurationMs>0);
171 if (
done(printStatus)) {
176 assert(!needToInitConnection_);
177 assert(!needToInitTargetFiring_);
187 sim_->
runNetwork(runDurationMs/1000, runDurationMs%1000,
false);
192 printf(
"#%d: rate=%.4fHz, target=%.4fHz, error=%.7f, errorMargin=%.7f\n", cntIter_, thisRate, targetRate_,
193 thisRate-targetRate_, errorMargin_);
196 currentError_ = thisRate - targetRate_;
200 if (
done(printStatus)) {
205 if (wtStepSize_>0 && thisRate>targetRate_ || wtStepSize_<0 && thisRate<targetRate_) {
210 wtStepSize_ = -wtStepSize_/2.0;
214 sim_->
biasWeights(connId_, wtStepSize_, adjustRange_);
223 if (!needToInitAlgo_)
227 assert(!needToInitConnection_);
228 assert(!needToInitTargetFiring_);
235 wtShouldIncrease_ =
true;
236 wtStepSize_ = stepSizeFraction_ * (wtRange_->
max - wtRange_->
min);
237 #if defined(WIN32) || defined(WIN64)
238 currentError_ = DBL_MAX;
240 currentError_ = std::numeric_limits<double>::max();
250 if (wt.
init != wtInit_) {
257 needToInitAlgo_ =
false;
266 bool needToInitConnection_;
267 bool needToInitTargetFiring_;
268 bool needToInitAlgo_;
285 bool wtShouldIncrease_;
286 double currentError_;
291 double stepSizeFraction_;
301 _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)