|
|
| 2783 |
{ |
2783 |
{ |
| 2784 |
SetTestSuiteSeed (); |
2784 |
SetTestSuiteSeed (); |
| 2785 |
|
2785 |
|
| 2786 |
// Create the RNG with a uniform distribution between 0 and 10. |
|
|
| 2787 |
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> (); |
| 2788 |
x->CDF ( 0.0, 0.0); |
| 2789 |
x->CDF ( 5.0, 0.5); |
| 2790 |
x->CDF (10.0, 1.0); |
| 2791 |
|
| 2792 |
// Calculate the mean of these values. |
| 2793 |
double sum = 0.0; |
| 2794 |
double value; |
| 2795 |
for (uint32_t i = 0; i < N_MEASUREMENTS; ++i) |
| 2796 |
{ |
2786 |
{ |
| 2797 |
value = x->GetValue (); |
2787 |
// Create the RNG with a uniform distribution between 0 and 10. |
| 2798 |
sum += value; |
2788 |
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> (); |
|
|
2789 |
x->CDF ( 0.0, 0.0); |
| 2790 |
x->CDF ( 5.0, 0.5); |
| 2791 |
x->CDF (10.0, 1.0); |
| 2792 |
|
| 2793 |
// Calculate the mean of these values. |
| 2794 |
double sum = 0.0; |
| 2795 |
double value; |
| 2796 |
for (uint32_t i = 0; i < N_MEASUREMENTS; ++i) |
| 2797 |
{ |
| 2798 |
value = x->GetValue (); |
| 2799 |
sum += value; |
| 2800 |
} |
| 2801 |
double valueMean = sum / N_MEASUREMENTS; |
| 2802 |
|
| 2803 |
// The expected value for the mean of the values returned by this |
| 2804 |
// empirical distribution is the midpoint of the distribution |
| 2805 |
// |
| 2806 |
// E[value] = 5 . |
| 2807 |
// |
| 2808 |
double expectedMean = 5.0; |
| 2809 |
|
| 2810 |
// Test that values have approximately the right mean value. |
| 2811 |
double TOLERANCE = expectedMean * 1e-2; |
| 2812 |
NS_TEST_ASSERT_MSG_EQ_TOL (valueMean, expectedMean, TOLERANCE, "Wrong mean value."); |
| 2799 |
} |
2813 |
} |
| 2800 |
double valueMean = sum / N_MEASUREMENTS; |
|
|
| 2801 |
|
| 2802 |
// The expected value for the mean of the values returned by this |
| 2803 |
// empirical distribution is the midpoint of the distribution |
| 2804 |
// |
| 2805 |
// E[value] = 5 . |
| 2806 |
// |
| 2807 |
double expectedMean = 5.0; |
| 2808 |
|
| 2809 |
// Test that values have approximately the right mean value. |
| 2810 |
double TOLERANCE = expectedMean * 1e-2; |
| 2811 |
NS_TEST_ASSERT_MSG_EQ_TOL (valueMean, expectedMean, TOLERANCE, "Wrong mean value."); |
| 2812 |
|
2814 |
|
| 2813 |
// Bug 2082: Create the RNG with a uniform distribution between -1 and 1. |
2815 |
// Bug 2082: Create the RNG with a uniform distribution between -1 and 1. |
| 2814 |
Ptr<EmpiricalRandomVariable> y = CreateObject<EmpiricalRandomVariable> (); |
2816 |
Ptr<EmpiricalRandomVariable> y = CreateObject<EmpiricalRandomVariable> (); |
|
|
| 2816 |
y->CDF (0.0, 0.5); |
2818 |
y->CDF (0.0, 0.5); |
| 2817 |
y->CDF (1.0, 1.0); |
2819 |
y->CDF (1.0, 1.0); |
| 2818 |
NS_TEST_ASSERT_MSG_LT (y->GetValue (), 2, "Empirical variable with negative domain"); |
2820 |
NS_TEST_ASSERT_MSG_LT (y->GetValue (), 2, "Empirical variable with negative domain"); |
|
|
2821 |
|
| 2822 |
{ |
| 2823 |
// Create the RNG with a bimodal distribution |
| 2824 |
// Half of the values are 0.0, half ot the values are 100.0. |
| 2825 |
|
| 2826 |
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> (); |
| 2827 |
x->CDF ( 0.0, 0.5); |
| 2828 |
x->CDF (100.0, 1.0); |
| 2829 |
|
| 2830 |
// Calculate the mean of these values. |
| 2831 |
double sum = 0.0; |
| 2832 |
double value; |
| 2833 |
for (uint32_t i = 0; i < N_MEASUREMENTS; ++i) |
| 2834 |
{ |
| 2835 |
value = x->GetValue (); |
| 2836 |
sum += value; |
| 2837 |
} |
| 2838 |
double valueMean = sum / N_MEASUREMENTS; |
| 2839 |
|
| 2840 |
// The expected value for the mean of the values returned by this |
| 2841 |
// empirical distribution is |
| 2842 |
// |
| 2843 |
// E[value] = 50 . |
| 2844 |
// |
| 2845 |
double expectedMean = 50.0; |
| 2846 |
|
| 2847 |
// Test that values have approximately the right mean value. |
| 2848 |
double TOLERANCE = expectedMean * 1e-2; |
| 2849 |
NS_TEST_ASSERT_MSG_EQ_TOL (valueMean, expectedMean, TOLERANCE, "Wrong mean value."); |
| 2850 |
} |
| 2819 |
} |
2851 |
} |
| 2820 |
|
2852 |
|
| 2821 |
// =========================================================================== |
2853 |
// =========================================================================== |