Exemplo n.º 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);
  std::uniform_real<Dtype> random_distribution(a, caffe_nextafter<Dtype>(b));
  rng_t* engine = caffe_rng();
  for (int i = 0; i < n; ++i) {
    r[i] = random_distribution(*engine);
  }
}
Exemplo n.º 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);
  std::bernoulli_distribution random_distribution(p);
  rng_t* engine = caffe_rng();
  for (int i = 0; i < n; ++i) {
    r[i] = static_cast<unsigned int>(random_distribution(*engine));
  }
}
Exemplo n.º 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);
  std::normal_distribution<Dtype> random_distribution(a, sigma);
  rng_t* engine = caffe_rng();
  for (int i = 0; i < n; ++i) {
    r[i] = random_distribution(*engine);
  }
}
Exemplo n.º 4
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();
    }
}
Exemplo n.º 5
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());
    }
}
Exemplo n.º 6
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();
    }
}
Exemplo n.º 7
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
}