I said:
>On the other hand, maybe these should be DateTime::Set methods:
>   my $mean   = $set->mean( $sunrise, $sunset );
>   my $median = $set->median( $sunrise, $sunset );

On Thu, 10 Jun 2004 18:04:36 -0700, Bruce Van Allen wrote
> Huh? I'm confused by your usage of 'mean' and 'median'. In the case in
> question, I think 'midpoint' is a much clearer term to use.

I suggest placing mean and median in a module rather than just the FAQ because the 
current solution is just the midpoint of two datetimes. The mean can give this, but 
can 
also give results for more than two datetimes. 

Consider that an FAQ entry for calculating the average time you start work from a list 
of 
DateTimes would be a lot longer so should we put it in the FAQ? I don't think so. I 
think 
it should be a library method placed either in a Util module or in the DateTime::Set 
module. Then, once we do that, we can change the FAQ entry for midpoint to "Either 
use the 'mean' function in DateTime::XXX::XXX or use the following algorithm"

As for my usage of 'mean' and 'median':

'mean' and 'median' are mathematical constructs. The 'mean' is often called the 
'average' while the 'median' would be the middle value.

mean(1,2,3) == 2
median(1,2,3) == 2

But here's the difference:
mean(1,2,6) == 3
median(1,2,6) == 2

And the 'median' value with an even number of arguments:
median(1,2,3,4) == 2.5
(middle is both 2 and 3, therefore use their mean (2 + 3) / 2 == 2.5)


And the maths involved:
sub mean{
   return sum(@_) / scalar(@_);
}

sub median{
   my $middle = (scalar(@_) + 1) / 2;
   return ($middle == int(middle)) 
      ? $_[  $middle ]
      : mean( $_[  int($middle) ], $_[  int($middle)+1 ]);
}

sub sum {
   my $return = 0;
   $return += $_ foreach @_;
   return $return;
}

Of course, the DateTime code would be more difficult. I'd probably cheat by getting 
rd_secs and using the above mathematical functions to get mean and median rd_secs 
and then turning them back into DateTime objects.

Hope that clears it up.

Cheers!
Rick


Reply via email to