Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-1153

Sampling from a 'BetaDistribution' is slow

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 4.0, 3.6
    • None
    • None

    Description

      Currently the `BetaDistribution#sample` uses inverse CDF method, which is quite slow for sampling-intensive computations. I've implemented a method from the R. C. H. Cheng paper and it seems to work much better. Here's a simple microbenchmark:

      o.j.b.s.SamplingBenchmark.algorithmBCorBB       1e-3    1000  thrpt        5  2592200.015    14391.520  ops/s
      o.j.b.s.SamplingBenchmark.algorithmBCorBB       1000    1000  thrpt        5  3210800.292    33330.791  ops/s
      o.j.b.s.SamplingBenchmark.commonsVersion        1e-3    1000  thrpt        5    31034.225      438.273  ops/s
      o.j.b.s.SamplingBenchmark.commonsVersion        1000    1000  thrpt        5    21834.010      433.324  ops/s
      

      Should I submit a patch?

      R. C. H. Cheng (1978). Generating beta variates with nonintegral shape parameters. Communications of the ACM, 21, 317–322.

      Attachments

        1. ChengBetaSampler.java
          3 kB
          Sergei Lebedev
        2. ChengBetaSamplerTest.java
          3 kB
          Sergei Lebedev
        3. ChengBetaSampler.java
          3 kB
          Sergei Lebedev

        Activity

          People

            Unassigned Unassigned
            lebedev Sergei Lebedev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: