24 Impl(
CARLsim *sim,
double errorMargin,
int maxIter,
double stepSizeFraction) {
26 assert(errorMargin>0);
28 assert(stepSizeFraction>0.0f && stepSizeFraction<=1.0f);
33 errorMargin_ = errorMargin;
34 stepSizeFraction_ = stepSizeFraction;
47 wtShouldIncrease_ =
true;
50 needToInitConnection_ =
true;
51 needToInitTargetFiring_ =
true;
53 needToInitAlgo_ =
true;
64 needToInitAlgo_ =
true;
68 bool done(
bool printMessage) {
70 if (needToInitConnection_ || needToInitTargetFiring_ || needToInitAlgo_)
74 if (fabs(currentError_) < errorMargin_) {
76 printf(
"SimpleWeightTuner successful: Error margin reached in %d iterations.\n",cntIter_);
82 if (cntIter_ >= maxIter_) {
84 printf(
"SimpleWeightTuner failed: Max number of iterations (%d) reached.\n",maxIter_);
94 assert(connId>=0 && connId<sim_->getNumConnections());
98 adjustRange_ = adjustRange;
100 needToInitConnection_ =
false;
101 needToInitAlgo_ =
true;
106 targetRate_ = targetRate;
107 currentError_ = targetRate;
116 needToInitTargetFiring_ =
false;
117 needToInitAlgo_ =
true;
120 void iterate(
int runDurationMs,
bool printStatus) {
121 assert(runDurationMs>0);
124 if (
done(printStatus)) {
129 assert(!needToInitConnection_);
130 assert(!needToInitTargetFiring_);
140 sim_->
runNetwork(runDurationMs/1000, runDurationMs%1000,
false);
145 printf(
"#%d: rate=%.4fHz, target=%.4fHz, error=%.7f, errorMargin=%.7f\n", cntIter_, thisRate, targetRate_,
146 thisRate-targetRate_, errorMargin_);
149 currentError_ = thisRate - targetRate_;
153 if (
done(printStatus)) {
158 if ((wtStepSize_>0 && thisRate>targetRate_) || (wtStepSize_<0 && thisRate<targetRate_)) {
163 wtStepSize_ = -wtStepSize_/2.0;
167 sim_->
biasWeights(connId_, wtStepSize_, adjustRange_);
176 if (!needToInitAlgo_)
180 assert(!needToInitConnection_);
181 assert(!needToInitTargetFiring_);
188 wtShouldIncrease_ =
true;
189 wtStepSize_ = stepSizeFraction_ * (wtRange_->
max - wtRange_->
min);
190 #if defined(WIN32) || defined(WIN64) 191 currentError_ = DBL_MAX;
193 currentError_ = std::numeric_limits<double>::max();
203 if (wt.
init != wtInit_) {
210 needToInitAlgo_ =
false;
219 bool needToInitConnection_;
220 bool needToInitTargetFiring_;
221 bool needToInitAlgo_;
238 bool wtShouldIncrease_;
239 double currentError_;
244 double stepSizeFraction_;
254 _impl( new
Impl(sim, errorMargin, maxIter, stepSizeFraction) ) {}
void startRecording()
Starts a new recording period.
carlsimState_t getCARLsimState()
Returns the current CARLsim state.
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.
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.
int runNetwork(int nSec, int nMsec=0, bool printRunSummary=true, bool copyState=false)
run the simulation for time=(nSec*seconds + nMsec*milliseconds)
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)
run state, where the model is stepped
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.
SpikeMonitor * getSpikeMonitor(int grpId)
returns pointer to previously allocated SpikeMonitor object, NULL else
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