|
Boost : |
From: Matthias Schabel (boost_at_[hidden])
Date: 2007-03-05 15:20:42
> In building probability and likelihood models, I often encounter the
> issue of transforming from either to their logarithms and vice versa.
> Code would be much simpler and less error-prone if the appropriate
> domain was defined, the natural arithmetic operators were used, and
> the conversions occurred (or could be prevented to catch errors) as
> necessary, but without necessarily requiring explicit bookkeeping to
> distinguish these quantities and their logarithms.
>
> This suggests a (small) set of types with appropriate conversions,
> much as in the units library. However, probabilities are of course
> unitless.
>
> Should this idea be developed as a separate library or does it make
> any sense to fold it into the existing units framework?
We've tried to make mcs::units as flexible and extensible as possible
in order to accommodate a wide range of value types; as you point
out, since probabilities and log probabilities don't have associated
units (by definition, since taking the log of a unit doesn't make any
sense from a dimensional analysis standpoint), so I don't think this
is something that should be directly supported in the library itself.
That being said, mcs::units can be used for tagging and conversion
in this way if you're willing to specialize the conversion_helper class
template for your probability/log_probability classes.
If you want to try this, I can walk you through the steps...
Matthias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk