Exp random sample

18 views
Skip to first unread message

Gyanendra Pokharel

unread,
Feb 22, 2012, 9:57:48 PM2/22/12
to gg...@googlegroups.com
Hi,
I want to get random sample from the exponential distribution exp(10^5). I made following function 

real function logprior(z)
 real :: z, logprior
  if(z < 0)then
    logprior = 0.0
    if(z >= 0.0) then
      logprior =(1/(10.00**5)) * exp(-z/(10.00**5))
     logprior = log(logprior)
  endif
 endif
end function logprior

But it returns zero values.

Can some one suggest why it is not working and how how it works?
GP

Robert Miles

unread,
May 21, 2012, 12:06:46 AM5/21/12
to gg...@googlegroups.com
Have you tried steeping through the code with z set to 0.0?
Does it give the result you want?

Larry Baker

unread,
May 21, 2012, 12:27:35 AM5/21/12
to gg...@googlegroups.com
I thin your conditional should not be nested.  You probably want code like this:

    if ( z >= 0.0 ) then
      logprior = ( 1/(10.00**5) ) * exp( -z/(10.00**5) )
      logprior = log( logprior )
    else
      logprior = 0.0
    end if

This handles the case of z<0 and z=NaN or +-Inf in the else clause.

Larry Baker
US Geological Survey




--
You received this message because you are subscribed to the Google Groups "gg95" group.
To view this discussion on the web visit https://groups.google.com/d/msg/gg95/-/fG6m_NE6xkwJ.
To post to this group, send email to gg...@googlegroups.com.
To unsubscribe from this group, send email to gg95+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gg95?hl=en.

Reply all
Reply to author
Forward
0 new messages