From 04ca88ac15beb35cd127e7c6c2233b774e12c994 Mon Sep 17 00:00:00 2001 From: Kai Li Date: Sat, 11 Jan 2014 23:51:54 +0800 Subject: Fixed uniform distribution upper bound to be inclusive --- src/caffe/util/math_functions.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/caffe/util/math_functions.cpp') diff --git a/src/caffe/util/math_functions.cpp b/src/caffe/util/math_functions.cpp index c3c0a69c..850a408f 100644 --- a/src/caffe/util/math_functions.cpp +++ b/src/caffe/util/math_functions.cpp @@ -1,8 +1,10 @@ // Copyright 2013 Yangqing Jia // Copyright 2014 kloudkl@github +#include //#include #include +#include #include #include @@ -281,6 +283,11 @@ void caffe_powx(const int n, const double* a, const double b, map_vector_double_t(y, n) = const_map_vector_double_t(a, n).array().pow(b); } +template +Dtype caffe_nextafter(const Dtype b) { + return boost::math::nextafter(b, std::numeric_limits::max()); +} + template <> void caffe_vRngUniform(const int n, float* r, const float a, const float b) { @@ -288,7 +295,8 @@ void caffe_vRngUniform(const int n, float* r, // n, r, a, b)); // FIXME check if boundaries are handled in the same way ? - boost::uniform_real random_distribution(a, b); + boost::random::uniform_real_distribution random_distribution( + a, caffe_nextafter(b)); Caffe::random_generator_t &generator = Caffe::vsl_stream(); for(int i = 0; i < n; i += 1) @@ -304,7 +312,8 @@ void caffe_vRngUniform(const int n, double* r, // n, r, a, b)); // FIXME check if boundaries are handled in the same way ? - boost::uniform_real random_distribution(a, b); + boost::random::uniform_real_distribution random_distribution( + a, caffe_nextafter(b)); Caffe::random_generator_t &generator = Caffe::vsl_stream(); for(int i = 0; i < n; i += 1) @@ -316,6 +325,7 @@ void caffe_vRngUniform(const int n, double* r, template <> void caffe_vRngGaussian(const int n, float* r, const float a, const float sigma) { + DCHECK(sigma > 0); //VSL_CHECK(vsRngGaussian(VSL_RNG_METHOD_GAUSSIAN_BOXMULLER, // Caffe::vsl_stream(), n, r, a, sigma)); @@ -333,6 +343,7 @@ void caffe_vRngGaussian(const int n, float* r, const float a, template <> void caffe_vRngGaussian(const int n, double* r, const double a, const double sigma) { + DCHECK(sigma > 0); //VSL_CHECK(vdRngGaussian(VSL_RNG_METHOD_GAUSSIAN_BOXMULLER, // Caffe::vsl_stream(), n, r, a, sigma)); -- cgit v1.2.3