Bug 2082 - EmpiricalRandomVariable::Validate () fails if the value provided in the CDF member function is negative.
EmpiricalRandomVariable::Validate () fails if the value provided in the CDF m...
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: core
ns-3-dev
PC Linux
: P5 normal
Assigned To: Mathieu Lacage
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2015-03-20 08:32 UTC by Rubén Martínez
Modified: 2015-04-03 19:39 UTC (History)
2 users (show)

See Also:


Attachments
EmpiricalVariable patch (527 bytes, patch)
2015-03-20 08:32 UTC, Rubén Martínez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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