Commons Math
  1. Commons Math
  2. MATH-1039

Logarithmic probability and density calculations for the distributions

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 4.0
    • Labels:

      Description

      A person working with fairly small probabilities and densities often employs their logarithms to increase precision and decrease the chance of an underflow. However, just taking a log of the probability() or density() return value doesn't necessarily solve the problem, as these methods themselves could have lost precision or underflowed. This patch introduces new logProbability() and logDensity() methods overriden for many relevant distribution. The patch also introduces tests of these new methods.

      1. LOGDENSITY.patch
        37 kB
        Aleksei Dievskii

        Activity

        Hide
        Aleksei Dievskii added a comment -

        You're welcome!

        Show
        Aleksei Dievskii added a comment - You're welcome!
        Hide
        Phil Steitz added a comment -

        Patch committed with only one material change in r1533974

        • New logDensity methods were not added to interfaces; only to abstract parents.

        Leaving this open so we do not forget to lift to interfaces in 4.0.

        Many thanks for the patch!

        Show
        Phil Steitz added a comment - Patch committed with only one material change in r1533974 New logDensity methods were not added to interfaces; only to abstract parents. Leaving this open so we do not forget to lift to interfaces in 4.0. Many thanks for the patch!
        Hide
        Aleksei Dievskii added a comment -

        2.14.1, though I don't think that they changed these functions in the next release.

        Show
        Aleksei Dievskii added a comment - 2.14.1, though I don't think that they changed these functions in the next release.
        Hide
        Phil Steitz added a comment -

        Thanks! What version of R?

        Show
        Phil Steitz added a comment - Thanks! What version of R?
        Hide
        Aleksei Dievskii added a comment -

        1. I didn't know that interfaces couldn't be changed outside a major release. Of course, keeping the changes to abstract parents will cover the immediate needs.
        2. The reference data come from R (so I just haven't changed the overall testing data disclaimer). I used the standard density functions (dpois, dnorm and so on) with log=TRUE argument.

        Show
        Aleksei Dievskii added a comment - 1. I didn't know that interfaces couldn't be changed outside a major release. Of course, keeping the changes to abstract parents will cover the immediate needs. 2. The reference data come from R (so I just haven't changed the overall testing data disclaimer). I used the standard density functions (dpois, dnorm and so on) with log=TRUE argument.
        Hide
        Phil Steitz added a comment -

        This looks very good and useful. Thanks for the patch! Just a couple of quick comments and I can commit.

        1. For 3.3 we can't add to the interfaces, so I suggest to add impls to the abstract parents and hold the add to the interfaces until 4.0. Unless someone screams, I will do that (so just omit the changes to the distribution interfaces)
        2. Thanks so much for the careful job on the test cases. Where does the reference data come from? I like to include the source of reference data where possible.

        Show
        Phil Steitz added a comment - This looks very good and useful. Thanks for the patch! Just a couple of quick comments and I can commit. 1. For 3.3 we can't add to the interfaces, so I suggest to add impls to the abstract parents and hold the add to the interfaces until 4.0. Unless someone screams, I will do that (so just omit the changes to the distribution interfaces) 2. Thanks so much for the careful job on the test cases. Where does the reference data come from? I like to include the source of reference data where possible.
        Hide
        Aleksei Dievskii added a comment -

        The patch introducing logDensity() and logProbability().

        Show
        Aleksei Dievskii added a comment - The patch introducing logDensity() and logProbability().

          People

          • Assignee:
            Phil Steitz
            Reporter:
            Aleksei Dievskii
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development