Commons Math
  1. Commons Math
  2. MATH-222

Need way to compute density of distributions

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      Currently, there are a number of distributions defined in commons math, but the interface for Distribution and ContinuousDistribution doesn't provide for the computation of the PDF at a particular point.

      It is common for it to be necessary to compute the density function, for example in the Metropolis algorithm.

      It is also pretty common for it to be very difficult to compute a density function or for the density function to be undefined as certain points. Only the cumulative density is mathematically assured.

      Thus, I propose to create a new interface HasDensityFunction<T> that requires the implementation of a double density(T) method. T is the type of the argument for the density function which would be Double in the case of most univariate statistics, but could, for instance, be a vector of doubles for a Dirichlet distribution or a vector of integers for a Multinomial.

      1. MATH-222.patch
        37 kB
        Ted Dunning
      2. MATH-222-with-beta.patch
        45 kB
        Ted Dunning

        Activity

        Hide
        Ted Dunning added a comment -

        This is a patch that adds the proposed mechanism.

        Show
        Ted Dunning added a comment - This is a patch that adds the proposed mechanism.
        Hide
        Ted Dunning added a comment -

        This is a patch that implements the proposed density computation and adds an implementation of the beta distribution.

        I know that the addition of the beta distribution is a bit out of scope, but I was going to add that in any case and it would have needed a density method so it would have depended on this patch. To avoid dependencies, I merged the changes.

        A version of this patch without the beta distribution is also attached to this issue. If the other patch is put into trunk, I will be happy to submit a separate patch for the beta distribution.

        Show
        Ted Dunning added a comment - This is a patch that implements the proposed density computation and adds an implementation of the beta distribution. I know that the addition of the beta distribution is a bit out of scope, but I was going to add that in any case and it would have needed a density method so it would have depended on this patch. To avoid dependencies, I merged the changes. A version of this patch without the beta distribution is also attached to this issue. If the other patch is put into trunk, I will be happy to submit a separate patch for the beta distribution.
        Hide
        Luc Maisonobe added a comment -

        The first patch has been applied in subversion repository (in 2.0 branch) as of r693598 with the following changes:

        • the BetaDistributionTest file has been removed (it probably belongs to the second patch)
        • the commons-math.iml file has been removed (it probably depends on a specific development environment)
        • the patch for pom.xml has been removed (language level are configured using maven.compile.source and maven.compile.target properties)
        • Apache header has been added to the HasDensityFunction interface
        • Javadoc has been added to the HasDensityFunction interface

        Before applying the second patch, I think we would need a Contributor License Agreement (see http://www.apache.org/licenses/#clas. The patch adds a complete class that is almost 200 lines long so I don't think we can include it immediately. Apart from that, this would be an interesting addition.

        Show
        Luc Maisonobe added a comment - The first patch has been applied in subversion repository (in 2.0 branch) as of r693598 with the following changes: the BetaDistributionTest file has been removed (it probably belongs to the second patch) the commons-math.iml file has been removed (it probably depends on a specific development environment) the patch for pom.xml has been removed (language level are configured using maven.compile.source and maven.compile.target properties) Apache header has been added to the HasDensityFunction interface Javadoc has been added to the HasDensityFunction interface Before applying the second patch, I think we would need a Contributor License Agreement (see http://www.apache.org/licenses/#clas . The patch adds a complete class that is almost 200 lines long so I don't think we can include it immediately. Apart from that, this would be an interesting addition.
        Hide
        Ted Dunning added a comment -

        I have a CLA on file already (I am a Mahout committer).


        ted

        Show
        Ted Dunning added a comment - I have a CLA on file already (I am a Mahout committer). – ted
        Hide
        Luc Maisonobe added a comment -

        second patch added to branch MATH_2_0 as of r693959

        Show
        Luc Maisonobe added a comment - second patch added to branch MATH_2_0 as of r693959

          People

          • Assignee:
            Unassigned
            Reporter:
            Ted Dunning
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development