13 #include <shogun/lib/external/SFMT/SFMT.h>
14 #include <shogun/lib/external/dSFMT/dSFMT.h>
72 m_A = 9.91256303526217e-3;
75 m_x = SG_MALLOC(
float64_t, m_blockCount + 1);
77 m_xComp = SG_MALLOC(uint32_t, m_blockCount);
86 m_y[0] = GaussianPdfDenorm(m_R);
92 m_y[1] = m_y[0] + (m_A / m_x[1]);
95 for(
int i=2; i < m_blockCount; i++)
97 m_x[i] = GaussianPdfDenormInv(m_y[i-1]);
98 m_y[i] = m_y[i-1] + (m_A / m_x[i]);
102 m_x[m_blockCount] = 0.0;
105 m_A_div_y0 = m_A / m_y[0];
112 for(int32_t i=1; i < m_blockCount-1; i++)
116 m_xComp[m_blockCount-1] = 0;
124 m_sfmt_32 = SG_MALLOC(sfmt_t, 1);
125 m_sfmt_64 = SG_MALLOC(sfmt_t, 1);
126 m_dsfmt = SG_MALLOC(dsfmt_t, 1);
132 return sfmt_genrand_uint32(m_sfmt_32);
137 return sfmt_genrand_uint64(m_sfmt_64);
142 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN)
143 if ((size >= sfmt_get_min_array_size32(m_sfmt_32)) && (size % 4) == 0)
145 sfmt_fill_array32(m_sfmt_32, array, size);
149 for (int32_t i=0; i < size; i++)
155 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN)
156 if ((size >= sfmt_get_min_array_size64(m_sfmt_64)) && (size % 2) == 0)
158 sfmt_fill_array64(m_sfmt_64, array, size);
162 for (int32_t i=0; i < size; i++)
168 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN)
169 if ((size >= dsfmt_get_min_array_size()) && (size % 2) == 0)
171 dsfmt_fill_array_open_close(m_dsfmt, array, size);
175 for (int32_t i=0; i < size; i++)
176 array[i] = dsfmt_genrand_open_close(m_dsfmt);
181 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN)
182 if ((size >= dsfmt_get_min_array_size()) && (size % 2) == 0)
184 dsfmt_fill_array_close_open(m_dsfmt, array, size);
188 for (int32_t i=0; i < size; i++)
189 array[i] = dsfmt_genrand_close_open(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_open_open(m_dsfmt, array, size);
201 for (int32_t i=0; i < size; i++)
202 array[i] = dsfmt_genrand_open_open(m_dsfmt);
207 #if defined(USE_ALIGNED_MEMORY) || defined(DARWIN)
208 if ((size >= dsfmt_get_min_array_size()) && (size % 2) == 0)
210 dsfmt_fill_array_close1_open2(m_dsfmt, array, size);
214 for (int32_t i=0; i < size; i++)
215 array[i] = dsfmt_genrand_close1_open2(m_dsfmt);
220 return sfmt_genrand_real1(m_sfmt_32);
225 return dsfmt_genrand_open_open(m_dsfmt);
230 return dsfmt_genrand_close_open(m_dsfmt);
244 int32_t i = (int32_t)(u & 0x7F);
245 float64_t sign = ((u & 0x80) == 0) ? -1.0 : 1.0;
256 return u2 * m_uint32ToU * m_A_div_y0 * sign;
259 return sample_tail() * sign;
265 return u2 * m_uint32ToU * m_x[i] * sign;
273 if(m_y[i-1] + ((m_y[i] - m_y[i-1]) *
random_half_open()) < GaussianPdfDenorm(x) ) {
305 void CRandom::reinit(uint32_t seed)
309 sfmt_init_gen_rand(m_sfmt_32, m_seed);
310 sfmt_init_gen_rand(m_sfmt_64, m_seed);
311 dsfmt_init_gen_rand(m_dsfmt, m_seed);
320 #elif defined(HAVE_ARC4RANDOM)
322 #elif defined(DEV_RANDOM)
325 ssize_t actual_read =
326 read(fd, reinterpret_cast<char*>(&seed),
sizeof(seed));
328 ASSERT(actual_read ==
sizeof(seed));
332 gettimeofday(&tv, NULL);
333 seed=(uint32_t) (4223517*getpid()*tv.tv_sec*tv.tv_usec);
void fill_array_c1o2(float64_t *array, int32_t size) const
float64_t std_normal_distrib() const
void fill_array(uint32_t *array, int32_t size) const
uint64_t random_64() const
float64_t random_close() const
uint32_t get_seed() const
float64_t normal_distrib(float64_t mu, float64_t sigma) const
void fill_array_oo(float64_t *array, int32_t size) const
uint32_t random_32() const
void fill_array_oc(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)
static float64_t exp(float64_t x)
static float64_t log(float64_t v)
float64_t random_half_open() const
Matrix::Scalar max(Matrix m)
float64_t random_open() const
static float32_t sqrt(float32_t x)
static uint32_t generate_seed()