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);
373 void DoRun()
override;
377 :
TestCaseBase(
"Uniform Random Variable Stream Generator")
384 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
388 gsl_histogram_set_ranges_uniform(h, 0., 1.);
392 double chiSquared =
ChiSquared(h, expected, rng);
393 gsl_histogram_free(h);
403 double confidence = 0.99;
404 double maxStatistic = gsl_cdf_chisq_Pinv(confidence, (
N_BINS - 1));
406 <<
" bins is " << maxStatistic);
408 double result = maxStatistic;
415 if (result < maxStatistic)
439 value = x->GetValue();
445 static const uint32_t UNIFORM_INTEGER_MIN{0};
446 static const uint32_t UNIFORM_INTEGER_MAX{4294967295U};
449 intValue = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN);
452 intValue = x->GetInteger(UNIFORM_INTEGER_MAX, UNIFORM_INTEGER_MAX);
456 for (
int i = 0; i < 20; i++)
458 intValue += x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN + 1);
464 for (
int i = 0; i < 20; i++)
466 intValue = x->GetInteger(UNIFORM_INTEGER_MAX - 1, UNIFORM_INTEGER_MAX);
467 if (intValue == UNIFORM_INTEGER_MAX)
475 intValue = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
476 uint32_t intValue2 = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
495 void DoRun()
override;
499 :
TestCaseBase(
"Antithetic Uniform Random Variable Stream Generator")
506 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
510 gsl_histogram_set_ranges_uniform(h, 0., 1.);
514 double chiSquared =
ChiSquared(h, expected, rng);
515 gsl_histogram_free(h);
527 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
549 value = x->GetValue();
567 void DoRun()
override;
574 :
TestCaseBase(
"Constant Random Variable Stream Generator")
590 c->SetAttribute(
"Constant",
DoubleValue(constant));
596 constant = c->GetValue();
602 "Constant value changed in loop");
618 void DoRun()
override;
625 :
TestCaseBase(
"Sequential Random Variable Stream Generator")
643 s->SetAttribute(
"Increment",
StringValue(
"ns3::UniformRandomVariable[Min=3.0|Max=3.0]"));
649 value = s->GetValue();
651 value = s->GetValue();
653 value = s->GetValue();
655 value = s->GetValue();
657 value = s->GetValue();
659 value = s->GetValue();
678 void DoRun()
override;
685 :
TestCaseBase(
"Normal Random Variable Stream Generator")
692 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
695 std::vector<double> expected(
N_BINS);
702 for (std::size_t i = 0; i <
N_BINS; ++i)
704 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
708 double chiSquared =
ChiSquared(h, expected, rng);
709 gsl_histogram_free(h);
720 auto rng = generator.Create();
723 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
727 double variance = 2.0;
732 x->SetAttribute(
"Variance",
DoubleValue(variance));
739 double expectedMean = mean;
746 "Wrong mean value.");
764 void DoRun()
override;
771 :
TestCaseBase(
"Antithetic Normal Random Variable Stream Generator")
778 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
781 std::vector<double> expected(
N_BINS);
788 for (std::size_t i = 0; i <
N_BINS; ++i)
790 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
794 double chiSquared =
ChiSquared(h, expected, rng);
796 gsl_histogram_free(h);
808 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
812 double variance = 2.0;
817 x->SetAttribute(
"Variance",
DoubleValue(variance));
827 double expectedMean = mean;
834 "Wrong mean value.");
852 void DoRun()
override;
859 :
TestCaseBase(
"Exponential Random Variable Stream Generator")
866 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
869 std::vector<double> expected(
N_BINS);
875 for (std::size_t i = 0; i <
N_BINS; ++i)
877 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
881 double chiSquared =
ChiSquared(h, expected, rng);
883 gsl_histogram_free(h);
895 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
908 double expectedMean = mean;
915 "Wrong mean value.");
933 void DoRun()
override;
940 :
TestCaseBase(
"Antithetic Exponential Random Variable Stream Generator")
947 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
950 std::vector<double> expected(
N_BINS);
956 for (std::size_t i = 0; i <
N_BINS; ++i)
958 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
962 double chiSquared =
ChiSquared(h, expected, rng);
964 gsl_histogram_free(h);
976 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
992 double expectedMean = mean;
999 "Wrong mean value.");
1017 void DoRun()
override;
1027 :
TestCaseBase(
"Pareto Random Variable Stream Generator")
1034 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1037 std::vector<double> expected(
N_BINS);
1042 for (std::size_t i = 0; i <
N_BINS; ++i)
1045 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1049 double chiSquared =
ChiSquared(h, expected, rng);
1051 gsl_histogram_free(h);
1063 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1075 double valueMean =
Average(x);
1086 double expectedMean = (shape * scale) / (shape - 1.0);
1092 "Wrong mean value.");
1110 void DoRun()
override;
1120 :
TestCaseBase(
"Antithetic Pareto Random Variable Stream Generator")
1127 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1130 std::vector<double> expected(
N_BINS);
1135 for (std::size_t i = 0; i <
N_BINS; ++i)
1138 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1142 double chiSquared =
ChiSquared(h, expected, rng);
1144 gsl_histogram_free(h);
1156 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1171 double valueMean =
Average(x);
1183 double expectedMean = (shape * scale) / (shape - 1.0);
1189 "Wrong mean value.");
1207 void DoRun()
override;
1217 :
TestCaseBase(
"Weibull Random Variable Stream Generator")
1224 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1227 std::vector<double> expected(
N_BINS);
1235 for (std::size_t i = 0; i <
N_BINS; ++i)
1237 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1242 double chiSquared =
ChiSquared(h, expected, rng);
1244 gsl_histogram_free(h);
1256 const auto maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1259 const auto scale = 5.0;
1260 const auto shape = 1.0;
1268 const auto measuredMean =
Average(x);
1292 const auto expectedMean = scale;
1295 const auto valueMean = x->GetMean();
1302 "Wrong measured mean value.");
1320 void DoRun()
override;
1330 :
TestCaseBase(
"Antithetic Weibull Random Variable Stream Generator")
1337 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1340 std::vector<double> expected(
N_BINS);
1348 for (std::size_t i = 0; i <
N_BINS; ++i)
1350 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1354 double chiSquared =
ChiSquared(h, expected, rng);
1356 gsl_histogram_free(h);
1368 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1383 double valueMean =
Average(x);
1407 double expectedMean = scale;
1413 "Wrong mean value.");
1431 void DoRun()
override;
1441 :
TestCaseBase(
"Log-Normal Random Variable Stream Generator")
1448 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1451 std::vector<double> expected(
N_BINS);
1459 for (std::size_t i = 0; i <
N_BINS; ++i)
1462 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1466 double chiSquared =
ChiSquared(h, expected, rng);
1468 gsl_histogram_free(h);
1480 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1493 double valueMean =
Average(x);
1502 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1515 "Wrong mean value.");
1533 void DoRun()
override;
1543 :
TestCaseBase(
"Antithetic Log-Normal Random Variable Stream Generator")
1550 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1553 std::vector<double> expected(
N_BINS);
1561 for (std::size_t i = 0; i <
N_BINS; ++i)
1564 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1568 double chiSquared =
ChiSquared(h, expected, rng);
1570 gsl_histogram_free(h);
1582 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1597 double valueMean =
Average(x);
1606 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1619 "Wrong mean value.");
1637 void DoRun()
override;
1647 :
TestCaseBase(
"Gamma Random Variable Stream Generator")
1654 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1657 std::vector<double> expected(
N_BINS);
1665 for (std::size_t i = 0; i <
N_BINS; ++i)
1668 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1672 double chiSquared =
ChiSquared(h, expected, rng);
1674 gsl_histogram_free(h);
1686 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1698 double valueMean =
Average(x);
1705 double expectedMean = alpha * beta;
1711 "Wrong mean value.");
1729 void DoRun()
override;
1739 :
TestCaseBase(
"Antithetic Gamma Random Variable Stream Generator")
1746 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1749 std::vector<double> expected(
N_BINS);
1757 for (std::size_t i = 0; i <
N_BINS; ++i)
1760 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1764 double chiSquared =
ChiSquared(h, expected, rng);
1766 gsl_histogram_free(h);
1778 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1794 double valueMean =
Average(x);
1801 double expectedMean = alpha * beta;
1807 "Wrong mean value.");
1825 void DoRun()
override;
1835 :
TestCaseBase(
"Erlang Random Variable Stream Generator")
1842 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1845 std::vector<double> expected(
N_BINS);
1851 double lambda = 1.0;
1856 for (std::size_t i = 0; i <
N_BINS; ++i)
1859 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1863 double chiSquared =
ChiSquared(h, expected, rng);
1865 gsl_histogram_free(h);
1877 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1881 double lambda = 2.0;
1889 double valueMean =
Average(x);
1896 double expectedMean = k * lambda;
1902 "Wrong mean value.");
1920 void DoRun()
override;
1930 :
TestCaseBase(
"Antithetic Erlang Random Variable Stream Generator")
1937 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1940 std::vector<double> expected(
N_BINS);
1946 double lambda = 1.0;
1951 for (std::size_t i = 0; i <
N_BINS; ++i)
1954 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1958 double chiSquared =
ChiSquared(h, expected, rng);
1960 gsl_histogram_free(h);
1972 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1976 double lambda = 2.0;
1988 double valueMean =
Average(x);
1995 double expectedMean = k * lambda;
2001 "Wrong mean value.");
2016 void DoRun()
override;
2026 :
TestCaseBase(
"Zipf Random Variable Stream Generator")
2045 double valueMean =
Average(x);
2075 double expectedMean = 1.0;
2081 "Wrong mean value.");
2096 void DoRun()
override;
2106 :
TestCaseBase(
"Antithetic Zipf Random Variable Stream Generator")
2128 double valueMean =
Average(x);
2158 double expectedMean = 1.0;
2164 "Wrong mean value.");
2179 void DoRun()
override;
2189 :
TestCaseBase(
"Zeta Random Variable Stream Generator")
2206 double valueMean =
Average(x);
2220 double expectedMean =
2221 gsl_sf_zeta_int(
static_cast<int>(alpha - 1)) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2227 "Wrong mean value.");
2242 void DoRun()
override;
2252 :
TestCaseBase(
"Antithetic Zeta Random Variable Stream Generator")
2272 double valueMean =
Average(x);
2286 double expectedMean =
2287 gsl_sf_zeta_int(
static_cast<int>(alpha) - 1) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2293 "Wrong mean value.");
2308 void DoRun()
override;
2315 :
TestCaseBase(
"Deterministic Random Variable Stream Generator")
2331 double array1[] = {4, 4, 7, 7, 10, 10};
2332 std::size_t count1 = 6;
2333 s->SetValueArray(array1, count1);
2338 value = s->GetValue();
2340 value = s->GetValue();
2342 value = s->GetValue();
2344 value = s->GetValue();
2346 value = s->GetValue();
2348 value = s->GetValue();
2355 double array2[] = {1000, 2000, 3000, 4000};
2356 std::size_t count2 = 4;
2357 s->SetValueArray(array2, count2);
2360 value = s->GetValue();
2362 value = s->GetValue();
2364 value = s->GetValue();
2366 value = s->GetValue();
2368 value = s->GetValue();
2383 void DoRun()
override;
2393 :
TestCaseBase(
"Empirical Random Variable Stream Generator")
2405 x->SetInterpolate(
false);
2413 double value = x->GetValue();
2416 "Incorrect value returned, expected only 5 or 10.");
2420 double valueMean =
Average(x);
2432 double expectedMean = 8.75;
2436 "Wrong mean value.");
2439 x->SetInterpolate(
true);
2454 expectedMean = 6.25;
2460 "Wrong mean value.");
2464 y->SetInterpolate(
false);
2483 void DoRun()
override;
2493 :
TestCaseBase(
"EmpiricalAntithetic Random Variable Stream Generator")
2505 x->SetInterpolate(
false);
2516 double value = x->GetValue();
2519 "Incorrect value returned, expected only 5 or 10.");
2523 double valueMean =
Average(x);
2526 double expectedMean = 8.75;
2530 "Wrong mean value.");
2533 x->SetInterpolate(
true);
2541 expectedMean = 6.25;
2547 "Wrong mean value.");
2562 void DoRun()
override;
2566 :
TestCaseBase(
"NormalRandomVariable caching of parameters")
2577 double v1 = n->GetValue(-10, 1, 10);
2578 double v2 = n->GetValue(10, 1, 10);
2599 void DoRun()
override;
2606 :
TestCaseBase(
"Bernoulli Random Variable Stream Generator")
2613 gsl_histogram* h = gsl_histogram_alloc(2);
2619 double chiSquared =
ChiSquared(h, expected, rng);
2621 gsl_histogram_free(h);
2633 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2636 double probability = 0.5;
2640 x->SetAttribute(
"Probability",
DoubleValue(probability));
2643 double mean = probability;
2644 double valueMean =
Average(x);
2645 double expectedMean = mean;
2652 "Wrong mean value.");
2670 void DoRun()
override;
2677 :
TestCaseBase(
"Antithetic Bernoulli Random Variable Stream Generator")
2684 gsl_histogram* h = gsl_histogram_alloc(2);
2690 double chiSquared =
ChiSquared(h, expected, rng);
2692 gsl_histogram_free(h);
2704 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2707 double probability = 0.5;
2711 x->SetAttribute(
"Probability",
DoubleValue(probability));
2717 double mean = probability;
2718 double valueMean =
Average(x);
2719 double expectedMean = mean;
2726 "Wrong mean value.");
2744 void DoRun()
override;
2751 :
TestCaseBase(
"Binomial Random Variable Stream Generator")
2759 double probability = 0.5;
2761 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2764 std::vector<double> expected(trials + 1);
2765 for (std::size_t i = 0; i < trials + 1; ++i)
2767 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2770 double chiSquared =
ChiSquared(h, expected, rng);
2772 gsl_histogram_free(h);
2783 double probability = 0.5;
2787 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2793 x->SetAttribute(
"Probability",
DoubleValue(probability));
2796 double mean = trials * probability;
2797 double valueMean =
Average(x);
2798 double expectedMean = mean;
2805 "Wrong mean value.");
2823 void DoRun()
override;
2830 :
TestCaseBase(
"Antithetic Binomial Random Variable Stream Generator")
2838 double probability = 0.5;
2840 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2843 std::vector<double> expected(trials + 1);
2844 for (std::size_t i = 0; i < trials + 1; ++i)
2846 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2849 double chiSquared =
ChiSquared(h, expected, rng);
2851 gsl_histogram_free(h);
2862 double probability = 0.5;
2866 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2872 x->SetAttribute(
"Probability",
DoubleValue(probability));
2878 double mean = trials * probability;
2879 double valueMean =
Average(x);
2880 double expectedMean = mean;
2887 "Wrong mean value.");
2904 void DoRun()
override;
2908 :
TestCase(
"Check correct operation of the Shuffle function")
2922 std::vector<uint8_t> vec{};
2924 Shuffle(vec.begin(), vec.end(), rv);
2931 Shuffle(vec.begin(), vec.end(), rv);
2938 Shuffle(vec.begin(), vec.end(), rv);
2948 Shuffle(vec.begin(), vec.end(), rv);
2952 "Expected vector {4, 1, 9, 3, 2, 7}");
2965 void DoRun()
override;
2975 :
TestCaseBase(
"Laplacian Random Variable Stream Generator")
2987 double bound = 20.0;
2998 auto valueVariance =
Variance(x1, valueMean);
3001 const auto expectedMean = mu;
3009 "Wrong variance value.");
3024 const auto lowerBound = mu - bound;
3025 const auto upperBound = mu + bound;
3028 const auto value = x2->GetValue();
3031 "Value not in expected boundaries.");
3045 void DoRun()
override;
3055 :
TestCaseBase(
"Largest Extreme Value Random Variable Stream Generator")
3077 auto valueVariance =
Variance(x, valueMean);
3088 "Wrong variance value.");
3104 :
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