c++ - Change rand_r to srand/rand -
i change use of rand_r method srand/rand or other random generator seed.
in code there loop call train method seed.
int nseeds = 5; (int seed = 0; seed < nseeds; seed ++) { c.train(k, reps, gradientreps, improvereps, lambda, seed, symmetricdiff); } in train method there 3 calls rand_r change. thought call srand @ beginning given seed , call rand() method, don't know if proper way. think?
void cluster::train(int k, int reps, int gradientreps, int improvereps, scalar lambda, int seed, int whichloss) { unsigned int seed_ = seed; unsigned int* sptr = &seed_; //srand(seed); (int rep = 0; rep < reps; rep ++) { (int k = 0; k < k; k ++) if (rep == 0 or (int) chat[k].size() == 0 or (int) chat[k].size() == gd->nnodes) { (int = 0; < gd->nnodes; ++) if (rand_r(sptr) % 2 == 0) chat[k].insert(i); (int = 0; < gd->nedgefeatures; ++) theta[k*gd->nedgefeatures + i] = 0; theta[k*gd->nedgefeatures + rand_r(sptr)%gd->nedgefeatures] = 1.0; } (int k = 0; k < k; k ++) { (int o = 0; o < k; o ++) { int x1 = o; int x2 = rand_r(sptr) % k; // code } } } } link source. above code in main.cpp , cluster.cpp.
if compiler supports c++11, use new random number library. if not, should try boost random (it's same). recommend using mt19937 random number engine, produces pretty quality random numbers, , it's fast.
then code this:
std::mt19937 rng; ... std::uniform_int_distribution dist(0, k - 1); ... int x2 = dist(rng);
Comments
Post a Comment