示例#1
0
void caffe_rng_uniform(const int n, const Dtype a, const Dtype b, Dtype* r) {
    CHECK_GE(n, 0);
    CHECK(r);
    CHECK_LE(a, b);
    boost::uniform_real<Dtype> random_distribution(a, caffe_nextafter<Dtype>(b));
    boost::variate_generator<caffe::rng_t*, boost::uniform_real<Dtype> >
    variate_generator(caffe_rng(), random_distribution);
    for (int i = 0; i < n; ++i) {
        r[i] = variate_generator();
    }
}
示例#2
0
void caffe_rng_bernoulli(const int n, const Dtype p, unsigned int* r) {
    CHECK_GE(n, 0);
    CHECK(r);
    CHECK_GE(p, 0);
    CHECK_LE(p, 1);
    boost::bernoulli_distribution<Dtype> random_distribution(p);
    boost::variate_generator<caffe::rng_t*, boost::bernoulli_distribution<Dtype> >
    variate_generator(caffe_rng(), random_distribution);
    for (int i = 0; i < n; ++i) {
        r[i] = static_cast<unsigned int>(variate_generator());
    }
}
示例#3
0
void caffe_rng_gaussian(const int n, const Dtype a,
                        const Dtype sigma, Dtype* r) {
    CHECK_GE(n, 0);
    CHECK(r);
    CHECK_GT(sigma, 0);
    boost::normal_distribution<Dtype> random_distribution(a, sigma);
    boost::variate_generator<caffe::rng_t*, boost::normal_distribution<Dtype> >
    variate_generator(caffe_rng(), random_distribution);
    for (int i = 0; i < n; ++i) {
        r[i] = variate_generator();
    }
}
示例#4
0
void caffe_rng_bernoulli(const int n, const Dtype p, int* r) {
  CHECK_GE(n, 0);
  CHECK(r);
  CHECK_GE(p, 0);
  CHECK_LE(p, 1);
#ifdef USE_MKL
  bernoulli_generate(n, p, r);
#else
  boost::bernoulli_distribution<Dtype> random_distribution(p);
  boost::variate_generator<caffe::rng_t*, boost::bernoulli_distribution<Dtype> >
      variate_generator(caffe_rng(), random_distribution);
  for (int i = 0; i < n; ++i) {
    r[i] = variate_generator();
  }
#endif
}