Free cookie consent management tool by TermsFeed Policy Generator

Opened 5 years ago

Last modified 4 years ago

#3027 closed enhancement

Provide a simple, efficient, and correct implementation to sample Gaussian random variables — at Version 4

Reported by: gkronber Owned by:
Priority: medium Milestone: HeuristicLab 3.3.17
Component: Random Version: trunk
Keywords: Cc:

Description (last modified by gkronber)

We currently use the Ziggurat method which is fast but not straight-forward. abeham made some tests and found significant deviations of the empirical distributions of samples generated with our implementation compared to other implementations.

In this image an offset is added to the probability values to prevent overlapping of points. The issue is that the blue line stops at approx. -3.5 and 3.5. So the current implementation does not produce correct distributions in the tails.

Change History (5)

comment:1 Changed 5 years ago by gkronber

Code from Sim#:

    const double NormalMagicConst = 4 * Math.Exp(-0.5) / Math.Sqrt(2.0);
    public double RandNormal(double mu, double sigma) {
      double z, zz, u1, u2;
      do {
        u1 = Random.NextDouble();
        u2 = 1 - Random.NextDouble();
        z = NormalMagicConst * (u1 - 0.5) / u2;
        zz = z * z / 4.0;
      } while (zz > -Math.Log(u2));
      return mu + z * sigma;
    }

comment:2 Changed 5 years ago by gkronber

Performance comparison (1mio samples, release build):

FastRandom:
N(0,1)-hl: 28,7
N(0,1)-Sim#: 53,9
N(0,1)-alglib: 69,7

MersenneTwister:
N(0,1)-hl: 92,3
N(0,1)-Sim#: 174,1

Changed 5 years ago by gkronber

comment:3 Changed 5 years ago by gkronber

  • Description modified (diff)

comment:4 Changed 5 years ago by gkronber

  • Description modified (diff)
Note: See TracTickets for help on using tickets.