Search code examples
netlogoprobabilityagentprobability-distribution

Multiple mutually exclusive events and probabilities in netlogo


consider the following 5 events that can occur in netlogo,

[a b c d e f] Each event has a specific probability of occurring. Say [0 0 0.3 0.5 0.1 0.1], that is, p(a) = 0, p(b) = 0, p (d) = 0.5

One (and only one event)must occur . How do I model it in Netlogo.

What i did:

ask turtles 
[
 if random-float 1 < 0
[EventA]
if random-float 1 < 0.5
[EventD] ; and so on 


]

But with this approach, sometimes no event will occur or sometimes more than 1.


Solution

  • Short answer: This is a classic use case for "roulette-wheel" selection.

    You can use the NetLogo RND extension to do this, or roll your own following the Lottery example in the model library.

    More:

    The method abstracts the probabilities to weights, so any set of values from a list or from an agentset can be used; the probability of selection is the ratio of the individual value to the sum of all values in the set or list.

    It does not require the set or lists to be sorted, and is scalable to any number of items.

    You can write it to produce either the list index of the selected value, or a related value (like an agent or a value from another list).

    It can be used for both with-replacement and without-replacement selection from the set.

    Without-replacement can be done either by removing individuals from the selection list/set or by setting the selection weight/value of an individual to 0 once it is selected(use a copy of the real values if the selection is repeated.)

    Link to NetLogo RND Extension

    Simple roll-your-own example:

    ;; List weight has values to consider
    ;; Returns the index of the selected item
    To RW-Select [ weight ]
      Let last-index length weight
      Let total sum weight
      Let index 0
      Let cumulative 0
      Let rnd random-float total
      While [cumulative <= rnd and index < last-index] 
      [ 
        Set cumulative cumulative + item index weight
        Set index index + 1
      ]
        Report (index - 1)
    End