12#include "ns3/boolean.h"
13#include "ns3/double.h"
14#include "ns3/integer.h"
16#include "ns3/random-variable-stream.h"
17#include "ns3/rng-seed-manager.h"
18#include "ns3/shuffle.h"
19#include "ns3/string.h"
21#include "ns3/uinteger.h"
26#include <gsl/gsl_cdf.h>
27#include <gsl/gsl_histogram.h>
28#include <gsl/gsl_randist.h>
29#include <gsl/gsl_sf_zeta.h>
41namespace RandomVariable
87 bool underflow =
true,
88 bool overflow =
true)
const
91 std::size_t nBins = gsl_histogram_bins(h);
92 double increment = (end - start) / (nBins - 1.);
95 std::vector<double> range(nBins + 1);
104 range[0] = -std::numeric_limits<double>::max();
108 range[nBins] = std::numeric_limits<double>::max();
111 gsl_histogram_set_ranges(h, range.data(), nBins + 1);
126 double value = rng->GetValue();
145 const auto value = rng->GetValue();
146 sum += std::pow(value - average, 2);
149 return valueVariance;
168 template <
typename RNG>
210 const std::vector<double>& expected,
215 "Histogram and expected vector have different sizes.");
220 double value = rng->GetValue();
221 gsl_histogram_increment(h, value);
225 double chiSquared = 0;
226 std::size_t nBins = gsl_histogram_bins(h);
227 for (std::size_t i = 0; i < nBins; ++i)
229 double hbin = gsl_histogram_get(h, i);
230 double tmp = hbin - expected[i];
287 for (std::size_t i = 0; i < nRuns; ++i)
289 auto rng = generator->
Create();
335 seed =
static_cast<uint32_t>(time(
nullptr));
338 "Special run number value of zero; seeding with time of day: " << seed);
372 void DoRun()
override;
376 :
TestCaseBase(
"Uniform Random Variable Stream Generator")
383 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
387 gsl_histogram_set_ranges_uniform(h, 0., 1.);
391 double chiSquared =
ChiSquared(h, expected, rng);
392 gsl_histogram_free(h);
402 double confidence = 0.99;
403 double maxStatistic = gsl_cdf_chisq_Pinv(confidence, (
N_BINS - 1));
405 <<
" bins is " << maxStatistic);
407 double result = maxStatistic;
414 if (result < maxStatistic)
438 value = x->GetValue();
444 static const uint32_t UNIFORM_INTEGER_MIN{0};
445 static const uint32_t UNIFORM_INTEGER_MAX{4294967295U};
448 intValue = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN);
451 intValue = x->GetInteger(UNIFORM_INTEGER_MAX, UNIFORM_INTEGER_MAX);
455 for (
int i = 0; i < 20; i++)
457 intValue += x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN + 1);
463 for (
int i = 0; i < 20; i++)
465 intValue = x->GetInteger(UNIFORM_INTEGER_MAX - 1, UNIFORM_INTEGER_MAX);
466 if (intValue == UNIFORM_INTEGER_MAX)
474 intValue = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
475 uint32_t intValue2 = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
494 void DoRun()
override;
498 :
TestCaseBase(
"Antithetic Uniform Random Variable Stream Generator")
505 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
509 gsl_histogram_set_ranges_uniform(h, 0., 1.);
513 double chiSquared =
ChiSquared(h, expected, rng);
514 gsl_histogram_free(h);
526 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
548 value = x->GetValue();
566 void DoRun()
override;
573 :
TestCaseBase(
"Constant Random Variable Stream Generator")
589 c->SetAttribute(
"Constant",
DoubleValue(constant));
595 constant = c->GetValue();
601 "Constant value changed in loop");
617 void DoRun()
override;
624 :
TestCaseBase(
"Sequential Random Variable Stream Generator")
642 s->SetAttribute(
"Increment",
StringValue(
"ns3::UniformRandomVariable[Min=3.0|Max=3.0]"));
648 value = s->GetValue();
650 value = s->GetValue();
652 value = s->GetValue();
654 value = s->GetValue();
656 value = s->GetValue();
658 value = s->GetValue();
677 void DoRun()
override;
684 :
TestCaseBase(
"Normal Random Variable Stream Generator")
691 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
694 std::vector<double> expected(
N_BINS);
701 for (std::size_t i = 0; i <
N_BINS; ++i)
703 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
707 double chiSquared =
ChiSquared(h, expected, rng);
708 gsl_histogram_free(h);
719 auto rng = generator.Create();
722 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
726 double variance = 2.0;
731 x->SetAttribute(
"Variance",
DoubleValue(variance));
738 double expectedMean = mean;
745 "Wrong mean value.");
763 void DoRun()
override;
770 :
TestCaseBase(
"Antithetic Normal Random Variable Stream Generator")
777 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
780 std::vector<double> expected(
N_BINS);
787 for (std::size_t i = 0; i <
N_BINS; ++i)
789 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
793 double chiSquared =
ChiSquared(h, expected, rng);
795 gsl_histogram_free(h);
807 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
811 double variance = 2.0;
816 x->SetAttribute(
"Variance",
DoubleValue(variance));
826 double expectedMean = mean;
833 "Wrong mean value.");
851 void DoRun()
override;
858 :
TestCaseBase(
"Exponential Random Variable Stream Generator")
865 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
868 std::vector<double> expected(
N_BINS);
874 for (std::size_t i = 0; i <
N_BINS; ++i)
876 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
880 double chiSquared =
ChiSquared(h, expected, rng);
882 gsl_histogram_free(h);
894 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
907 double expectedMean = mean;
914 "Wrong mean value.");
932 void DoRun()
override;
939 :
TestCaseBase(
"Antithetic Exponential Random Variable Stream Generator")
946 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
949 std::vector<double> expected(
N_BINS);
955 for (std::size_t i = 0; i <
N_BINS; ++i)
957 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
961 double chiSquared =
ChiSquared(h, expected, rng);
963 gsl_histogram_free(h);
975 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
991 double expectedMean = mean;
998 "Wrong mean value.");
1016 void DoRun()
override;
1026 :
TestCaseBase(
"Pareto Random Variable Stream Generator")
1033 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1036 std::vector<double> expected(
N_BINS);
1041 for (std::size_t i = 0; i <
N_BINS; ++i)
1044 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1048 double chiSquared =
ChiSquared(h, expected, rng);
1050 gsl_histogram_free(h);
1062 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1074 double valueMean =
Average(x);
1085 double expectedMean = (shape * scale) / (shape - 1.0);
1091 "Wrong mean value.");
1109 void DoRun()
override;
1119 :
TestCaseBase(
"Antithetic Pareto Random Variable Stream Generator")
1126 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1129 std::vector<double> expected(
N_BINS);
1134 for (std::size_t i = 0; i <
N_BINS; ++i)
1137 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1141 double chiSquared =
ChiSquared(h, expected, rng);
1143 gsl_histogram_free(h);
1155 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1170 double valueMean =
Average(x);
1182 double expectedMean = (shape * scale) / (shape - 1.0);
1188 "Wrong mean value.");
1206 void DoRun()
override;
1216 :
TestCaseBase(
"Weibull Random Variable Stream Generator")
1223 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1226 std::vector<double> expected(
N_BINS);
1234 for (std::size_t i = 0; i <
N_BINS; ++i)
1236 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1241 double chiSquared =
ChiSquared(h, expected, rng);
1243 gsl_histogram_free(h);
1255 const auto maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1258 const auto scale = 5.0;
1259 const auto shape = 1.0;
1267 const auto measuredMean =
Average(x);
1291 const auto expectedMean = scale;
1294 const auto valueMean = x->GetMean();
1301 "Wrong measured mean value.");
1319 void DoRun()
override;
1329 :
TestCaseBase(
"Antithetic Weibull Random Variable Stream Generator")
1336 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1339 std::vector<double> expected(
N_BINS);
1347 for (std::size_t i = 0; i <
N_BINS; ++i)
1349 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1353 double chiSquared =
ChiSquared(h, expected, rng);
1355 gsl_histogram_free(h);
1367 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1382 double valueMean =
Average(x);
1406 double expectedMean = scale;
1412 "Wrong mean value.");
1430 void DoRun()
override;
1440 :
TestCaseBase(
"Log-Normal Random Variable Stream Generator")
1447 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1450 std::vector<double> expected(
N_BINS);
1458 for (std::size_t i = 0; i <
N_BINS; ++i)
1461 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1465 double chiSquared =
ChiSquared(h, expected, rng);
1467 gsl_histogram_free(h);
1479 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1492 double valueMean =
Average(x);
1501 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1514 "Wrong mean value.");
1532 void DoRun()
override;
1542 :
TestCaseBase(
"Antithetic Log-Normal Random Variable Stream Generator")
1549 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1552 std::vector<double> expected(
N_BINS);
1560 for (std::size_t i = 0; i <
N_BINS; ++i)
1563 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1567 double chiSquared =
ChiSquared(h, expected, rng);
1569 gsl_histogram_free(h);
1581 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1596 double valueMean =
Average(x);
1605 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1618 "Wrong mean value.");
1636 void DoRun()
override;
1646 :
TestCaseBase(
"Gamma Random Variable Stream Generator")
1653 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1656 std::vector<double> expected(
N_BINS);
1664 for (std::size_t i = 0; i <
N_BINS; ++i)
1667 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1671 double chiSquared =
ChiSquared(h, expected, rng);
1673 gsl_histogram_free(h);
1685 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1697 double valueMean =
Average(x);
1704 double expectedMean = alpha * beta;
1710 "Wrong mean value.");
1728 void DoRun()
override;
1738 :
TestCaseBase(
"Antithetic Gamma Random Variable Stream Generator")
1745 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1748 std::vector<double> expected(
N_BINS);
1756 for (std::size_t i = 0; i <
N_BINS; ++i)
1759 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1763 double chiSquared =
ChiSquared(h, expected, rng);
1765 gsl_histogram_free(h);
1777 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1793 double valueMean =
Average(x);
1800 double expectedMean = alpha * beta;
1806 "Wrong mean value.");
1824 void DoRun()
override;
1834 :
TestCaseBase(
"Erlang Random Variable Stream Generator")
1841 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1844 std::vector<double> expected(
N_BINS);
1850 double lambda = 1.0;
1855 for (std::size_t i = 0; i <
N_BINS; ++i)
1858 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1862 double chiSquared =
ChiSquared(h, expected, rng);
1864 gsl_histogram_free(h);
1876 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1880 double lambda = 2.0;
1888 double valueMean =
Average(x);
1895 double expectedMean = k * lambda;
1901 "Wrong mean value.");
1919 void DoRun()
override;
1929 :
TestCaseBase(
"Antithetic Erlang Random Variable Stream Generator")
1936 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1939 std::vector<double> expected(
N_BINS);
1945 double lambda = 1.0;
1950 for (std::size_t i = 0; i <
N_BINS; ++i)
1953 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1957 double chiSquared =
ChiSquared(h, expected, rng);
1959 gsl_histogram_free(h);
1971 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1975 double lambda = 2.0;
1987 double valueMean =
Average(x);
1994 double expectedMean = k * lambda;
2000 "Wrong mean value.");
2015 void DoRun()
override;
2025 :
TestCaseBase(
"Zipf Random Variable Stream Generator")
2044 double valueMean =
Average(x);
2074 double expectedMean = 1.0;
2080 "Wrong mean value.");
2095 void DoRun()
override;
2105 :
TestCaseBase(
"Antithetic Zipf Random Variable Stream Generator")
2127 double valueMean =
Average(x);
2157 double expectedMean = 1.0;
2163 "Wrong mean value.");
2178 void DoRun()
override;
2188 :
TestCaseBase(
"Zeta Random Variable Stream Generator")
2205 double valueMean =
Average(x);
2219 double expectedMean =
2220 gsl_sf_zeta_int(
static_cast<int>(alpha - 1)) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2226 "Wrong mean value.");
2241 void DoRun()
override;
2251 :
TestCaseBase(
"Antithetic Zeta Random Variable Stream Generator")
2271 double valueMean =
Average(x);
2285 double expectedMean =
2286 gsl_sf_zeta_int(
static_cast<int>(alpha) - 1) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2292 "Wrong mean value.");
2307 void DoRun()
override;
2314 :
TestCaseBase(
"Deterministic Random Variable Stream Generator")
2330 double array1[] = {4, 4, 7, 7, 10, 10};
2331 std::size_t count1 = 6;
2332 s->SetValueArray(array1, count1);
2337 value = s->GetValue();
2339 value = s->GetValue();
2341 value = s->GetValue();
2343 value = s->GetValue();
2345 value = s->GetValue();
2347 value = s->GetValue();
2354 double array2[] = {1000, 2000, 3000, 4000};
2355 std::size_t count2 = 4;
2356 s->SetValueArray(array2, count2);
2359 value = s->GetValue();
2361 value = s->GetValue();
2363 value = s->GetValue();
2365 value = s->GetValue();
2367 value = s->GetValue();
2382 void DoRun()
override;
2392 :
TestCaseBase(
"Empirical Random Variable Stream Generator")
2404 x->SetInterpolate(
false);
2412 double value = x->GetValue();
2415 "Incorrect value returned, expected only 5 or 10.");
2419 double valueMean =
Average(x);
2431 double expectedMean = 8.75;
2435 "Wrong mean value.");
2438 x->SetInterpolate(
true);
2453 expectedMean = 6.25;
2459 "Wrong mean value.");
2463 y->SetInterpolate(
false);
2482 void DoRun()
override;
2492 :
TestCaseBase(
"EmpiricalAntithetic Random Variable Stream Generator")
2504 x->SetInterpolate(
false);
2515 double value = x->GetValue();
2518 "Incorrect value returned, expected only 5 or 10.");
2522 double valueMean =
Average(x);
2525 double expectedMean = 8.75;
2529 "Wrong mean value.");
2532 x->SetInterpolate(
true);
2540 expectedMean = 6.25;
2546 "Wrong mean value.");
2561 void DoRun()
override;
2565 :
TestCaseBase(
"NormalRandomVariable caching of parameters")
2576 double v1 = n->GetValue(-10, 1, 10);
2577 double v2 = n->GetValue(10, 1, 10);
2598 void DoRun()
override;
2605 :
TestCaseBase(
"Bernoulli Random Variable Stream Generator")
2612 gsl_histogram* h = gsl_histogram_alloc(2);
2618 double chiSquared =
ChiSquared(h, expected, rng);
2620 gsl_histogram_free(h);
2632 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2635 double probability = 0.5;
2639 x->SetAttribute(
"Probability",
DoubleValue(probability));
2642 double mean = probability;
2643 double valueMean =
Average(x);
2644 double expectedMean = mean;
2651 "Wrong mean value.");
2669 void DoRun()
override;
2676 :
TestCaseBase(
"Antithetic Bernoulli Random Variable Stream Generator")
2683 gsl_histogram* h = gsl_histogram_alloc(2);
2689 double chiSquared =
ChiSquared(h, expected, rng);
2691 gsl_histogram_free(h);
2703 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2706 double probability = 0.5;
2710 x->SetAttribute(
"Probability",
DoubleValue(probability));
2716 double mean = probability;
2717 double valueMean =
Average(x);
2718 double expectedMean = mean;
2725 "Wrong mean value.");
2743 void DoRun()
override;
2750 :
TestCaseBase(
"Binomial Random Variable Stream Generator")
2758 double probability = 0.5;
2760 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2763 std::vector<double> expected(trials + 1);
2764 for (std::size_t i = 0; i < trials + 1; ++i)
2766 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2769 double chiSquared =
ChiSquared(h, expected, rng);
2771 gsl_histogram_free(h);
2782 double probability = 0.5;
2786 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2792 x->SetAttribute(
"Probability",
DoubleValue(probability));
2795 double mean = trials * probability;
2796 double valueMean =
Average(x);
2797 double expectedMean = mean;
2804 "Wrong mean value.");
2822 void DoRun()
override;
2829 :
TestCaseBase(
"Antithetic Binomial Random Variable Stream Generator")
2837 double probability = 0.5;
2839 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2842 std::vector<double> expected(trials + 1);
2843 for (std::size_t i = 0; i < trials + 1; ++i)
2845 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2848 double chiSquared =
ChiSquared(h, expected, rng);
2850 gsl_histogram_free(h);
2861 double probability = 0.5;
2865 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2871 x->SetAttribute(
"Probability",
DoubleValue(probability));
2877 double mean = trials * probability;
2878 double valueMean =
Average(x);
2879 double expectedMean = mean;
2886 "Wrong mean value.");
2903 void DoRun()
override;
2907 :
TestCase(
"Check correct operation of the Shuffle function")
2921 std::vector<uint8_t> vec{};
2923 Shuffle(vec.begin(), vec.end(), rv);
2930 Shuffle(vec.begin(), vec.end(), rv);
2937 Shuffle(vec.begin(), vec.end(), rv);
2947 Shuffle(vec.begin(), vec.end(), rv);
2951 "Expected vector {4, 1, 9, 3, 2, 7}");
2964 void DoRun()
override;
2974 :
TestCaseBase(
"Laplacian Random Variable Stream Generator")
2986 double bound = 20.0;
2997 auto valueVariance =
Variance(x1, valueMean);
3000 const auto expectedMean = mu;
3008 "Wrong variance value.");
3023 const auto lowerBound = mu - bound;
3024 const auto upperBound = mu + bound;
3027 const auto value = x2->GetValue();
3030 "Value not in expected boundaries.");
3044 void DoRun()
override;
3054 :
TestCaseBase(
"Largest Extreme Value Random Variable Stream Generator")
3076 auto valueVariance =
Variance(x, valueMean);
3087 "Wrong variance value.");
3103 :
TestSuite(
"random-variable-stream-generators",
Type::UNIT)
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold a signed integer type.
double GetVariance() const
Returns the variance value for the laplacian distribution returned by this RNG stream.
double GetMean() const
Returns the mean value for the Largest Extreme Value distribution returned by this RNG stream.
double GetVariance() const
Returns the variance value for the Largest Extreme Value distribution returned by this RNG stream.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
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, Duration duration=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 laplacian 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 largest extreme value distribution random variable stream generator.
LargestExtremeValueTestCase()
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 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.
Test the Shuffle function.
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...
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.
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.
double Variance(Ptr< RandomVariableStream > rng, double average) const
Compute the variance of a random variable.
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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.
void Shuffle(RND_ACCESS_ITER first, RND_ACCESS_ITER last, Ptr< UniformRandomVariable > rv)
Shuffle the elements in the range first to last.
-ns3 Test suite for the ns3 wrapper script