28 #include <sys/types.h>
114 : m_variable (o.m_variable->
Copy ())
118 : m_variable (variable.
Copy ())
184 double GetMin (
void)
const;
185 double GetMax (
void)
const;
195 virtual double GetValue (
double s,
double l);
251 return s + generator->
RandU01 () * (l - s);
287 return static_cast<uint32_t
> (
GetValue (s, l + 1) );
446 m_currentConsecutive (0)
457 m_currentConsecutive (0)
466 m_increment (c.m_increment),
467 m_consecutive (c.m_consecutive),
468 m_current (c.m_current),
469 m_currentConsecutive (c.m_currentConsecutive)
704 : m_scale (0.5 / 1.5),
712 : m_scale (m * 0.5 / 1.5),
720 : m_scale (m * (s - 1.0) / s),
728 : m_scale (m * (s - 1.0) / s),
736 : m_scale (params.first),
737 m_shape (params.second),
744 : m_scale (params.first),
745 m_shape (params.second),
908 double exponent = 1.0 /
m_alpha;
911 double r =
m_mean * std::pow ( -std::log (generator->
RandU01 ()), exponent);
995 m_bound (INFINITE_VALUE),
1013 m_variance (c.m_variance),
1014 m_bound (c.m_bound),
1033 double u1 = generator->
RandU01 ();
1034 double u2 = generator->
RandU01 ();
1035 double v1 = 2 * u1 - 1;
1036 double v2 = 2 * u2 - 1;
1037 double w = v1 * v1 + v2 * v2;
1040 double y = std::sqrt ((-2 * std::log (w)) / w);
1126 virtual void CDF (
double v,
double c);
1139 virtual double Interpolate (
double,
double,
double,
double,
double);
1176 validated (c.validated),
1192 if (
emp.size () == 0)
1200 double r = generator->
RandU01 ();
1201 if (r <=
emp.front ().cdf)
1203 return emp.front ().value;
1205 if (r >=
emp.back ().cdf)
1207 return emp.back ().value;
1210 std::vector<ValueCDF>::size_type bottom = 0;
1211 std::vector<ValueCDF>::size_type top =
emp.size () - 1;
1214 std::vector<ValueCDF>::size_type c = (top + bottom) / 2;
1215 if (r >=
emp[c].cdf && r <
emp[c + 1].cdf)
1218 emp[c].value,
emp[c + 1].value,
1250 for (std::vector<ValueCDF>::size_type i = 0; i <
emp.size (); ++i)
1255 std::cerr <<
"Empirical Dist error,"
1256 <<
" current value " << current.
value
1257 <<
" prior value " << prior.
value
1258 <<
" current cdf " << current.
cdf
1259 <<
" prior cdf " << prior.
cdf << std::endl;
1268 double v1,
double v2,
double r)
1271 return (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1308 virtual double Interpolate (
double,
double,
double,
double,
double);
1330 double v1,
double v2,
double r)
1333 return std::ceil (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1477 double u, v, r2,
normal, z;
1483 u = -1 + 2 * generator->
RandU01 ();
1484 v = -1 + 2 * generator->
RandU01 ();
1489 while (r2 > 1.0 || r2 == 0);
1491 normal = u * std::sqrt (-2.0 * std::log (r2) / r2);
1525 double GetValue (
double alpha,
double beta);
1580 double u = generator->
RandU01 ();
1581 return GetValue (1.0 + alpha, beta) * std::pow (u, 1.0 / alpha);
1585 double d = alpha - 1.0 / 3.0;
1586 double c = (1.0 / 3.0) / std::sqrt (d);
1599 if (u < 1 - 0.0331 * x * x * x * x)
1603 if (std::log (u) < 0.5 * x * x + d * (1 - v + std::log (v)))
1609 return beta * d * v;
1658 double GetValue (
unsigned int k,
double lambda);
1709 for (
unsigned int i = 0; i < k; ++i)
1788 m_mode (3.0 * mean - s - l)
1806 double u = generator->
RandU01 ();
1886 for (
int i = 1; i <= n; i++)
1888 m_c += (1.0 / std::pow ((
double)i, alpha));
1899 double u = generator->
RandU01 ();
1900 double sum_prob = 0,zipf_value = 0;
1901 for (
int i = 1; i <=
m_n; i++)
1903 sum_prob +=
m_c / std::pow ((
double)i,
m_alpha);
1962 m_b (std::pow (2.0, 2.14))
1970 m_b (std::pow (2.0, alpha - 1.0))
1994 X = floor (std::pow (u, -1.0 / (
m_alpha - 1.0)));
1995 T = std::pow (1.0 + 1.0 / X,
m_alpha - 1.0);
1996 test = v * X * (T - 1.0) / (
m_b - 1.0);
1998 while ( test > (T /
m_b) );
2022 os <<
"Constant:" << constant->
GetValue ();
2028 os <<
"Uniform:" << uniform->
GetMin () <<
":" << uniform->
GetMax ();
2035 double bound = normal->
GetBound ();
2043 os.setstate (std::ios_base::badbit);
2050 std::string::size_type tmp;
2051 tmp = value.find (
":");
2052 if (tmp == std::string::npos)
2054 is.setstate (std::ios_base::badbit);
2057 std::string type = value.substr (0, tmp);
2058 value = value.substr (tmp + 1, value.npos);
2059 if (type ==
"Constant")
2061 std::istringstream iss (value);
2066 else if (type ==
"Uniform")
2068 if (value.size () == 0)
2074 tmp = value.find (
":");
2075 if (tmp == value.npos)
2079 std::istringstream issA (value.substr (0, tmp));
2080 std::istringstream issB (value.substr (tmp + 1, value.npos));
2087 else if (type ==
"Normal")
2089 if (value.size () == 0)
2095 tmp = value.find (
":");
2096 if (tmp == value.npos)
2100 std::string::size_type tmp2;
2101 std::string sub = value.substr (tmp + 1, value.npos);
2102 tmp2 = sub.find (
":");
2103 if (tmp2 == value.npos)
2105 std::istringstream issA (value.substr (0, tmp));
2106 std::istringstream issB (sub);
2114 std::istringstream issA (value.substr (0, tmp));
2115 std::istringstream issB (sub.substr (0, tmp2));
2116 std::istringstream issC (sub.substr (tmp2 + 1, value.npos));
2127 NS_FATAL_ERROR (
"RandomVariable deserialization not implemented for " << type);