Madelon
Madelon

Reputation: 95

NetLogo: dealing with infinity probability in distribution

in netlogo, I select a specific distribution for travel distance based on a random number. Then, based on the selected distribution, I calculate the probability to travel to a number of specific patches at a specific distance. For one of the distributions, the probability approaches infinity around 0. This creates an error when this specific distribution is selected and one of the patches is where the turtle already is (distance = 0). Netlogo will give the error "math operation produced a number too large for NetLogo". Is there a way to get around this error, such as having netlogo use the largest possible number when this error pops up?

The code looks like this:

to create-window
 get_state
 get_parms
  set i 0
  set j 0
  while [i < windowsize]
  [
    set j 0
    while [j < windowsize]
    [
      let dist (sqrt (((item j xlist) - xcor)  ^ 2 + ((item i ylist) - ycor) ^ 2))
      matrix:set window i j ((wshape / wscale) * ((dist / wscale) ^ (wshape - 1)) * exp (-((dist / wscale) ^ wshape))) 
      set j j + 1 
    ]
    set i i + 1
  ]
end


to get_state
   set state random 3 + 1
end


to get_parms 
  if state = 1 [
    set wscale 0.01856659
    set wshape 1.43983152]
  if state = 2 [
    set wscale 0.18418573
    set wshape 0.92631983]
  if state = 3 [
    set wscale 1.07631234
    set wshape 1.78987126]
end

State 2 is the one with the problem (if the distance is 0), but I want to be able to easily change this parameters, so I'd prefer not to use an if function based on the state number or the parameter values..

Upvotes: 2

Views: 842

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30498

You have two options:

1) Modify the code that calculates the probability to not produce the error in the first place, by detecting the zero case and doing something special. (I can't be more specific without knowing what the code looks like.)

2) Wrap the calculation of the probability using the carefully primitive (dictionary entry), trapping the error and preventing it from halting your model.

Also, how can a probability approach infinity? Shouldn't it approach 1.0?

Upvotes: 1

Related Questions