randomnetlogodistributionexponential-distribution

It is possible to create an exponential distribution in netlogo with maximum and minimum values?


Suppose I have X patches, and patches have a patch variable called "patch-quality", with values between 0 and 1. I want to generate a random number between 0 and 1 for that variable following an exponential distribution.

When you set up an exponential distribution in NetLogo, you need a mean:

random-exponential mean

The mean of my exponential distribution is 0.13 (I want most patches to be close to 0 quality).

set patch-quality random-exponential 0.13

The problem is that, sometimes, I got few patches with patch-quality above 1.

Is there a way to generate an exponential distribution in NetLogo that wouldn't generate patches with patch-quality above 1?


Solution

  • A few months back, I was struggling with this exact problem.

    An exponential distribution by nature does not have an upper limit so this can't be done. You could however use a truncated exponential distribution that follows the exact shape of an exponential distribution between its upper and lower bound. One of the results of this is that the mean of your truncated exponential distribution is NOT the same as the mean of your exponential distribution on which it is based.

    Creating a truncated exponential distribution is quite easy. You assign a random number to each patch depending on the exponential distribution. Then you check whether or not that number is within the bounds you set. If it is not, you take a new number until it is.

      let exp-mean 0.13
      ask patches [
        set baseline-quality random-exponential exp-mean
        while [baseline-quality > 1] [set baseline-quality random-exponential exp-mean
      ]