CDF not covered error with Empirical Random Variable even though CDF is covered

23 views
Skip to first unread message

Krishna Bharadwaj Pisupati

unread,
Feb 3, 2020, 3:14:40 AM2/3/20
to ns-3-users
Hii there,

I used Empirical RV as documented (Strictly increasing values and CDF between 0 to 1 covering whole distribution). But the error I'm facing was when I used this in the hardcoding method and in for loop. erv1 is a pointer object to Empirical RV

Method 1 : Hardcoding (No ERROR)

 erv1->CDF (-61,0);
 erv1
->CDF (-60,0.00216478);
 erv1
->CDF (-59,0.0233032);
 erv1
->CDF (-58,0.0855724);
 erv1
->CDF (-57,0.157137);
 erv1
->CDF (-56,0.201324);
 erv1
->CDF (-55,0.240418);
 erv1
->CDF (-54,0.363555);
 erv1
->CDF (-53,0.512543);
 erv1
->CDF (-52,0.584617);
 erv1
->CDF (-51,0.630078);
 erv1
->CDF (-50,0.669426);
 erv1
->CDF (-49,0.702789);
 erv1
->CDF (-48,0.729785);
 erv1
->CDF (-47,0.757672);
 erv1
->CDF (-46,0.784159);
 erv1
->CDF (-45,0.81141);
 erv1
->CDF (-44,0.829747);
 erv1
->CDF (-43,0.864001);
 erv1
->CDF (-42,0.915446);
 erv1
->CDF (-41,0.949191);
 erv1
->CDF (-40,0.975169);
 erv1
->CDF (-39,0.992232);
 erv1
->CDF (-38,1);


Method 2 : Using in for loop (ERROR : CDF does not cover the whole distribution)

 std::vector<std::vector<double> > file1data;
 file1data
= GrabCDFFrom ("trace_pdf.txt");
 std
::cout << "matrix contains " << file1data.size() << " rows\n";
 
for (unsigned int i = 0 ; i < file1data.size(); i++)
 
{
   std
::cout << file1data[i][1] << "\t" << file1data[i][0] << "\n";
   erv1
->CDF (file1data[i][1], file1data[i][0]);
 
}


When for loop is used, I used cout statements inside user-script and NS_LOG_UNCOND statements in random-variable-stream.cc. Both the vectors (from user-script and libraries) were having the same values. The code is throwing error even the prior.cdf =1 (from random-variable-stream.cc) in this case.

Kindly tell me where I'm going wrong. I'm not able to detect the error I'm doing. I'm attaching the user-script (empirical_rv_error.cc) and sample text file to calculate CDF (trace_pdf.txt)

Thanks and Regards,
Krishna.


emperical_rv_error.cc
trace_pdf.txt

Krishna Bharadwaj Pisupati

unread,
Feb 3, 2020, 3:19:35 AM2/3/20
to ns-3-users
Hii there,

Kindly delete line 55 [erv1->SetAttribute ("Interpolate", BooleanValue (true));] from the attached cc file to compile without any errors. Apologies for the error in the file.

Thanks and regards,
Krishna.

pdbarnes

unread,
Feb 3, 2020, 2:14:07 PM2/3/20
to ns-3-users
The trace file and your hard-coded script don't have the same data...

The trace file begins

 17 -60
166 -59 

In the loop you reverse the order, so you insert "17" as the first CDF probability, not 0 or 0.00216478

On Monday, February 3, 2020 at 12:14:40 AM UTC-8, Krishna Bharadwaj Pisupati wrote:

 erv1->CDF (-61,0);
 erv1
->CDF (-60,0.00216478);

Krishna Bharadwaj Pisupati

unread,
Feb 3, 2020, 11:22:00 PM2/3/20
to ns-3-users
Hi pdbarnes,

The function GrabCDFFrom (*.txt) has this initial CDF point inclusion. After reading the data from .txt, it computes CDF and finally includes the following vector value: (intial data-1, 0.0). I checked this by printing the values from the random-variable-stream library. I'm attaching the output of 2 methods for your reference. Kindly suggest me if somewhere I'm going wrong.

 // Pushing the initial CDF value of 0.0 into the 2D vector
 
double initial_cdf = 0.0;
 std
::vector<double> initialdata;
 initialdata
.push_back (initial_cdf);
 initialdata
.push_back (allData[0][1]-1);
 allData
.insert (allData.begin(),initialdata);


Thanks and regards,
Krishna.
CDF_from_library.png
CDF_from_script.png
Harcoded_CDF_NoError.png

Krishna Bharadwaj Pisupati

unread,
Feb 4, 2020, 1:14:28 AM2/4/20
to ns-3-users
Hi pdbarnes,

I found out the error. As you said, the trace is not the same as the hardcoded one. But a small change in that!!!. When computing CDF, the last value of the vector was 0.999999 with high precision (20 digits) but it was never equal to one. But the std::cout statement was showing the value as 1. In the hardcode method I was forcing the last value to be 1. This is where the code got stuck. So I used std::ceil (last value in vector) which got compiled without any errors.

Since it's a C++ discussion, kindly suggest me whether to delete or retain this post in ns-3 group.

Thanks and Regards,
Krishna.

pdbarnes

unread,
Feb 5, 2020, 6:35:31 PM2/5/20
to ns-3-users
Ahhh!  Looks like EmpriricalRandomVariable could give you a better error message, by showing the final cdf value.  I'll create an issue for this:
Reply all
Reply to author
Forward
0 new messages