28 #include <sys/types.h>
115 : m_variable (o.m_variable->
Copy ())
119 : m_variable (variable.
Copy ())
186 double GetMin (
void)
const;
187 double GetMax (
void)
const;
197 virtual double GetValue (
double s,
double l);
253 return s + generator->
RandU01 () * (l -
s);
289 return static_cast<uint32_t
> (
GetValue (s, l + 1) );
450 m_currentConsecutive (0)
461 m_currentConsecutive (0)
470 m_increment (c.m_increment),
471 m_consecutive (c.m_consecutive),
472 m_current (c.m_current),
473 m_currentConsecutive (c.m_currentConsecutive)
710 : m_scale (0.5 / 1.5),
718 : m_scale (m * 0.5 / 1.5),
726 : m_scale (m * (s - 1.0) / s),
734 : m_scale (m * (s - 1.0) / s),
742 : m_scale (params.
first),
743 m_shape (params.second),
750 : m_scale (params.
first),
751 m_shape (params.second),
915 double exponent = 1.0 /
m_alpha;
918 double r =
m_mean * std::pow ( -std::log (generator->
RandU01 ()), exponent);
1003 m_bound (INFINITE_VALUE),
1021 m_variance (c.m_variance),
1022 m_bound (c.m_bound),
1041 double u1 = generator->
RandU01 ();
1042 double u2 = generator->
RandU01 ();
1043 double v1 = 2 * u1 - 1;
1044 double v2 = 2 * u2 - 1;
1045 double w = v1 * v1 + v2 * v2;
1048 double y = std::sqrt ((-2 * std::log (w)) / w);
1135 virtual void CDF (
double v,
double c);
1148 virtual double Interpolate (
double,
double,
double,
double,
double);
1185 validated (c.validated),
1201 if (
emp.size () == 0)
1209 double r = generator->
RandU01 ();
1210 if (r <=
emp.front ().cdf)
1212 return emp.front ().value;
1214 if (r >=
emp.back ().cdf)
1216 return emp.back ().value;
1219 std::vector<ValueCDF>::size_type bottom = 0;
1220 std::vector<ValueCDF>::size_type top =
emp.size () - 1;
1223 std::vector<ValueCDF>::size_type c = (top + bottom) / 2;
1224 if (r >=
emp[c].cdf && r <
emp[c + 1].cdf)
1227 emp[c].value,
emp[c + 1].value,
1259 for (std::vector<ValueCDF>::size_type i = 0; i <
emp.size (); ++i)
1264 std::cerr <<
"Empirical Dist error,"
1265 <<
" current value " << current.
value
1266 <<
" prior value " << prior.
value
1267 <<
" current cdf " << current.
cdf
1268 <<
" prior cdf " << prior.
cdf << std::endl;
1277 double v1,
double v2,
double r)
1280 return (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1318 virtual double Interpolate (
double,
double,
double,
double,
double);
1340 double v1,
double v2,
double r)
1343 return std::ceil (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1489 double u, v, r2,
normal, z;
1495 u = -1 + 2 * generator->
RandU01 ();
1496 v = -1 + 2 * generator->
RandU01 ();
1501 while (r2 > 1.0 || r2 == 0);
1503 normal = u * std::sqrt (-2.0 * std::log (r2) / r2);
1538 double GetValue (
double alpha,
double beta);
1593 double u = generator->
RandU01 ();
1594 return GetValue (1.0 + alpha, beta) * std::pow (u, 1.0 / alpha);
1598 double d = alpha - 1.0 / 3.0;
1599 double c = (1.0 / 3.0) / std::sqrt (d);
1612 if (u < 1 - 0.0331 * x * x * x * x)
1616 if (std::log (u) < 0.5 * x * x + d * (1 - v + std::log (v)))
1622 return beta * d * v;
1672 double GetValue (
unsigned int k,
double lambda);
1723 for (
unsigned int i = 0; i < k; ++i)
1803 m_mode (3.0 * mean - s - l)
1821 double u = generator->
RandU01 ();
1902 for (
int i = 1; i <= n; i++)
1904 m_c += (1.0 / std::pow ((
double)i, alpha));
1915 double u = generator->
RandU01 ();
1916 double sum_prob = 0,zipf_value = 0;
1917 for (
int i = 1; i <=
m_n; i++)
1919 sum_prob +=
m_c / std::pow ((
double)i,
m_alpha);
1979 m_b (std::pow (2.0, 2.14))
1987 m_b (std::pow (2.0, alpha - 1.0))
2011 X = floor (std::pow (u, -1.0 / (
m_alpha - 1.0)));
2012 T = std::pow (1.0 + 1.0 / X,
m_alpha - 1.0);
2013 test = v * X * (T - 1.0) / (
m_b - 1.0);
2015 while ( test > (T /
m_b) );
2039 os <<
"Constant:" << constant->
GetValue ();
2045 os <<
"Uniform:" << uniform->
GetMin () <<
":" << uniform->
GetMax ();
2052 double bound = normal->
GetBound ();
2060 os.setstate (std::ios_base::badbit);
2067 std::string::size_type tmp;
2068 tmp = value.find (
":");
2069 if (tmp == std::string::npos)
2071 is.setstate (std::ios_base::badbit);
2074 std::string type = value.substr (0, tmp);
2075 value = value.substr (tmp + 1, value.npos);
2076 if (type ==
"Constant")
2078 std::istringstream iss (value);
2083 else if (type ==
"Uniform")
2085 if (value.size () == 0)
2091 tmp = value.find (
":");
2092 if (tmp == value.npos)
2096 std::istringstream issA (value.substr (0, tmp));
2097 std::istringstream issB (value.substr (tmp + 1, value.npos));
2104 else if (type ==
"Normal")
2106 if (value.size () == 0)
2112 tmp = value.find (
":");
2113 if (tmp == value.npos)
2117 std::string::size_type tmp2;
2118 std::string sub = value.substr (tmp + 1, value.npos);
2119 tmp2 = sub.find (
":");
2120 if (tmp2 == value.npos)
2122 std::istringstream issA (value.substr (0, tmp));
2123 std::istringstream issB (sub);
2131 std::istringstream issA (value.substr (0, tmp));
2132 std::istringstream issB (sub.substr (0, tmp2));
2133 std::istringstream issC (sub.substr (tmp2 + 1, value.npos));
2144 NS_FATAL_ERROR (
"RandomVariable deserialization not implemented for " << type);