26 static unsigned int s_states[128];
27 if (thread_num == -1) {
29 return rand_r(&s_states[omp_get_thread_num()]);
32 if (thread_num > 128) {
33 lout_error(
"[Rand] Can not support to many thread (Over 128)");
35 lout <<
"[Rand] Initial State" << endl;
37 for (
int i = 0; i < thread_num; i++) {
42 if (thread_num != -1) {
56 for (
int i = 0; i < nNum; i++)
57 dSum =
Log_Sum(dSum, pdProbs[i]);
58 for (
int i = 0; i < nNum; i++)
64 double d = 1.0 *
omp_rand() / RAND_MAX;
68 for (sX = 0; sX<nNum; sX++) {
71 if (fabs(dSum - 1) < 1e-5)
90 for (
int i = 0; i<nNum; i++)
94 for (
int i = 0; i<nNum; i++)
98 for (
int i = 0; i<nNum; i++)
99 pdProbs[i] = 1.0 / nNum;
105 double d = 1.0 *
omp_rand() / RAND_MAX;
109 for (sX = 0; sX<nNum; sX++) {
112 if (fabs(dSum - 1) < 1e-5)
121 cout <<
"[LineSampling] " << sX <<
"\t" << dSum << endl;
129 double d = 1.0 *
omp_rand() / RAND_MAX;
135 lout_error(
"[RandomPos] n(" << n <<
") > len(" << len <<
") !!");
138 for (
int i = 0; i<n; i++) {
139 int s = rand() % (len - i);
147 double dRand(
double dmin,
double dmax)
149 double d = 1.0 * rand() / RAND_MAX;
150 return d*(dmax - dmin) + dmin;
154 return omp_rand() % (nMax - nMin) + nMin;
159 for (
int i = 0; i < num; i++) {
160 p[i] = max(p[i], threshold);
170 double b_t =
SigmFunc( delta * (2.0 * t / T - 1) );
171 double b_T =
SigmFunc( delta * (2.0 * T / T - 1) );
172 double b_1 =
SigmFunc( delta * (2.0 * 1 / T - 1) );
174 return (b_t - b_1) / (b_T - b_1);
179 return 1.0 / (1 + exp(-x));
int LogLineSampling(const LogP *pdProbs, int nNum)
void RandomPos(int *a, int len, int n)
double SigmFunc(double x)
calculate the sigmoid function f(x) = 1/(1+exp(-x))
void LineNormalize(Prob *pdProbs, int nNum)
LogP Log_Sum(LogP x, LogP y)
double dRand(double dmin, double dmax)
get a random float between dmin and dmax
int LineSampling(const Prob *pdProbs, int nNum)
bool Acceptable(Prob prob)
int omp_rand(int thread_num)
void EasySmooth(Prob *p, int num, Prob threshold)
smooth a distribution
LogP LogLineNormalize(LogP *pdProbs, int nNum)
double GetAISFactor(int t, int T)
Get the AIS intermediate factor beta_t.
Log lout
the defination is in wb-log.cpp
int omp_nrand(int nMin, int nMax)
get a random integer int [nMin, nMax-1]