ulong nextPrime(int p, int s, ulong n, ulong k, ulong *x) { // find minimal i s.t. i > k and i unmarked ulong newK = k+1; ulong local = MAX( localIdx(p,s,n,newK), 0); // do not consider primes outside our range while(local < blockSize(p,s,n)-1 && x[local] == 0) { local++; } if(x[local] == 0) { return LLONG_MAX; // no primes for this processor. This is possible. } else { // if we get here we assume we found a prime! return globalIdx(p,s,n,local); } } /* end nextPrime */
void verifyWeightChange(unsigned epoch, nemo::Simulation* sim, unsigned m, float reward) { unsigned checked = 0; for(unsigned local = 0; local < groupSize; ++local) { const std::vector<synapse_id>& synapses = sim->getSynapsesFrom(globalIdx(0, local)); for(std::vector<synapse_id>::const_iterator id = synapses.begin(); id != synapses.end(); ++id) { unsigned target = sim->getSynapseTarget(*id); if(local != localIdx(target)) continue; unsigned actualDelay = sim->getSynapseDelay(*id); BOOST_REQUIRE_EQUAL(delay(localIdx(target)), actualDelay); BOOST_REQUIRE(sim->getSynapsePlastic(*id)); /* dt is positive for pre-post pair, and negative for post-pre * pairs */ int dt = -(int(postFireDelay - actualDelay)); float dw_expected = 0.0f; if(dt > 0) { dw_expected = dwPost(dt-1); } else if(dt <= 0) { dw_expected = dwPre(dt); } float expectedWeight = initWeight + epoch * reward * dw_expected; float actualWeight = sim->getSynapseWeight(*id); const float tolerance = 0.001f; // percent BOOST_REQUIRE_CLOSE(expectedWeight, actualWeight, tolerance); checked += 1; } } std::cout << "Epoch " << epoch << ": checked " << checked << " synapses\n"; }