Bug 578

Summary: [contribution] ZipfVariable
Product: ns-3 Reporter: Francesco Malandrino <francesco.malandrino>
Component: coreAssignee: Michele Weigle <mweigle>
Status: RESOLVED FIXED    
Severity: normal CC: craigdo, francesco.malandrino, mathieu.lacage, mweigle, tomh
Priority: P5    
Version: pre-release   
Hardware: All   
OS: All   
Attachments: The patch
Patch, new version
Patch (for real)
Patch with correct copy constructor
Patch with (hopefully) correct coding style
correct coding style
include header diff
Validation plot for Zipf RNG with n=100. shape=1

Description Francesco Malandrino 2009-05-26 13:48:48 UTC
Created attachment 445 [details]
The patch

The attached patch adds a new ZipfVariable random variable.
The implementation is likely suboptimal, but it may still be useful.
Comment 1 Francesco Malandrino 2009-05-27 09:51:58 UTC
Created attachment 446 [details]
Patch, new version

This new version adds a default constructor. Additionally, it compiles correctly also in optimized mode.
Comment 2 Francesco Malandrino 2009-05-27 09:55:22 UTC
Created attachment 447 [details]
Patch (for real)

The patch done against che correct version of ns-3
Comment 3 Michele Weigle 2009-05-27 13:20:21 UTC
This looks fine, though I didn't check the math -- I assume it's correct.   Just to check, can you generate a PDF or CDF using this code and compare it against the theoretical PDF/CDF?

I do have a question about the Copy constructor:
RandomVariableBase* ZipfVariableImpl::Copy () const
{
  return new ZipfVariableImpl (m_n, m_alpha);
}

All of the other random variables have Copy constructors like this:
RandomVariableBase* NormalVariableImpl::Copy() const
{
  return new NormalVariableImpl(*this);
}

Why is this one different? 
Comment 4 Francesco Malandrino 2009-05-27 13:54:59 UTC
Created attachment 448 [details]
Patch with correct copy constructor

This version has a correct copy constructor
Comment 5 Mathieu Lacage 2009-05-28 10:27:53 UTC
(In reply to comment #4)
> Created an attachment (id=448) [details]
> Patch with correct copy constructor
> 
> This version has a correct copy constructor
> 

This version still has incorrect coding style: can you fix it before merging ?

i.e., 

for ()
  //do stuff

should be:

for ()
  {
    // do stuff
  }

yes, even for one-line for loops. see http://www.nsnam.org/codingstyle.html

Comment 6 Tom Henderson 2009-05-28 10:35:03 UTC
(In reply to comment #3)
> This looks fine, though I didn't check the math -- I assume it's correct.  
> Just to check, can you generate a PDF or CDF using this code and compare it
> against the theoretical PDF/CDF?

Craig just did some chi-squared testing of our other distributions, so I suspect he could easily check this one too.
Comment 7 Francesco Malandrino 2009-05-28 14:10:22 UTC
Created attachment 449 [details]
Patch with (hopefully) correct coding style
Comment 8 Mathieu Lacage 2009-05-28 14:15:09 UTC
Created attachment 450 [details]
correct coding style
Comment 9 Michele Weigle 2009-06-03 08:50:16 UTC
Once we get a validation of the implementation, I'm fine with accepting this.
Comment 10 Mathieu Lacage 2009-06-08 07:52:22 UTC
(In reply to comment #9)
> Once we get a validation of the implementation, I'm fine with accepting this.
> 

I can easily generate data for this implementation. Can you generate reference data I can check this against ?
Comment 11 Mathieu Lacage 2009-06-08 07:57:00 UTC
Created attachment 458 [details]
include header diff
Comment 12 Tom Henderson 2009-06-08 09:16:23 UTC
(In reply to comment #9)
> Once we get a validation of the implementation, I'm fine with accepting this.
> 

FYI, I asked Craig to run this through his chi-squared test framework and gsl, and report back here.
Comment 13 Craig Dowell 2009-06-15 20:03:59 UTC
GSL does not provide a Zipf/zeta distribution to use as a known-good PDF.

I can probably get the needed info out of Mathematica tomorrow; but this will be a hand-crafted very much special case validation test.

Anyone know of an (authoritative) open-source Zipf/zeta PDF and CDF function I can get my hands on?


Comment 14 Michele Weigle 2009-06-16 08:05:15 UTC
I found something at NIST.
http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/zippdf.htm

Looks like they have a Zipf distirbution in their Dataplot application:
http://www.itl.nist.gov/div898/software/dataplot/homepage.htm

Hope this helps.

-Michele
Comment 15 Craig Dowell 2009-06-16 15:05:16 UTC
Thanks Michele, ZIPCDF from DataPlot is exactly what I needed.

Heh, I love this.  Fortran-77 code with the original bleeding-edge version released by James J. Filliben in 1978.

Still useful (and runnable!) after all these years.












Comment 16 Craig Dowell 2009-06-17 15:20:50 UTC
Created attachment 470 [details]
Validation plot for Zipf RNG with n=100. shape=1

It took a little work, but I finally put together a simple validation test for this RNG.  This is by no means a comprehensive test, but the Zipf RNG appears to work nicely as advertised for N=100, alpha=1.  I don't plan on doing any more testing.

See attached PNG for a pretty picture.
Comment 17 Michele Weigle 2009-06-17 16:15:07 UTC
OK, I'm fine with this to be committed.

-Michele

Comment 18 Craig Dowell 2009-06-24 01:48:31 UTC
pushed, changeset:  c86681050541