Random variable from truncated gumbel distribution

Hi there. What would be the easiest way to generate random variables following Truncated Gumbel Distribution in Gauss? For example, gumbel distribution with upper bound.

Thanks.

Huihui

1 Answer



0



Below is a function that calculates the inverse truncated Gumbel distribution.

proc (1) = cdfGumbelTruncInv(p, a, b);
   local tmp, x, index, size;
   tmp = exp(-exp(b./a));
   x = -a .* ln(-ln((1-tmp) .* p + tmp)) + b;
    
   //check for p == 1
   index = indexcat(p, (1-__macheps)|__infp);
   if not scalmiss(index);
      if rows(p) == 1;
         size = maxc(rows(a)|rows(b));
         retp(reshape(__infp, size, 1));
       endif;
       x[index] = __infp;
   endif;
   //check for p == 0
   index = indexcat(p, __infn|(0+__macheps));
   if not scalmiss(index);
      if rows(p) == 1;
         size = maxc(rows(a)|rows(b));
         retp(zeros(size, 1));
      endif;
      x[index] = 0;
   endif;
   retp(x);
endp;

By passing uniform random numbers into this function you should get random numbers with the truncated Gumbel distribution.

r = rndu(100, 1);
r_gumbel = cdfGumbelTruncInv(r, 1, 1);

Your Answer

1 Answer

0

Below is a function that calculates the inverse truncated Gumbel distribution.

proc (1) = cdfGumbelTruncInv(p, a, b);
   local tmp, x, index, size;
   tmp = exp(-exp(b./a));
   x = -a .* ln(-ln((1-tmp) .* p + tmp)) + b;
    
   //check for p == 1
   index = indexcat(p, (1-__macheps)|__infp);
   if not scalmiss(index);
      if rows(p) == 1;
         size = maxc(rows(a)|rows(b));
         retp(reshape(__infp, size, 1));
       endif;
       x[index] = __infp;
   endif;
   //check for p == 0
   index = indexcat(p, __infn|(0+__macheps));
   if not scalmiss(index);
      if rows(p) == 1;
         size = maxc(rows(a)|rows(b));
         retp(zeros(size, 1));
      endif;
      x[index] = 0;
   endif;
   retp(x);
endp;

By passing uniform random numbers into this function you should get random numbers with the truncated Gumbel distribution.

r = rndu(100, 1);
r_gumbel = cdfGumbelTruncInv(r, 1, 1);

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.