Generating Random Upside-down Gaussian Distribution

Viewed 129

I am attempting to generate a random distribution that follows an upside-down gaussian distribution, shifted uo so that it is still in range(0,1). I need to do this with as few special functions as possible and can only use a flat random number generator.

I am able to generate according to a Gaussian by putting the flat random numbers through the inverse Gaussian CDF. This works and gives me the gaussian dist that I would expect. In python, this looks like this:

def InverseCDF(x, mu, sigma):
  return mu + sigma * special.erfinv(2*x - 1)

Now when I am trying to generate a distribution that follows 1-e^(-x^2), I believe the inverse CDF of this function is the same as for the regular gaussian with the argument of the inverse error function now 2*p + 1. So it would look like below:

   def InverseCDF(x, mu, sigma):
      return mu + sigma * special.erfinv(2*x + 1)

The problem here is that erfinv is only defined from (-1,1) and the argument is now greater than 1. I have tried scaling this and flipping in all sorts of ways, putting negatives almost everywhere I can, and I can never seem to generate a histogram that follows an upside-down gaussian. In most cases, I actually get back a regular gaussian distribution.

Any idea what I'm doing wrong, or any tips on how to generate this upside-down gaussian? Thanks in advance for any help.

1 Answers

OK, with x between 0 and 1, I get this for the cdf:

-(sqrt(%pi)*(sqrt(2)*sigma*erf((sqrt(2)*x-sqrt(2)*mu)/(2*sigma))
            +sqrt(2)*erf(mu/(sqrt(2)*sigma))*sigma)
 -2*x)
 /(sqrt(%pi)*(sqrt(2)*erf((sqrt(2)*mu-sqrt(2))/(2*sigma))
             -sqrt(2)*erf(mu/(sqrt(2)*sigma)))*sigma
  +2)

Maybe some algebra will make it possible to figure out a formula for the inverse, if not, I guess a numerical root search will work. I guess it will be simpler for specific values of mu and sigma.

I did that with Maxima (http://maxima.sourceforge.net), by constructing the pdf and integrating it. Plotting the expression above yields a plausible picture.

Related