23 #include "ns3/boolean.h"
24 #include "ns3/double.h"
25 #include "ns3/integer.h"
27 #include "ns3/random-variable-stream.h"
28 #include "ns3/rng-seed-manager.h"
29 #include "ns3/string.h"
35 #include <gsl/gsl_cdf.h>
36 #include <gsl/gsl_histogram.h>
37 #include <gsl/gsl_randist.h>
38 #include <gsl/gsl_sf_zeta.h>
50 namespace RandomVariable
96 bool underflow =
true,
97 bool overflow =
true)
const
100 std::size_t nBins = gsl_histogram_bins(h);
101 double increment = (end -
start) / (nBins - 1.);
104 std::vector<double> range(nBins + 1);
106 for (
auto& r : range)
120 gsl_histogram_set_ranges(h, range.data(), nBins + 1);
158 template <
typename RNG>
174 auto rng = CreateObject<RNG>();
200 const std::vector<double>& expected,
205 "Histogram and expected vector have different sizes.");
211 gsl_histogram_increment(h, value);
215 double chiSquared = 0;
216 std::size_t nBins = gsl_histogram_bins(h);
217 for (std::size_t i = 0; i < nBins; ++i)
219 double hbin = gsl_histogram_get(h, i);
220 double tmp = hbin - expected[i];
277 for (std::size_t i = 0; i < nRuns; ++i)
279 auto rng = generator->
Create();
283 sum /= (double)nRuns;
325 seed =
static_cast<uint32_t
>(time(
nullptr));
328 "Special run number value of zero; seeding with time of day: " << seed);
362 void DoRun()
override;
366 :
TestCaseBase(
"Uniform Random Variable Stream Generator")
373 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
377 gsl_histogram_set_ranges_uniform(h, 0., 1.);
381 double chiSquared =
ChiSquared(h, expected, rng);
382 gsl_histogram_free(h);
392 double confidence = 0.99;
393 double maxStatistic = gsl_cdf_chisq_Pinv(confidence, (
N_BINS - 1));
395 <<
" bins is " << maxStatistic);
397 double result = maxStatistic;
399 for (uint32_t i = 0; i <
N_RUNS; ++i)
404 if (result < maxStatistic)
428 value =
x->GetValue();
434 static const uint32_t UNIFORM_INTEGER_MIN{0};
435 static const uint32_t UNIFORM_INTEGER_MAX{4294967295U};
438 intValue =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN);
441 intValue =
x->GetInteger(UNIFORM_INTEGER_MAX, UNIFORM_INTEGER_MAX);
445 for (
int i = 0; i < 20; i++)
447 intValue +=
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN + 1);
453 for (
int i = 0; i < 20; i++)
455 intValue =
x->GetInteger(UNIFORM_INTEGER_MAX - 1, UNIFORM_INTEGER_MAX);
456 if (intValue == UNIFORM_INTEGER_MAX)
464 intValue =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
465 uint32_t intValue2 =
x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
484 void DoRun()
override;
488 :
TestCaseBase(
"Antithetic Uniform Random Variable Stream Generator")
495 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
499 gsl_histogram_set_ranges_uniform(h, 0., 1.);
503 double chiSquared =
ChiSquared(h, expected, rng);
504 gsl_histogram_free(h);
516 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
538 value =
x->GetValue();
556 void DoRun()
override;
563 :
TestCaseBase(
"Constant Random Variable Stream Generator")
591 "Constant value changed in loop");
607 void DoRun()
override;
614 :
TestCaseBase(
"Sequential Random Variable Stream Generator")
632 s->SetAttribute(
"Increment",
StringValue(
"ns3::UniformRandomVariable[Min=3.0|Max=3.0]"));
638 value = s->GetValue();
640 value = s->GetValue();
642 value = s->GetValue();
644 value = s->GetValue();
646 value = s->GetValue();
648 value = s->GetValue();
667 void DoRun()
override;
674 :
TestCaseBase(
"Normal Random Variable Stream Generator")
681 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
684 std::vector<double> expected(
N_BINS);
691 for (std::size_t i = 0; i <
N_BINS; ++i)
693 expected[i] = gsl_cdf_gaussian_P(range[i + 1],
sigma) - gsl_cdf_gaussian_P(range[i],
sigma);
697 double chiSquared =
ChiSquared(h, expected, rng);
698 gsl_histogram_free(h);
709 auto rng = generator.Create();
712 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
716 double variance = 2.0;
728 double expectedMean = mean;
735 "Wrong mean value.");
753 void DoRun()
override;
760 :
TestCaseBase(
"Antithetic Normal Random Variable Stream Generator")
767 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
770 std::vector<double> expected(
N_BINS);
777 for (std::size_t i = 0; i <
N_BINS; ++i)
779 expected[i] = gsl_cdf_gaussian_P(range[i + 1],
sigma) - gsl_cdf_gaussian_P(range[i],
sigma);
783 double chiSquared =
ChiSquared(h, expected, rng);
785 gsl_histogram_free(h);
797 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
801 double variance = 2.0;
816 double expectedMean = mean;
823 "Wrong mean value.");
841 void DoRun()
override;
848 :
TestCaseBase(
"Exponential Random Variable Stream Generator")
855 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
858 std::vector<double> expected(
N_BINS);
864 for (std::size_t i = 0; i <
N_BINS; ++i)
866 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
870 double chiSquared =
ChiSquared(h, expected, rng);
872 gsl_histogram_free(h);
884 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
897 double expectedMean = mean;
904 "Wrong mean value.");
922 void DoRun()
override;
929 :
TestCaseBase(
"Antithetic Exponential Random Variable Stream Generator")
936 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
939 std::vector<double> expected(
N_BINS);
945 for (std::size_t i = 0; i <
N_BINS; ++i)
947 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
951 double chiSquared =
ChiSquared(h, expected, rng);
953 gsl_histogram_free(h);
965 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
981 double expectedMean = mean;
988 "Wrong mean value.");
1006 void DoRun()
override;
1016 :
TestCaseBase(
"Pareto Random Variable Stream Generator")
1023 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1026 std::vector<double> expected(
N_BINS);
1031 for (std::size_t i = 0; i <
N_BINS; ++i)
1034 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1038 double chiSquared =
ChiSquared(h, expected, rng);
1040 gsl_histogram_free(h);
1052 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1075 double expectedMean = (shape * scale) / (shape - 1.0);
1081 "Wrong mean value.");
1099 void DoRun()
override;
1109 :
TestCaseBase(
"Antithetic Pareto Random Variable Stream Generator")
1116 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1119 std::vector<double> expected(
N_BINS);
1124 for (std::size_t i = 0; i <
N_BINS; ++i)
1127 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1131 double chiSquared =
ChiSquared(h, expected, rng);
1133 gsl_histogram_free(h);
1145 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1172 double expectedMean = (shape * scale) / (shape - 1.0);
1178 "Wrong mean value.");
1196 void DoRun()
override;
1206 :
TestCaseBase(
"Weibull Random Variable Stream Generator")
1213 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1216 std::vector<double> expected(
N_BINS);
1224 for (std::size_t i = 0; i <
N_BINS; ++i)
1226 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1231 double chiSquared =
ChiSquared(h, expected, rng);
1233 gsl_histogram_free(h);
1245 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1281 double expectedMean = scale;
1287 "Wrong mean value.");
1305 void DoRun()
override;
1315 :
TestCaseBase(
"Antithetic Weibull Random Variable Stream Generator")
1322 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1325 std::vector<double> expected(
N_BINS);
1333 for (std::size_t i = 0; i <
N_BINS; ++i)
1335 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1339 double chiSquared =
ChiSquared(h, expected, rng);
1341 gsl_histogram_free(h);
1353 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1392 double expectedMean = scale;
1398 "Wrong mean value.");
1416 void DoRun()
override;
1426 :
TestCaseBase(
"Log-Normal Random Variable Stream Generator")
1433 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1436 std::vector<double> expected(
N_BINS);
1444 for (std::size_t i = 0; i <
N_BINS; ++i)
1447 gsl_cdf_lognormal_P(range[i + 1], mu,
sigma) - gsl_cdf_lognormal_P(range[i], mu,
sigma);
1451 double chiSquared =
ChiSquared(h, expected, rng);
1453 gsl_histogram_free(h);
1465 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1487 double expectedMean = std::exp(mu +
sigma *
sigma / 2.0);
1500 "Wrong mean value.");
1518 void DoRun()
override;
1528 :
TestCaseBase(
"Antithetic Log-Normal Random Variable Stream Generator")
1535 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1538 std::vector<double> expected(
N_BINS);
1546 for (std::size_t i = 0; i <
N_BINS; ++i)
1549 gsl_cdf_lognormal_P(range[i + 1], mu,
sigma) - gsl_cdf_lognormal_P(range[i], mu,
sigma);
1553 double chiSquared =
ChiSquared(h, expected, rng);
1555 gsl_histogram_free(h);
1567 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1591 double expectedMean = std::exp(mu +
sigma *
sigma / 2.0);
1604 "Wrong mean value.");
1622 void DoRun()
override;
1632 :
TestCaseBase(
"Gamma Random Variable Stream Generator")
1639 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1642 std::vector<double> expected(
N_BINS);
1650 for (std::size_t i = 0; i <
N_BINS; ++i)
1653 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1657 double chiSquared =
ChiSquared(h, expected, rng);
1659 gsl_histogram_free(h);
1671 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1690 double expectedMean = alpha * beta;
1696 "Wrong mean value.");
1714 void DoRun()
override;
1724 :
TestCaseBase(
"Antithetic Gamma Random Variable Stream Generator")
1731 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1734 std::vector<double> expected(
N_BINS);
1742 for (std::size_t i = 0; i <
N_BINS; ++i)
1745 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1749 double chiSquared =
ChiSquared(h, expected, rng);
1751 gsl_histogram_free(h);
1763 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1786 double expectedMean = alpha * beta;
1792 "Wrong mean value.");
1810 void DoRun()
override;
1820 :
TestCaseBase(
"Erlang Random Variable Stream Generator")
1827 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1830 std::vector<double> expected(
N_BINS);
1836 double lambda = 1.0;
1841 for (std::size_t i = 0; i <
N_BINS; ++i)
1844 gsl_cdf_gamma_P(range[i + 1],
k, lambda) - gsl_cdf_gamma_P(range[i],
k, lambda);
1848 double chiSquared =
ChiSquared(h, expected, rng);
1850 gsl_histogram_free(h);
1862 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1866 double lambda = 2.0;
1881 double expectedMean =
k * lambda;
1887 "Wrong mean value.");
1905 void DoRun()
override;
1915 :
TestCaseBase(
"Antithetic Erlang Random Variable Stream Generator")
1922 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1925 std::vector<double> expected(
N_BINS);
1931 double lambda = 1.0;
1936 for (std::size_t i = 0; i <
N_BINS; ++i)
1939 gsl_cdf_gamma_P(range[i + 1],
k, lambda) - gsl_cdf_gamma_P(range[i],
k, lambda);
1943 double chiSquared =
ChiSquared(h, expected, rng);
1945 gsl_histogram_free(h);
1957 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1961 double lambda = 2.0;
1980 double expectedMean =
k * lambda;
1986 "Wrong mean value.");
2001 void DoRun()
override;
2011 :
TestCaseBase(
"Zipf Random Variable Stream Generator")
2060 double expectedMean = 1.0;
2066 "Wrong mean value.");
2081 void DoRun()
override;
2091 :
TestCaseBase(
"Antithetic Zipf Random Variable Stream Generator")
2143 double expectedMean = 1.0;
2149 "Wrong mean value.");
2164 void DoRun()
override;
2174 :
TestCaseBase(
"Zeta Random Variable Stream Generator")
2205 double expectedMean =
2206 gsl_sf_zeta_int(
static_cast<int>(alpha - 1)) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2212 "Wrong mean value.");
2227 void DoRun()
override;
2237 :
TestCaseBase(
"Antithetic Zeta Random Variable Stream Generator")
2271 double expectedMean =
2272 gsl_sf_zeta_int(
static_cast<int>(alpha) - 1) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2278 "Wrong mean value.");
2293 void DoRun()
override;
2300 :
TestCaseBase(
"Deterministic Random Variable Stream Generator")
2316 double array1[] = {4, 4, 7, 7, 10, 10};
2317 std::size_t count1 = 6;
2318 s->SetValueArray(array1, count1);
2323 value = s->GetValue();
2325 value = s->GetValue();
2327 value = s->GetValue();
2329 value = s->GetValue();
2331 value = s->GetValue();
2333 value = s->GetValue();
2340 double array2[] = {1000, 2000, 3000, 4000};
2341 std::size_t count2 = 4;
2342 s->SetValueArray(array2, count2);
2345 value = s->GetValue();
2347 value = s->GetValue();
2349 value = s->GetValue();
2351 value = s->GetValue();
2353 value = s->GetValue();
2368 void DoRun()
override;
2378 :
TestCaseBase(
"Empirical Random Variable Stream Generator")
2390 x->SetInterpolate(
false);
2398 double value =
x->GetValue();
2401 "Incorrect value returned, expected only 5 or 10.");
2417 double expectedMean = 8.75;
2421 "Wrong mean value.");
2424 x->SetInterpolate(
true);
2439 expectedMean = 6.25;
2445 "Wrong mean value.");
2449 y->SetInterpolate(
false);
2468 void DoRun()
override;
2478 :
TestCaseBase(
"EmpiricalAntithetic Random Variable Stream Generator")
2490 x->SetInterpolate(
false);
2501 double value =
x->GetValue();
2504 "Incorrect value returned, expected only 5 or 10.");
2511 double expectedMean = 8.75;
2515 "Wrong mean value.");
2518 x->SetInterpolate(
true);
2526 expectedMean = 6.25;
2532 "Wrong mean value.");
2547 void DoRun()
override;
2551 :
TestCaseBase(
"NormalRandomVariable caching of parameters")
2562 double v1 = n->GetValue(-10, 1, 10);
2563 double v2 = n->GetValue(10, 1, 10);
2584 void DoRun()
override;
2591 :
TestCaseBase(
"Bernoulli Random Variable Stream Generator")
2598 gsl_histogram* h = gsl_histogram_alloc(2);
2604 double chiSquared =
ChiSquared(h, expected, rng);
2606 gsl_histogram_free(h);
2618 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2621 double probability = 0.5;
2625 x->SetAttribute(
"Probability",
DoubleValue(probability));
2628 double mean = probability;
2630 double expectedMean = mean;
2637 "Wrong mean value.");
2655 void DoRun()
override;
2662 :
TestCaseBase(
"Antithetic Bernoulli Random Variable Stream Generator")
2669 gsl_histogram* h = gsl_histogram_alloc(2);
2675 double chiSquared =
ChiSquared(h, expected, rng);
2677 gsl_histogram_free(h);
2689 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2692 double probability = 0.5;
2696 x->SetAttribute(
"Probability",
DoubleValue(probability));
2702 double mean = probability;
2704 double expectedMean = mean;
2711 "Wrong mean value.");
2729 void DoRun()
override;
2736 :
TestCaseBase(
"Binomial Random Variable Stream Generator")
2743 uint32_t trials = 10;
2744 double probability = 0.5;
2746 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2749 std::vector<double> expected(trials + 1);
2750 for (std::size_t i = 0; i < trials + 1; ++i)
2752 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2755 double chiSquared =
ChiSquared(h, expected, rng);
2757 gsl_histogram_free(h);
2767 uint32_t trials = 10;
2768 double probability = 0.5;
2772 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2778 x->SetAttribute(
"Probability",
DoubleValue(probability));
2781 double mean = trials * probability;
2783 double expectedMean = mean;
2790 "Wrong mean value.");
2808 void DoRun()
override;
2815 :
TestCaseBase(
"Antithetic Binomial Random Variable Stream Generator")
2822 uint32_t trials = 10;
2823 double probability = 0.5;
2825 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2828 std::vector<double> expected(trials + 1);
2829 for (std::size_t i = 0; i < trials + 1; ++i)
2831 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2834 double chiSquared =
ChiSquared(h, expected, rng);
2836 gsl_histogram_free(h);
2846 uint32_t trials = 10;
2847 double probability = 0.5;
2851 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2857 x->SetAttribute(
"Probability",
DoubleValue(probability));
2863 double mean = trials * probability;
2865 double expectedMean = mean;
2872 "Wrong mean value.");
2888 :
TestSuite(
"random-variable-stream-generators", UNIT)
double GetValue(double constant)
Get the next random value drawn from the distribution.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold a signed integer type.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
virtual double GetValue()=0
Get the next random value drawn from the distribution.
static void SetSeed(uint32_t seed)
Set the seed.
static uint64_t GetRun()
Get the current run number.
static uint32_t GetSeed()
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
Hold variables of type string.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Test case for antithetic bernoulli distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
BernoulliAntitheticTestCase()
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for bernoulli distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic binomial distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
BinomialAntitheticTestCase()
Test case for binomial distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for constant random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
void DoRun() override
Implementation to actually run this TestCase.
Test case for deterministic random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
Test case for antithetic empirical distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
EmpiricalAntitheticTestCase()
Test case for empirical distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic Erlang distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ErlangAntitheticTestCase()
Test case for Erlang distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for antithetic exponential distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ExponentialAntitheticTestCase()
Test case for exponential distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for antithetic gamma distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
GammaAntitheticTestCase()
void DoRun() override
Implementation to actually run this TestCase.
Test case for gamma distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic log-normal distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
LogNormalAntitheticTestCase()
Test case for log-normal distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic normal distribution random variable stream generator.
NormalAntitheticTestCase()
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for caching of Normal RV parameters (see issue #302)
void DoRun() override
Implementation to actually run this TestCase.
Test case for normal distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
Test case for antithetic Pareto distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ParetoAntitheticTestCase()
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for Pareto distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
RandomVariableStream test suite, covering all random number variable stream generator types.
Test case for sequential random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
void DoRun() override
Implementation to actually run this TestCase.
A factory base class to create new instances of a random variable.
virtual Ptr< RandomVariableStream > Create() const =0
Create a new instance of a random variable stream.
Factory class to create new instances of a particular random variable stream.
Ptr< RandomVariableStream > Create() const override
Create a new instance of a random variable stream.
bool m_anti
Whether to create antithetic random variable streams.
RngGenerator(bool anti=false)
Constructor.
Base class for RandomVariableStream test suites.
double ChiSquared(gsl_histogram *h, const std::vector< double > &expected, Ptr< RandomVariableStream > rng) const
Compute the chi squared value of a sampled distribution compared to the expected distribution.
static const uint32_t N_MEASUREMENTS
Number of samples to draw when populating the distributions.
void SetTestSuiteSeed()
Set the seed used for this test suite.
double ChiSquaredsAverage(const RngGeneratorBase *generator, std::size_t nRuns) const
Average the chi squared value over some number of runs, each run with a new instance of the random nu...
virtual double ChiSquaredTest(Ptr< RandomVariableStream > rng) const
Compute the chi square value from a random variable.
static const uint32_t N_BINS
Number of bins for sampling the distributions.
std::vector< double > UniformHistogramBins(gsl_histogram *h, double start, double end, bool underflow=true, bool overflow=true) const
Configure a GSL histogram with uniform bins, with optional under/over-flow bins.
bool m_seedSet
true if we've already set the seed the correctly.
TestCaseBase(std::string name)
Constructor.
static const uint32_t N_RUNS
Number of retry attempts to pass a chi-square test.
double Average(Ptr< RandomVariableStream > rng) const
Compute the average of a random variable.
Test case for antithetic Weibull distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
WeibullAntitheticTestCase()
Test case for Weibull distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic Zeta distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for Zeta distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for antithetic Zipf distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for Zipf distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
static RandomVariableSuite randomVariableSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.