Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: On the rejected additions to List::Util

by mr_mischief (Monsignor)
on Apr 28, 2009 at 20:47 UTC ( [id://760740]=note: print w/replies, xml ) Need Help??


in reply to On the rejected additions to List::Util

As ikegami points out, the arithmetic mean isn't that difficult with the tools provided by List::Util. Even the geometric mean isn't that much code once the multiplication is reduced.

sub geo_mean { exp( (log (reduce { $a * $b } @_)) / @_); }

I think Statistics::Basic as suggested by Roy Johnson is a good start for someone looking for statistical methods. Statistics::Descriptive may be even better since it includes things like percentiles, the geometric mean, trimmed means, and frequency distributions. Then there are Math::VecStat and a few others.

As the question was asked relative to API design, let me point out Acme::Tools as a counterexample. This module offers both the arithmetic mean and the geometric mean. Along with those are some date functions, table formatting code, credit card processing subs, URL handling, and compression/decompression along with yet more stuff. This is the sort of thing module authors usually try to avoid, as you don't always need to compress your data with bzip2 when you're trying to find out the date for Easter.

You see, the list-specific tools of List::Util are limited by what the author felt were very handy within the domain of lists which didn't tread into other recognized domains. Since statistics is another recognized domain (there are university classes named "Statistics", even), modules that handle other statistical methods are a better place for things like averages.

Having lots of methods available to you on CPAN is wonderful. In some cases it might make sense to add a method here or there to an API for a module. However, one must draw the line somewhere. You really don't want CPAN to be one giant super module that exports everyone's pet method into your name space. I think the current lines between the List modules and the Statistics modules makes plenty of sense. There are times you're working with lists and don't need statistics. There are other times you need statistics but not reduction, set logic, and zipping.

In this particular case, searching for "average" on http://search.cpan.org admittedly isn't very helpful. Searching for "mean" is slightly more helpful. Searching for something with fewer unrelated meanings like "geometric mean", "statistics", "monte carlo", or "standard deviation" is much more helpful. Just because you can't find the method you want where you look first doesn't mean nothing on CPAN has it, though.

Update: I replaced 'classes named "Statistics",' with 'university classes named "Statistics",' to make clearer what definition of "classes" I was using.

Replies are listed 'Best First'.
Re^2: On the rejected additions to List::Util
by planetscape (Chancellor) on Apr 28, 2009 at 22:47 UTC
    you don't always need to compress your data with bzip2 when you're trying to find out the date for Easter

    Such can come in handy when playing Fizzbin, however. ;-)

    HTH,

    planetscape

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://760740]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-28 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found