15 assert(errorMargin>0);
17 assert(stepSizeFraction>0.0f && stepSizeFraction<=1.0f);
22 errorMargin_ = errorMargin;
23 stepSizeFraction_ = stepSizeFraction;
36 wtShouldIncrease_ =
true;
39 needToInitConnection_ =
true;
40 needToInitTargetFiring_ =
true;
42 needToInitAlgo_ =
true;
59 needToInitAlgo_ =
true;
65 if (needToInitConnection_ || needToInitTargetFiring_ || needToInitAlgo_)
69 if (fabs(currentError_) < errorMargin_) {
71 printf(
"SimpleWeightTuner successful: Error margin reached in %d iterations.\n",cntIter_);
77 if (cntIter_ >= maxIter_) {
79 printf(
"SimpleWeightTuner failed: Max number of iterations (%d) reached.\n",maxIter_);
89 assert(connId>=0 && connId<sim_->getNumConnections());
93 adjustRange_ = adjustRange;
95 needToInitConnection_ =
false;
96 needToInitAlgo_ =
true;
101 targetRate_ = targetRate;
102 currentError_ = targetRate;
111 needToInitTargetFiring_ =
false;
112 needToInitAlgo_ =
true;
116 assert(runDurationMs>0);
119 if (
done(printStatus)) {
124 assert(!needToInitConnection_);
125 assert(!needToInitTargetFiring_);
135 sim_->
runNetwork(runDurationMs/1000, runDurationMs%1000,
false);
140 printf(
"#%d: rate=%.4fHz, target=%.4fHz, error=%.7f, errorMargin=%.7f\n", cntIter_, thisRate, targetRate_,
141 thisRate-targetRate_, errorMargin_);
144 currentError_ = thisRate - targetRate_;
148 if (
done(printStatus)) {
153 if ((wtStepSize_>0 && thisRate>targetRate_) || (wtStepSize_<0 && thisRate<targetRate_)) {
158 wtStepSize_ = -wtStepSize_/2.0;
162 sim_->
biasWeights(connId_, wtStepSize_, adjustRange_);
172 void SimpleWeightTuner::initAlgo() {
173 if (!needToInitAlgo_)
177 assert(!needToInitConnection_);
178 assert(!needToInitTargetFiring_);
185 wtShouldIncrease_ =
true;
186 wtStepSize_ = stepSizeFraction_ * (wtRange_->
max - wtRange_->
min);
187 #if defined(WIN32) || defined(WIN64)
188 currentError_ = DBL_MAX;
190 currentError_ = std::numeric_limits<double>::max();
200 if (wt.
init != wtInit_) {
207 needToInitAlgo_ =
false;
void startRecording()
Starts a new recording period.
carlsimState_t getCARLsimState()
Returns the current CARLsim state.
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.
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 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.
run state, where the model is stepped
a range struct for synaptic weight magnitudes
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)
RangeWeight getWeightRange(short int connId)
returns the RangeWeight struct for a specific connection ID