Subject: Re: CVS commit: src
To: Brian C. Grayson <bgrayson@orac.ece.utexas.edu>
From: Bill Studenmund <skippy@macro.Stanford.EDU>
List: source-changes
Date: 02/25/1999 10:50:18
On Wed, 24 Feb 1999, Brian C. Grayson wrote:

>   Problem 1:  The equation for the variance is wrong.  It ought to be:
> double variance = ((tsumsq/n) - avg*avg) * (n/(n-1));

or (tsumsq - n*avg*avg)/(n-1) which saves a divide. :-)

>   Try it out with two samples of 1e-3 and 1e-3, and the variance
> ought to be 0, and not 1e-6 as the current code produces.
> 
>   Problem 2:  Scaling is wrong.  In the printf, we print
> sqrt(variance*1000), but that should be sqrt(variance)*1000.
> 
> 
>   I've verified the correctness of this by using the octave
> stddev builtin (std) to calculate the stddev of the sample
> times.  Here's a diff, if you want to commit, or I can if there
> are no objections (and Luke/Matthew agree).
> 
> RCS file: /ccd0/cvsroot/src/sbin/ping/ping.c,v
> retrieving revision 1.44
> diff -1 -u -t -p -r1.44 ping.c
> --- ping.c  1999/02/24 19:31:38     1.44
> +++ ping.c  1999/02/25 02:52:22
> @@ -1113,3 +1113,3 @@ summary(int header)
>                  double avg = (tsum / n);
> -                double variance = (tsumsq / (n - (avg * avg)));
> +                double variance = ((tsumsq/n) - avg*avg) * (n/(n-1));
Or

  +                double variance = (tsumsq - n*avg*avg) /(n-1);
>  
> @@ -1118,3 +1118,3 @@ summary(int header)
>                          tmin * 1000.0, avg * 1000.0,
> -                        tmax * 1000.0, sqrt(variance * 1000.0));
> +                        tmax * 1000.0, sqrt(variance) * 1000.0);
>                  if (pingflags & F_FLOOD) {
> 
>