Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-68

AhrensDieterMarsagliaTsangGammaSampler constructor can be optimised for the theta parameter

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Implemented
    • 1.2
    • 1.3
    • sampling
    • None

    Description

      The AhrensDieterExponentialSampler has two algorithms based on the theta parameter. The constructor precomputes factors for both algorithms even though only one algorithm will even be called.

      I suggest optimising the constructor using:

      public AhrensDieterMarsagliaTsangGammaSampler(UniformRandomProvider rng,
                                                    double alpha,
                                                    double theta) {
          super(null);
          this.rng = rng;
          this.alpha = alpha;
          this.theta = theta;
          gaussian = new ZigguratNormalizedGaussianSampler(rng);
          if (theta < 1) {
              oneOverTheta = 1 / theta;
              bGSOptim = 1 + theta / Math.E;
              // Unused
              dOptim = cOptim = 0;
          } else {
              dOptim = theta - ONE_THIRD;
              cOptim = ONE_THIRD / Math.sqrt(dOptim);
              // Unused
              oneOverTheta = bGSOptim = 0;
          }
      }
      

      An alternative is to split the two algorithms into two classes as was done for the PoissonSampler for small and large mean.

      Attachments

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m