Bug 1313

Summary: Stddev (average.h) returning NaN
Product: ns-3 Reporter: Tom Henderson <tomh>
Component: statsAssignee: Mitch Watrous <watrous>
Status: RESOLVED FIXED    
Severity: normal CC: ns-bugs, tjkopena
Priority: P5    
Version: pre-release   
Hardware: All   
OS: All   

Description Tom Henderson 2011-12-14 13:13:12 EST
It has been reported by Nicholas Loulloudes that Stddev() in src/tools/average.h can return NaN on a non-empty list.  Discussion here:
http://mailman.isi.edu/pipermail/ns-developers/2011-December/009699.html

Doxygen updates and possible code updates may be needed.

Also, the return values for the empty list may not be consistent between src/tools/average.h and src/stats/model/basic-data-calculators.h.  The convention seems to be to return NaN for empty list; e.g.
http://commons.apache.org/math/apidocs/org/apache/commons/math/stat/StatUtils.html
Comment 1 Tommaso Pecorella 2012-03-18 18:51:06 EDT
Just to summarize (and maybe close) this bug.

The analysis is wrong, as in "Count () / (double)(Count () - 1) * (m_avg2 - m_avg*m_avg)" the "(m_avg2 - m_avg*m_avg)" part is not at denominator.

The above code will return:
- 0 for Count = 0 (kinda stupid, but still)
- NaN for Count = 1 (it's expected and should be)
- a value, in all the other cases, with the special case:
-- 0 for a constant input (and this is as expected too).

Note that in the last case it is possible to have a near-zero result due to finite precision arithmetic.

Anyway, the issue remains, as we do have two different places where the calcs are done in slightly different ways. My proposal (at the time and now) is to merge them. Sadly, it's not that simple.

Checking the two implementations, one can see that:
1) the one in stats/model/basic-data-calculators.h is more complete (does more things) and it's also more precise, as it's implementing exactly the well-known Knuth's algorithm.
2) the one in tools/model/average.h is a more naive implementation (although not totally wrong) and might lead to drifts for large sequences.

So the obvious conclusion would be to use the basic-data-calculators.h one, but it's in a module and the dependencies would be not right. So the only left solution is:
a) pick the basic-data-calculators.h algorithm and improve the one in average.h
b) have basic-data-calculators.h rely on average.h functions
c) close this.

Anybody feeling like to do it ?

Cheers,

T.
Comment 2 Mitch Watrous 2012-03-20 12:56:45 EDT
Bug closed.

ns-3-dev changeset:  f794f31dc0be
Comment 3 Tommaso Pecorella 2012-03-20 14:27:19 EDT
Considering that in tools module there is:
module = bld.create_ns3_module('tools', ['network'])

and in stats module there is:
obj = bld.create_ns3_module('stats', ['network'])

there is no apparent dependency. However there is.

Shouldn't the tools one be:
module = bld.create_ns3_module('tools', ['network', 'stats']) ?

Cheers,

T.
Comment 4 Mitch Watrous 2012-03-20 14:46:28 EDT
(In reply to comment #3)
> Considering that in tools module there is:
> module = bld.create_ns3_module('tools', ['network'])
> 
> and in stats module there is:
> obj = bld.create_ns3_module('stats', ['network'])
> 
> there is no apparent dependency. However there is.
> 
> Shouldn't the tools one be:
> module = bld.create_ns3_module('tools', ['network', 'stats']) ?
> 
> Cheers,
> 
> T.

I did just what you suggested.  Here is the relevant line from

    src/tools/wscript

that specifies the tools module's dependencies:

    module = bld.create_ns3_module('tools', ['network', 'stats'])
Comment 5 Tommaso Pecorella 2012-03-20 15:07:36 EDT
Sry, didn't see that line. Nvm :)

Ty,