73 Impl(
CARLsim *sim,
double errorMargin,
int maxIter,
double stepSizeFraction) {
75 assert(errorMargin>0);
77 assert(stepSizeFraction>0.0f && stepSizeFraction<=1.0f);
82 errorMargin_ = errorMargin;
83 stepSizeFraction_ = stepSizeFraction;
96 wtShouldIncrease_ =
true;
99 needToInitConnection_ =
true;
100 needToInitTargetFiring_ =
true;
102 needToInitAlgo_ =
true;
113 needToInitAlgo_ =
true;
119 if (needToInitConnection_ || needToInitTargetFiring_ || needToInitAlgo_)
123 if (fabs(currentError_) < errorMargin_) {
125 printf(
"SimpleWeightTuner successful: Error margin reached in %d iterations.\n",cntIter_);
131 if (cntIter_ >= maxIter_) {
133 printf(
"SimpleWeightTuner failed: Max number of iterations (%d) reached.\n",maxIter_);
143 assert(connId>=0 && connId<sim_->getNumConnections());
147 adjustRange_ = adjustRange;
149 needToInitConnection_ =
false;
150 needToInitAlgo_ =
true;
155 targetRate_ = targetRate;
156 currentError_ = targetRate;
165 needToInitTargetFiring_ =
false;
166 needToInitAlgo_ =
true;
169 void iterate(
int runDurationMs,
bool printStatus) {
170 assert(runDurationMs>0);
173 if (
done(printStatus)) {
178 assert(!needToInitConnection_);
179 assert(!needToInitTargetFiring_);
189 sim_->
runNetwork(runDurationMs/1000, runDurationMs%1000,
false);
194 printf(
"#%d: rate=%.4fHz, target=%.4fHz, error=%.7f, errorMargin=%.7f\n", cntIter_, thisRate, targetRate_,
195 thisRate-targetRate_, errorMargin_);
198 currentError_ = thisRate - targetRate_;
202 if (
done(printStatus)) {
207 if (wtStepSize_>0 && thisRate>targetRate_ || wtStepSize_<0 && thisRate<targetRate_) {
212 wtStepSize_ = -wtStepSize_/2.0;
216 sim_->
biasWeights(connId_, wtStepSize_, adjustRange_);
225 if (!needToInitAlgo_)
229 assert(!needToInitConnection_);
230 assert(!needToInitTargetFiring_);
237 wtShouldIncrease_ =
true;
238 wtStepSize_ = stepSizeFraction_ * (wtRange_->
max - wtRange_->
min);
239 #if defined(WIN32) || defined(WIN64) 240 currentError_ = DBL_MAX;
242 currentError_ = std::numeric_limits<double>::max();
252 if (wt.
init != wtInit_) {
259 needToInitAlgo_ =
false;
268 bool needToInitConnection_;
269 bool needToInitTargetFiring_;
270 bool needToInitAlgo_;
287 bool wtShouldIncrease_;
288 double currentError_;
293 double stepSizeFraction_;
303 _impl( new
Impl(sim, errorMargin, maxIter, stepSizeFraction) ) {}
CARLsimState getCARLsimState()
Writes population weights from gIDpre to gIDpost to file fname in binary.
void startRecording()
Starts a new recording period.
void setTargetFiringRate(int grpId, double targetRate)
CARLsim User Interface This class provides a user interface to the public sections of CARLsimCore sou...
float getPopMeanFiringRate()
Returns the mean firing rate of the entire neuronal population.
run state, where the model is stepped
SpikeMonitor * getSpikeMonitor(int grpId)
Returns the number of spikes per neuron for a certain group.
void setConnectionToTune(short int connId, double initWt=-1.0, bool adjustRange=true)
Sets up the connection to tune.
~SimpleWeightTuner()
Destructor.
void setConnectionToTune(short int connId, double initWt, bool adjustRange)
SimpleWeightTuner(CARLsim *sim, double errorMargin=1e-3, int maxIter=100, double stepSizeFraction=0.5)
Creates a new instance of class SimpleWeightTuner.
void stopRecording()
Ends a recording period.
void reset()
Resets the algorithm to initial conditions.
bool done(bool printMessage=false)
Determines whether a termination criterion has been met.
void iterate(int runDurationMs, bool printStatus)
void setTargetFiringRate(int grpId, double targetRate)
Sets up the target firing rate of a specific group.
void iterate(int runDurationMs=1000, bool printStatus=true)
Performs an iteration step of the tuning algorithm.
void biasWeights(short int connId, float bias, bool updateWeightRange=false)
Adds a constant bias to the weight of every synapse in the connection.
bool done(bool printMessage)
int runNetwork(int nSec, int nMsec=0, bool printRunSummary=true)
run the simulation for time=(nSec*seconds + nMsec*milliseconds)
a range struct for synaptic weight magnitudes
Private implementation of the Stopwatch Utility.
SpikeMonitor * setSpikeMonitor(int grpId, const std::string &fileName)
Sets a Spike Monitor for a groups, prints spikes to binary file.
void setPersistentData(bool persistentData)
Sets PersistentMode either on (true) or off (false)
Impl(CARLsim *sim, double errorMargin, int maxIter, double stepSizeFraction)
RangeWeight getWeightRange(short int connId)
returns the RangeWeight struct for a specific connection ID