Skip to content

Commit 6444797

Browse files
author
Vanessa Arndorfer
committed
code clean-up and STDP logic fixes
1 parent 4034455 commit 6444797

File tree

5 files changed

+37
-61
lines changed

5 files changed

+37
-61
lines changed

Simulator/Edges/Neuro/AllDynamicSTDPSynapses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ AllDynamicSTDPSynapses::AllDynamicSTDPSynapses(int numVertices, int maxEdges) :
1717
/// Setup the internal structure of the class (allocate memories and initialize them).
1818
void AllDynamicSTDPSynapses::setupEdges()
1919
{
20-
setupEdges(Simulator::getInstance().getDeltaT(),
20+
setupEdges(Simulator::getInstance().getTotalVertices(),
2121
Simulator::getInstance().getMaxEdgesPerVertex());
2222
}
2323

Simulator/Edges/Neuro/AllDynamicSTDPSynapses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Each kind of synapse parameter is stored in a 2D array. Each item in the first
1010
* dimension of the array corresponds with each neuron, and each item in the second
1111
* dimension of the array corresponds with a synapse parameter of each synapse of the neuron.
12-
* Because each neuron owns different number of synapses, the number of synapses
12+
* Because each neuron owns different number of synapses, the number of synapses
1313
* for each neuron is stored in a 1D array, edge_counts.
1414
*
1515
* For CUDA implementation, we used another structure, AllDSSynapsesDevice, where synapse

Simulator/Edges/Neuro/AllSTDPSynapses.cpp

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -275,28 +275,28 @@ void AllSTDPSynapses::advanceEdge(BGSIZE iEdg, AllVertices &neurons)
275275
// pre and post neurons index
276276
int idxPre = sourceVertexIndex_[iEdg];
277277
int idxPost = destVertexIndex_[iEdg];
278-
uint64_t spikeHistory, spikeHistory2;
278+
uint64_t t_post, t_pre;
279279
BGFLOAT delta;
280-
BGFLOAT epre, epost;
280+
281+
// epre and epost are set to 1 for the independent model [Froemke and Dan (2002)]
282+
BGFLOAT epre = 1.0;
283+
BGFLOAT epost = 1.0;
281284

282285
if (fPre) { // preSpikeHit
283-
// spikeCount points to the next available position of spike_history,
284-
// so the getSpikeHistory w/offset = -2 will return the spike time
285-
// just one before the last spike.
286-
spikeHistory = spNeurons.getSpikeHistory(idxPre, -2);
287-
288-
epre = 1.0;
289-
epost = 1.0;
290-
// call the learning function stdpLearning() for each pair of
291-
// pre-post spikes
286+
// call the learning function stdpLearning() for each pair of pre-post spikes
292287
int offIndex = -1; // last spike
293288
while (true) {
294-
spikeHistory = spNeurons.getSpikeHistory(idxPost, offIndex);
295-
if (spikeHistory == numeric_limits<unsigned long>::max())
289+
// time of the offset post-spike hit
290+
uint64_t t_post = spNeurons.getSpikeHistory(idxPost, offIndex);
291+
292+
// break if no post-spike is found
293+
if (t_post == numeric_limits<unsigned long>::max())
296294
break;
295+
297296
// delta is the spike interval between pre-post spikes
298-
// (include pre-synaptic transmission delay)
299-
delta = -static_cast<BGFLOAT>(g_simulationStep - spikeHistory) * deltaT;
297+
// deltaT converts the timestep to seconds
298+
delta = -static_cast<BGFLOAT>(g_simulationStep - t_post) * deltaT;
299+
300300
/*
301301
LOG4CPLUS_DEBUG(fileLogger_,"\nAllSTDPSynapses::advanceSynapse: fPre" << endl
302302
<< "\tiEdg: " << iEdg << endl
@@ -320,28 +320,25 @@ void AllSTDPSynapses::advanceEdge(BGSIZE iEdg, AllVertices &neurons)
320320
}
321321

322322
if (fPost) { // postSpikeHit
323-
// spikeCount points to the next available position of spike_history,
324-
// so the getSpikeHistory w/offset = -2 will return the spike time
325-
// just one before the last spike.
326-
spikeHistory = spNeurons.getSpikeHistory(idxPost, -2);
327-
epost = 1.0;
328-
epre = 1;
329-
330-
331-
// call the learning function stdpLearning() for each pair of
332-
// post-pre spikes
323+
// call the learning function stdpLearning() for each pair of post-pre spikes
333324
int offIndex = -1; // last spike
334325
while (true) {
335-
spikeHistory = spNeurons.getSpikeHistory(idxPre, offIndex);
336-
if (spikeHistory == numeric_limits<unsigned long>::max())
326+
// time when the pre-spike left the source neuron
327+
t_pre = spNeurons.getSpikeHistory(idxPre, offIndex);
328+
329+
// break if no pre-spike is found
330+
if (t_pre == numeric_limits<unsigned long>::max())
337331
break;
338332

339-
if (spikeHistory + total_delay > g_simulationStep) {
333+
// delay accounts for the time it takes the spike to reach the destination neuron
334+
if (t_pre + total_delay > g_simulationStep) {
340335
--offIndex;
341336
continue;
342337
}
338+
343339
// delta is the spike interval between post-pre spikes
344-
delta = static_cast<BGFLOAT>(g_simulationStep - spikeHistory - total_delay) * deltaT;
340+
delta = static_cast<BGFLOAT>(g_simulationStep - t_pre - total_delay) * deltaT;
341+
345342
/*
346343
LOG4CPLUS_DEBUG(fileLogger_,"\nAllSTDPSynapses::advanceSynapse: fPost" << endl
347344
<< "\tiEdg: " << iEdg << endl
@@ -353,6 +350,7 @@ void AllSTDPSynapses::advanceEdge(BGSIZE iEdg, AllVertices &neurons)
353350
<< "\tepost: " << epost << endl
354351
<< "\tdelta: " << delta << endl << endl);
355352
*/
353+
356354
if (delta >= 3.0 * taupos)
357355
break;
358356

@@ -366,7 +364,6 @@ void AllSTDPSynapses::advanceEdge(BGSIZE iEdg, AllVertices &neurons)
366364
psr *= decay;
367365
}
368366

369-
370367
BGFLOAT AllSTDPSynapses::synapticWeightModification(BGSIZE iEdg, BGFLOAT synapticWeight,
371368
double delta)
372369
{
@@ -379,15 +376,11 @@ BGFLOAT AllSTDPSynapses::synapticWeightModification(BGSIZE iEdg, BGFLOAT synapti
379376
BGFLOAT Apos = Apos_[iEdg];
380377
BGFLOAT Wex = Wex_[iEdg];
381378
BGFLOAT &W = W_[iEdg];
382-
edgeType type = type_[iEdg];
383379
BGFLOAT dw = 0;
384-
BGFLOAT oldW = W;
385-
386-
// BGFLOAT modDelta = fabs(delta);
387380

381+
// muneg and mupos default to 0 for the basic multiplicative model
388382
if (delta < -STDPgap) {
389383
// depression
390-
391384
dw = pow(fabs(W) / Wex, muneg) * Aneg * exp(delta / tauneg); // normalize
392385
} else if (delta > STDPgap) {
393386
// potentiation
@@ -411,24 +404,17 @@ void AllSTDPSynapses::stdpLearning(BGSIZE iEdg, double delta, double epost, doub
411404
int srcVertex, int destVertex)
412405
{
413406
BGFLOAT STDPgap = STDPgap_[iEdg];
414-
BGFLOAT muneg = muneg_[iEdg];
415-
BGFLOAT mupos = mupos_[iEdg];
416-
BGFLOAT tauneg = tauneg_[iEdg];
417-
BGFLOAT taupos = taupos_[iEdg];
418-
BGFLOAT Aneg = Aneg_[iEdg];
419-
BGFLOAT Apos = Apos_[iEdg];
420407
BGFLOAT Wex = Wex_[iEdg];
421408
BGFLOAT &W = W_[iEdg];
422409
edgeType type = type_[iEdg];
423410
BGFLOAT oldW = W;
424-
// BGFLOAT modDelta = fabs(delta);
425411

426-
if (delta <= fabs(STDPgap)) {
412+
if (fabs(delta) <= STDPgap) {
427413
return;
428414
}
429415

430416
// dw is the fractional change in synaptic strength; add 1.0 to become the scaling ratio
431-
//dw = 1.0 + dw * epre * epost;
417+
// dw = 1.0 + dw * epre * epost; // used for the non-independent model
432418
BGFLOAT dw = 1.0 + synapticWeightModification(iEdg, W, delta);
433419

434420
// if scaling ratio is less than zero, set it to zero so this synapse, its
@@ -443,6 +429,7 @@ void AllSTDPSynapses::stdpLearning(BGSIZE iEdg, double delta, double epost, doub
443429
if (fabs(W) > Wex) {
444430
W = edgSign(type) * Wex;
445431
}
432+
446433
/*
447434
LOG4CPLUS_DEBUG(edgeLogger_, endl <<
448435
"iEdg value " << iEdg

Simulator/Edges/Neuro/AllSTDPSynapses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Each kind of synapse parameter is stored in a 2D array. Each item in the first
1010
* dimension of the array corresponds with each neuron, and each item in the second
1111
* dimension of the array corresponds with a synapse parameter of each synapse of the neuron.
12-
* Because each neuron owns different number of synapses, the number of synapses
12+
* Because each neuron owns different number of synapses, the number of synapses
1313
* for each neuron is stored in a 1D array, edge_counts.
1414
*
1515
* For CUDA implementation, we used another structure, AllDSSynapsesDevice, where synapse

configfiles/stdp_fE_0.90_10000.xml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<SimInfoParams name="SimInfoParams">
44
<graphmlFile name="graphmlFile">../configfiles/graphs/fE_0.90_10000.graphml</graphmlFile>
55
<SimParams name="SimParams">
6-
<epochDuration name="epochDuration">100.0</epochDuration>
7-
<numEpochs name="numEpochs">3</numEpochs>
6+
<epochDuration name="epochDuration">10.0</epochDuration>
7+
<numEpochs name="numEpochs">1</numEpochs>
88
</SimParams>
99
<SimConfig name="SimConfig">
1010
<maxFiringRate name="maxFiringRate">200</maxFiringRate>
@@ -106,7 +106,7 @@
106106
<e name="e">5.0265e-7</e>
107107
</Wex>
108108
<Aneg name="Aneg">
109-
<i name="i">-52e-2</i>
109+
<i name="i">-0.52</i>
110110
<e name="e">-0.52</e>
111111
</Aneg>
112112
<Apos name="Apos">
@@ -116,17 +116,6 @@
116116
</EdgesParams>
117117

118118
<ConnectionsParams class="ConnStatic" name="ConnectionsParams">
119-
<threshConnsRadius name="threshConnsRadius">0</threshConnsRadius>
120-
<connsPerNeuron name="connsPerNeuron">0</connsPerNeuron>
121-
<rewiringProbability name="rewiringProbability">0</rewiringProbability>
122-
<excWeight name=" excWeight">
123-
<min name="min">2.36936e-38</min>
124-
<max name="max">2.35106e-38</max>
125-
</excWeight>
126-
<inhWeight name=" inhWeight">
127-
<min name="min">9.18355e-41</min>
128-
<max name="max">3.58732e-43</max>
129-
</inhWeight>
130119
</ConnectionsParams>
131120

132121
<LayoutParams class="LayoutNeuro" name="LayoutParams">

0 commit comments

Comments
 (0)