Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: On the rejected additions to List::Util by mr_mischief
in thread On the rejected additions to List::Util by metaperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found