Bug 2082

Summary: EmpiricalRandomVariable::Validate () fails if the value provided in the CDF member function is negative.
Product: ns-3 Reporter: Rubén Martínez <rmartinez>
Component: coreAssignee: Mathieu Lacage <mathieu.lacage>
Status: RESOLVED FIXED    
Severity: normal CC: ns-bugs, tomh
Priority: P5    
Version: ns-3-dev   
Hardware: PC   
OS: Linux   
Attachments: EmpiricalVariable patch

Description Rubén Martínez 2015-03-20 08:32:00 UTC
Created attachment 1997 [details]
EmpiricalVariable patch

If the provided empirical CDF contains negative values in the X axis this function will always report an error (and it should not).

This issue can be reproduced like this: 

  EmpiricalRandomVariable uv;

  uv.CDF(-0.1,0.1);
  uv.CDF(0, 0.2);
  uv.CDF(0.1, 0.3);

  uv.GetValue();


The problem is: 

Line 1601: if (current.value < prior.value || current.cdf < prior.cdf)

Which is true in the first iteration because the "prior" variable is initialized by its default constructor:

Line 1597:  ValueCDF prior;

Which sets prior.value = 0 and prior.cdf = 0.

A possible fix would be to assign the first element of the empirical distribution:

Line 1597:  ValueCDF prior = emp[0];
Comment 1 Tom Henderson 2015-03-26 14:19:47 UTC
I confirmed this and agree with (and tested) the patch (although the example provided should use

  Ptr<EmpiricalRandomVariable> uv = CreateObject<EmpiricalRandomVariable> ();
)

I will apply tomorrow if no other comments.
Comment 2 Tom Henderson 2015-04-03 19:39:26 UTC
pushed in changeset 11278:4213cff834ff