17 #include <shogun/lib/external/SFMT/SFMT.h> 18 #include <shogun/lib/external/dSFMT/dSFMT.h> 71 m_A = 9.91256303526217e-3;
74 m_x = SG_MALLOC(
float64_t, m_blockCount + 1);
76 m_xComp = SG_MALLOC(uint32_t, m_blockCount);
85 m_y[0] = GaussianPdfDenorm(m_R);
91 m_y[1] = m_y[0] + (m_A / m_x[1]);
94 for(
int i=2; i < m_blockCount; i++)
96 m_x[i] = GaussianPdfDenormInv(m_y[i-1]);
97 m_y[i] = m_y[i-1] + (m_A / m_x[i]);
101 m_x[m_blockCount] = 0.0;
104 m_A_div_y0 = m_A / m_y[0];
111 for(int32_t i=1; i < m_blockCount-1; i++)
115 m_xComp[m_blockCount-1] = 0;
123 m_sfmt_32 = SG_MALLOC(sfmt_t, 1);
124 m_sfmt_64 = SG_MALLOC(sfmt_t, 1);
125 m_dsfmt = SG_MALLOC(dsfmt_t, 1);
132 uint32_t v = sfmt_genrand_uint32(m_sfmt_32);
140 uint64_t v = sfmt_genrand_uint64(m_sfmt_64);
147 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN) 148 if ((size >= sfmt_get_min_array_size32(m_sfmt_32)) && (size % 4) == 0)
151 sfmt_fill_array32(m_sfmt_32, array, size);
156 for (int32_t i=0; i < size; i++)
162 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN) 163 if ((size >= sfmt_get_min_array_size64(m_sfmt_64)) && (size % 2) == 0)
166 sfmt_fill_array64(m_sfmt_64, array, size);
171 for (int32_t i=0; i < size; i++)
178 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN) 179 if ((size >= dsfmt_get_min_array_size()) && (size % 2) == 0)
181 dsfmt_fill_array_open_close(m_dsfmt, array, size);
186 for (int32_t i=0; i < size; i++)
187 array[i] = dsfmt_genrand_open_close(m_dsfmt);
194 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN) 195 if ((size >= dsfmt_get_min_array_size()) && (size % 2) == 0)
197 dsfmt_fill_array_close_open(m_dsfmt, array, size);
202 for (int32_t i=0; i < size; i++)
203 array[i] = dsfmt_genrand_close_open(m_dsfmt);
210 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN) 211 if ((size >= dsfmt_get_min_array_size()) && (size % 2) == 0)
213 dsfmt_fill_array_open_open(m_dsfmt, array, size);
218 for (int32_t i=0; i < size; i++)
219 array[i] = dsfmt_genrand_open_open(m_dsfmt);
226 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN) 227 if ((size >= dsfmt_get_min_array_size()) && (size % 2) == 0)
229 dsfmt_fill_array_close1_open2(m_dsfmt, array, size);
234 for (int32_t i=0; i < size; i++)
235 array[i] = dsfmt_genrand_close1_open2(m_dsfmt);
242 float64_t v = sfmt_genrand_real1(m_sfmt_32);
250 float64_t v = dsfmt_genrand_open_open(m_dsfmt);
258 float64_t v = dsfmt_genrand_close_open(m_dsfmt);
274 int32_t i = (int32_t)(u & 0x7F);
275 float64_t sign = ((u & 0x80) == 0) ? -1.0 : 1.0;
286 return u2 * m_uint32ToU * m_A_div_y0 * sign;
289 return sample_tail() * sign;
295 return u2 * m_uint32ToU * m_x[i] * sign;
303 if(m_y[i-1] + ((m_y[i] - m_y[i-1]) *
random_half_open()) < GaussianPdfDenorm(x) ) {
336 void CRandom::reinit(uint32_t seed)
340 sfmt_init_gen_rand(m_sfmt_32, m_seed);
341 sfmt_init_gen_rand(m_sfmt_64, m_seed);
342 dsfmt_init_gen_rand(m_dsfmt, m_seed);
351 #elif defined(HAVE_ARC4RANDOM) 353 #elif defined(DEV_RANDOM) 354 int fd = open(DEV_RANDOM, O_RDONLY);
356 ssize_t actual_read =
357 read(fd, reinterpret_cast<char*>(&seed),
sizeof(seed));
359 ASSERT(actual_read ==
sizeof(seed));
363 gettimeofday(&tv, NULL);
364 seed=(uint32_t) (4223517*getpid()*tv.tv_sec*tv.tv_usec);
float64_t std_normal_distrib() const
void fill_array(uint32_t *array, int32_t size) const
float64_t normal_distrib(float64_t mu, float64_t sigma) const
float64_t random_open() const
void fill_array_oc(float64_t *array, int32_t size) const
float64_t random_close() const
uint32_t random_32() const
SG_FORCED_INLINE void lock()
void fill_array_oo(float64_t *array, int32_t size) const
void fill_array_co(float64_t *array, int32_t size) const
all of classes and functions are contained in the shogun namespace
void set_seed(uint32_t seed)
void fill_array_c1o2(float64_t *array, int32_t size) const
static float64_t exp(float64_t x)
static float64_t log(float64_t v)
SG_FORCED_INLINE void unlock()
float64_t random_half_open() const
static float32_t sqrt(float32_t x)
static uint32_t generate_seed()
T max(const Container< T > &a)
uint64_t random_64() const
uint32_t get_seed() const