avgtime - Small D util for your everyday benchmarking needs

Don Clugston dac at nospam.com
Fri Mar 23 03:51:36 PDT 2012


On 23/03/12 11:20, Don Clugston wrote:
> On 23/03/12 09:37, Juan Manuel Cabo wrote:
>> On Friday, 23 March 2012 at 05:51:40 UTC, Manfred Nowak wrote:
>>>
>>> | For samples, if it is known that they are drawn from a symmetric
>>> | distribution, the sample mean can be used as an estimate of the
>>> | population mode.
>>
>> I'm not printing the population mode, I'm printing the 'sample mode'.
>> It has a very clear meaning: most frequent value. To have frequency,
>> I group into 'bins' by precision: 12.345 and 12.3111 will both
>> go to the 12.3 bin.
>>
>>>
>>> and the program computes the variance as if the values of the sample
>>> follow a normal distribution, which is symmetric.
>>
>> This program doesn't compute the variance. Maybe you are talking
>> about another program. This program computes the standard deviation
>> of the sample. The sample doesn't need to of any distribution
>> to have a standard deviation. It is not a distribution parameter,
>> it is a statistic.
>>
>>> Therefore the mode of the sample is of interest only, when the variance
>>> is calculated wrongly.
>>
>> ???
>>
>> The 'sample mode', 'median' and 'average' can quickly tell you
>> something about the shape of the histogram, without
>> looking at it.
>> If the three coincide, then maybe you are in normal distribution land.
>>
>> The only place where I assume normal distribution is for the
>> confidence intervals. And it's in the usage help.
>>
>> If you want to support estimating weird probability
>> distributions parameters, forking and pull requests are
>> welcome. Rewrites too. Good luck detecting distribution
>> shapes!!!! ;-)
>>
>>
>>>
>>> -manfred
>>
>> PS: I should use the t student to make the confidence intervals,
>> and for computing that I should use the sample standard
>> deviation (/n-1), but that is a completely different story.
>> The z normal with n>30 aproximation is quite good.
>> (I would have to embed a table for the t student tail factors,
>> pull reqs velcome).
>
> No, it's easy. Student t is in std.mathspecial.

Aargh, I didn't get around to copying it in. But this should do it.

/** Inverse of Student's t distribution
  *
  * Given probability p and degrees of freedom nu,
  * finds the argument t such that the one-sided
  * studentsDistribution(nu,t) is equal to p.
  *
  * Params:
  * nu = degrees of freedom. Must be >1
  * p  = probability. 0 < p < 1
  */
real studentsTDistributionInv(int nu, real p )
in {
    assert(nu>0);
    assert(p>=0.0L && p<=1.0L);
}
body
{
     if (p==0) return -real.infinity;
     if (p==1) return real.infinity;

     real rk, z;
     rk =  nu;

     if ( p > 0.25L && p < 0.75L ) {
         if ( p == 0.5L ) return 0;
         z = 1.0L - 2.0L * p;
         z = betaIncompleteInv( 0.5L, 0.5L*rk, fabs(z) );
         real t = sqrt( rk*z/(1.0L-z) );
         if( p < 0.5L )
             t = -t;
         return t;
     }
     int rflg = -1; // sign of the result
     if (p >= 0.5L) {
         p = 1.0L - p;
         rflg = 1;
     }
     z = betaIncompleteInv( 0.5L*rk, 0.5L, 2.0L*p );

     if (z<0) return rflg * real.infinity;
     return rflg * sqrt( rk/z - rk );
}


More information about the Digitalmars-d-announce mailing list