Boost logo

Boost :

From: Kevin Lynch (krlynch_at_[hidden])
Date: 2006-07-09 06:48:45


John Maddock wrote:
> Paul Bristow has been toiling away producing some statistical functions on
> top of some of my Math special functions, and we've encountered a bit of a
> naming dilemma that I hope the ever resourceful Boosters can solve for us
> :-)
>

<snip>

> So I'm hoping some Boosters can work their usual naming magic :-)
>

Why not hide the functions behind a class interface? After all, the
various functions are "properties" of the distributions. Hence:

class students_t {
        students_t(double mu);
        double P(double x);
        double Q(double x);
        double invP(double p); (or perhaps inverseP or Pinv or something)
        .....
}

class normal {
        normal(double mu, double sigma);
        double P(double x);
        double Q(double x);
        double invP(double x);
        ......
}

This interface has a few major benefits over raw functions:

1) Since Paul is using your C++ special functions library in the
implementation, there's no argument on the implementation side for C
compatibility. Without C compatibility as a driving force, you don't
need to stick with free functions and the corresponding combinatorial
explosion of hard to remember names.
2) A class interface also lets you carry around data specific to the
current "in use" distribution in one place, rather than needing to stuff
it into every call (the mean in the case of Student's t, the mean and
deviation for the Normal, etc).
3) This "normalizes" the interface for the calls to the distribution
functions - every call for "P" has exactly one argument, and not two or
three or four depending on the distribution in use.
4) The consistent interface is of course easier to document, teach and
learn, and easier to use.

Every well behaved (1D) distribution has to fit this interface, doesn't
it? In other words, all well behaved (1D cumulative) distributions have
to be single valued and invertible. You might also want to provide a
function to obtain the non-cumulative distribution value (perhaps
operator() or dist() or something).

Of course, you would probably templatize and you might want to inherit
from 1D or 2D abstract base classes if you plan to provide
multidimensional distributions (or maybe not ...) and functions that
operate on distributions.

In any case, I look forward to the results....

-- 
-------------------------------------------------------------------------------
Kevin Lynch				voice:	(617) 353-6025
Physics Department			Fax: (617) 353-9393
Boston University			office:	 PRB-361
590 Commonwealth Ave.			e-mail:	 krlynch_at_[hidden]
Boston, MA 02215 USA			http://budoe.bu.edu/~krlynch
-------------------------------------------------------------------------------

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk