Drawing from a truncated exponential distribution

21 views
Skip to first unread message

Colin Lynch

unread,
Aug 2, 2019, 6:28:00 PM8/2/19
to netlogo-users
I am attempting to draw random numbers from a truncated exponential distribution where I would control three free parameters: the expected value of the distribution, and the upper and lower limits of the distribution. After scouring the web, I have been unable to find a truncated exponential function for Netlogo 6.1.0 (I can find rngs:rnd-exponential <stream_id> <mean>  to draw from an regular exponential, but I don't know how to look under the hood of this function to alter it for my own ends). Does anyone know if such a function exists, or if not, does anyone know how to program a custom pdf that I could then draw from? 

Dale Frakes

unread,
Aug 2, 2019, 7:15:51 PM8/2/19
to Colin Lynch, netlogo-users
Colin, does the mean of the resulting distribution need to match the mean of the non-truncated distribution?  If not, you can use "rejection sampling" where you would continue sampling from the non-truncated distribution until you get a value that's within your bounds. 

Here's an example of doing that with a plain normal distribution:

to-report random-normal-bounded [#u #sd #min #max]

  let temp-value random-normal #u #sd
  while [(temp-value < #min) or (temp-value > #max)]
  [
    set temp-value random-normal #u #sd
  ]
  report temp-value

end



On Fri, Aug 2, 2019 at 3:28 PM Colin Lynch <cmly...@asu.edu> wrote:
I am attempting to draw random numbers from a truncated exponential distribution where I would control three free parameters: the expected value of the distribution, and the upper and lower limits of the distribution. After scouring the web, I have been unable to find a truncated exponential function for Netlogo 6.1.0 (I can find rngs:rnd-exponential <stream_id> <mean>  to draw from an regular exponential, but I don't know how to look under the hood of this function to alter it for my own ends). Does anyone know if such a function exists, or if not, does anyone know how to program a custom pdf that I could then draw from? 

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/376179e1-003c-4225-a0fe-f9e5ac04a926%40googlegroups.com.


--
Dale Frakes
Adjunct Instructor, PhD Student
PSU Systems Science

Adam MacKenzie

unread,
Aug 2, 2019, 7:54:34 PM8/2/19
to netlogo-users, Colin Lynch
Colin-

I think Dale's approach is straightforward and should get you what you're looking for, pending your intent on the construction of the distribution.

Regarding the code itself:  I leveraged the Colt library in a pretty straightforward fashion for the extension.  Their definition via API documentation for this distribution is at: https://dst.lbl.gov/ACSSoftware/colt/api/cern/jet/random/Exponential.html and the top page where you can snag all the documentation/download their libraries is at https://dst.lbl.gov/ACSSoftware/colt/


Mac

On Friday, August 2, 2019, 06:28:08 PM EDT, Colin Lynch <cmly...@asu.edu> wrote:


I am attempting to draw random numbers from a truncated exponential distribution where I would control three free parameters: the expected value of the distribution, and the upper and lower limits of the distribution. After scouring the web, I have been unable to find a truncated exponential function for Netlogo 6.1.0 (I can find rngs:rnd-exponential <stream_id> <mean>  to draw from an regular exponential, but I don't know how to look under the hood of this function to alter it for my own ends). Does anyone know if such a function exists, or if not, does anyone know how to program a custom pdf that I could then draw from? 

--

Colin Lynch

unread,
Aug 4, 2019, 5:55:49 PM8/4/19
to netlogo-users
Dear Dale,

Alas, the mean of the resulting distribution does need to match the mean of the non-truncated distribution. I've tried playing around with ways of adjusting the upper and lower bounds of the acceptable distribution range, but I can't seem to tweek them in such a way that the means stay consistent. Do you happen to know of a way to do this? 


On Friday, August 2, 2019 at 4:15:51 PM UTC-7, Dale Frakes wrote:
Colin, does the mean of the resulting distribution need to match the mean of the non-truncated distribution?  If not, you can use "rejection sampling" where you would continue sampling from the non-truncated distribution until you get a value that's within your bounds. 

Here's an example of doing that with a plain normal distribution:

to-report random-normal-bounded [#u #sd #min #max]

  let temp-value random-normal #u #sd
  while [(temp-value < #min) or (temp-value > #max)]
  [
    set temp-value random-normal #u #sd
  ]
  report temp-value

end



On Fri, Aug 2, 2019 at 3:28 PM Colin Lynch <cmly...@asu.edu> wrote:
I am attempting to draw random numbers from a truncated exponential distribution where I would control three free parameters: the expected value of the distribution, and the upper and lower limits of the distribution. After scouring the web, I have been unable to find a truncated exponential function for Netlogo 6.1.0 (I can find rngs:rnd-exponential <stream_id> <mean>  to draw from an regular exponential, but I don't know how to look under the hood of this function to alter it for my own ends). Does anyone know if such a function exists, or if not, does anyone know how to program a custom pdf that I could then draw from? 

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlog...@googlegroups.com.

Dale Frakes

unread,
Aug 4, 2019, 6:45:57 PM8/4/19
to netlog...@googlegroups.com
Colin,

probability theory is not one of my strengths, so I'd have to approach this using a kind of brute-force method.

Generally, you have a set of bounds, you could experiment by specifying a range of means for the random-exponential, and if you do enough of each value, you can calculate the mean of the resulting data set and get kind of a mapping between "incoming means" (supplied to the function) and outcoming means (that come out of repeated calls to the function). 

I did something like this in the following R code:

First, a function to give me a bounded exponential (note R's rexp uses a rate, where rate = 1/mean):

rexp_truncated <- function(emean, lowerlimit, upperlimit) {

  tmp <- rexp(n = 1, rate = 1/emean)
  while (tmp < lowerlimit | tmp > upperlimit) {
    tmp <- rexp(n  = 1, rate = 1/emean)
  }
  return (tmp)
}

Then I did some loops (probably quite inefficient) to sweep the values of "incoming-mean" and lower/upper bounds:

n <- 10000

df <- NULL

for(emean in seq(from = 2, to = 5, by = 0.5)) {
  for (lowerlimit in seq(from = .5, to = 1, by = 0.1)) {
    for (upperlimit in seq(from = 10, to = 15, by = 1)) {
      tmp <- c(emean, lowerlimit, upperlimit,
        mean(replicate(n = n, rexp_truncated(emean = emean, lowerlimit = lowerlimit, upperlimit = upperlimit)))
      )
      df <- rbind(df, tmp)
     
    }
  }
}

colnames(df) <- c("incoming-mean", "lowerlimit", "upperlimit", "estimated-mean")


And this will give an output something like this:



If "n" is large enough, these "estimated-mean"/out-coming values are pretty stable... but if the limits are too close to the incoming-mean, it can take a long time for rejection-sampling to get all the values...

So here, let's say (conveniently - because it happened to be in my table) I want the resulting mean to be 2.5, and my lower limit is 0.5 and upper limit is 15.  That means I'd need to supply the truncated-exponential function a mean of 2.

You might need to work that backwards using an optimization technique so that you can provide the estimated-mean and the bounds and get the "incoming mean" needed given those bounds.  Though somebody better versed in calculus of probability distributions could probably develop a similar mapping function analytically, but that wouldn't be me!

Note that even if you can get the means to match this way, the variance of the truncated distribution probably cannot be made to also match.

I hope that helps!

Dale
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/64fe5aa5-f0e1-4c83-8dc0-552fd42dc2cf%40googlegroups.com.

-- 
Dale Frakes
Adjunct Instructor, PhD Candidate
PSU Systems Science
dfr...@pdx.edu - http://web.pdx.edu/~dfrakes/
Reply all
Reply to author
Forward
0 new messages