Modalizing Mechanisms

Modalizing Mechanisms preview image

1 collaborator

Default-person Manolo Martínez (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.1.0 • Viewed 326 times • Downloaded 27 times • Run 0 times
Download the 'Modalizing Mechanisms' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This model shows how bet hedging in the presence of exponentially diminishing returns leads a population of agents to become sensitive to the probability with which a certain Bernoulli process occurs.

The model is discussed in my paper 'Modalizing Mechanisms' (forthcoming at the Journal of Philosophy).

HOW IT WORKS

Hunters (represented by orange squares in the View) hunt for monsters (represented as triangles). Monsters are born in an inchoate stage (yellow triangles) and then, after a number of ticks given by monster-starting-energy (default: 5) they evolve, with probabilities given by prob-air and 1 - prob-air, to air monsters (red triangles) or sea monsters (blue). If they are not hunted down, after another monster-starting-energy ticks, they die, and an inchoate monster is hatched in their stead at a random location. The initial population of monsters is given by number-of-monsters, default: 50.

Hunters (the initial population is given by number-of-hunters, default: 50) watch out for monsters (how far they can see is given by hunter-radius, default: 20) and when they see one they hunt it. The hunting process is described in the paper referred to above. The payoff of a hunt is added to the hunter's energy. Each hunter starts their life with hunter-starting-energy energy units (default: 100). With each tick they lose 1 energy unit. When they reach 0, they die, but if they reach hunter-reproducing-energy (default: 150), they hatch a new hunter, which appears at a random location. The newly hatched hunter has, most of the time, the same strategy as their parent, but, sometimes (the probability is given by mutation-probability, default: 0.1), they have a mutated strategy. Mutation works as follows:

  • Most of the time, the mutated strategy is a perturbation of the old one. The perturbation works by adding random noise in a prefixed proportion (given by mutation-mix, default: 0.2) and renormalizing.

  • Sometimes, the mutated strategy is a completely random one. The probability of a perturbation (as opposed to a wholly new mutation) is given by mutation-mix. In fact, the default for this parameter (the one used in the paper referred to above) is 1. This means that, in the simulations discussed in the paper, mutation was always perturbation of the parent strategy.

The way in which hunters reproduce is designed to provide a discrete analogue of the replicator-mutator dynamics: better performing hunters will reproduce more often, sometimes atching mutated offspring.

HOW TO USE IT

The SETUP button creates an initial arrangement of monsters and hunters. The GO button starts a simulation, which will then run until the GO button is pressed again, or until the number of hunters in a population has stabilized. That is, every 10k ticks, the mean number of hunters in the previous 10k ticks is calculated, and compared with the mean number of hunters in the previous 10k snapshot. That is, when the tick counter has reached 10k, with compare the mean number of hunters in the first 10k ticks with 0; then, when the tick counter reaches 20k, we compare the mean number of hunters from 10k + 1 to 20k with the mean number of hunters at 10k, etc. When this mean stops growing, the simulation stops.

The rationale behind this behavior is this: monsters act as a fixed resource (their population doesn't increase, nor decrease), so the more hunters there are, the more fitness they have and, consequently, the better their strategy is. When the mean population count reaches a plateau (stops growing) this indicates that they have reached a local optimum. This procedure is not extremely precise; suggestions for improvement are welcome!

THINGS TO NOTICE

Note how, while the count of hunters grows asymptotically with time, the mean investment policy has a less smooth development. This is probably because the mean hunter strategy (which is a matrix, and thus hard to plot) is more important in the initial stages than the investment policy, which only later becomes crucial. But I'm not sure about this; suggestions are also welcome here!

THINGS TO TRY

The paper, and the model as it is set up, assume exponentially diminishing returns on investment. This is hardcoded in the investment-to-payoff function in utils.nls. You can change the return on investment to a linear one by using investment-to-payoff-linear instead of investment-to-payoff-inv-exp in investment-to-payoff.

You will see that hunters simply resort to a step function, investing everything in the eventuality of an air attack whenever prob-air > 0.5.

The for-paper BehaviorSpace experiment should provide you with a set of data very similar to the one depicted in Figure 3 of the paper referred to above.

EXTENDING THE MODEL

It would be interesting to see what happens if hunters had to deal with monsters evolving to n varieties, for n > 2.

CREDITS AND REFERENCES

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

  • Martinez, M. (forthcoming). Modalizing Mechanisms, Journal of Philosophy
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE

Copyright 2015 Manolo Martínez.

This model is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Financial support for this work was provided by the DGI, Spanish Government, research project FFI2011-26853, and Consolider-Ingenio project CSD2009-00056.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;;This file is part of the Modalizing Mechanisms model.
;;
;;the Modalizing Mechanisms model is free software: you can redistribute it and/or modify
;;it under the terms of the GNU General Public License as published by
;;the Free Software Foundation, either version 3 of the License, or
;;(at your option) any later version.
;;the Modalizing Mechanisms model is distributed in the hope that it will be useful,
;;but WITHOUT ANY WARRANTY; without even the implied warranty of
;;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;GNU General Public License for more details.
;;
;;You should have received a copy of the GNU General Public License
;;along with the Modalizing Mechanisms model.  If not, see .

extensions [matrix]

__includes ["utils.nls"]

breed [monsters monster]
breed [hunters hunter]

globals [should-stop old-number-of-hunters hunters-list states messages acts hunter-pure-strats]

turtles-own [energy huntstage]
monsters-own [monstertype myhunter stagecolors]
hunters-own [mymonster strategy investmentpolicy]

to setup
  clear-all
  initialize-utils
  initialize-monsters
  initialize-hunters
  reset-ticks
end 

to initialize-monsters
 create-monsters number-of-monsters [
    set stagecolors [yellow red blue]
    set energy monster-starting-energy
    set monstertype random 3
    set color item monstertype stagecolors
    set huntstage 0
    set myhunter nobody
    setxy random-xcor random-ycor]
end 

to initialize-hunters
 create-hunters number-of-hunters [
    set energy hunter-starting-energy
    set strategy random-hunter-strat
    ;; set strategy matrix:make-identity 3
    set investmentpolicy random-hunter-investment-policy
    set shape "square"
    set color orange
    set huntstage 0
    set mymonster nobody
    setxy random-xcor random-ycor]
end 

to go
  check-progress
  if should-stop [
    stop
  ]
  monsters-go
  hunters-go
  tick
end 

to check-progress
  ;; calculates an average of the number of hunters over the last 10000 ticks. It it doesn't grow, we stop
  set hunters-list lput count hunters hunters-list
  if ticks / 10000 = floor (ticks / 10000) [
    let new-number-of-hunters mean hunters-list
    set hunters-list []
    if old-number-of-hunters >= new-number-of-hunters [
      set should-stop true
    ]
    set old-number-of-hunters new-number-of-hunters
  ]
end 

to monsters-go
  monsters-time-passes  
end 

to hunters-go
  hunters-find-monster
  hunters-hunt
  hunters-time-passes
end 

to monsters-time-passes
  ask monsters [
    set energy energy - 1
    if energy <= 0 [
      if-else monstertype = 0 [
        set monstertype (weighted-random-choice list prob-air (1 - prob-air)) + 1
        set energy monster-starting-energy
        set color item monstertype stagecolors
      ]
      [
        if huntstage > 0 [
          ;; show mysender
          dismantle-hunt self myhunter
        ]
        monster-die self  
      ]
    ]
  ]
end 

to monster-die [thismonster]
  ask thismonster [
    hatch 1 [
    set color yellow
    set monstertype 0       
    set energy monster-starting-energy
    setxy random-xcor random-ycor
    ]
    die
  ]
end 

to hunters-time-passes
  ask hunters [
    set energy energy - 1
    if energy <= 0 [
      if huntstage > 0 [
      dismantle-hunt mymonster self
      ]
      die
    ]
    if energy >= hunter-reproducing-energy [
        hatch 1 [
          set energy ([ energy ] of myself) / 2
          setxy random-xcor random-ycor
          if random-float 1 < mutation-probability [
            if-else random-float 1 < mutation-mix [
              set strategy perturb-matrix perturbation-ratio [ strategy ] of myself
              set investmentpolicy perturb-vector perturbation-ratio [ investmentpolicy ] of myself
            ] [
              set strategy random-hunter-strat
              set investmentpolicy random-hunter-investment-policy
            ]
          ]
        ]
        set energy energy / 2
    ]
  ]
end 

to hunters-find-monster
  ask hunters [
    if mymonster = nobody [
      let nearby-idle-monsters monsters in-radius hunter-radius with [myhunter = nobody]
      set mymonster one-of nearby-idle-monsters
      if mymonster != nobody [
        ;; show "found a monster"
        ask mymonster [ set myhunter myself ]
        ask (turtle-set self mymonster) [set huntstage 1 ]
      ]
    ]
  ]
end 

to hunters-hunt
  ask hunters [
    if-else huntstage = 0
      [ stop ]
      [if mymonster = nobody [
        dismantle-hunt mymonster self
        ;; show "i'm outta here"
        relocate self
        stop
      ]
    ]
    if huntstage = 1 [ first-round mymonster self ]
    if huntstage = 2 [ second-round mymonster self ]
  ]
end 

to first-round [monster hunter]
  ;; show "first round"
  let act get-act monster hunter
  if-else act > 0 or [monstertype] of monster > 0 [
    let payoff unprepared-attack [monstertype] of monster act
    ;; show "1st round payoff"
    ;; show payoff
    ask hunter [ set energy (energy + payoff) ]
    dismantle-hunt monster hunter
    monster-die monster
    relocate hunter
  ] [
    ask (turtle-set hunter monster) [ set huntstage 2 ]
  ]
end 

to second-round [monster hunter]
  ;; show "second round"
  ;; show [ monstertype ] of monster
  if ([ monstertype ] of monster) > 0 [
    let act get-act monster hunter
    let policy [ investmentpolicy] of hunter
    let payoff prepared-attack [monstertype] of monster act policy
    ;; show payoff
    ask hunter [ set energy (energy + payoff) ]
    dismantle-hunt monster hunter
    monster-die monster
    relocate hunter
  ]
end 

to-report unprepared-attack [thismonstertype act]
  if thismonstertype = 0 [ report energy-of-undecided ]
  if-else thismonstertype = act
    [ report 10 ]
    [ report investment-to-payoff 0 ]
end 

to-report prepared-attack [thismonstertype act policy]
  ;; show "prepared attack"
  if-else thismonstertype = act [
    let investment item (act - 1) policy
    report (investment-to-payoff investment) - 1
  ] [
    report -1
  ]
end 

to dismantle-hunt [monster hunter]
  if monster != nobody [
    ask monster [
      set myhunter nobody
      set huntstage 0
    ]
  ]
  if hunter != nobody [
    ask hunter [
      set mymonster nobody
      set huntstage 0
    ]
  ]
end 

to-report get-act [monster hunter]
  let hunterstrat [strategy] of hunter
  let thismonstertype [monstertype] of monster
  let stratpertype matrix:get-row hunterstrat thismonstertype
  let act weighted-random-choice stratpertype
  report act
end 

to relocate [agent]
  if agent != nobody [
    ask agent [ setxy random-xcor random-ycor ]
  ]
end 

There is only one version of this model, created over 10 years ago by Manolo Martínez.

Attached files

File Type Description Last updated
Modalizing Mechanisms.png preview Preview for 'Modalizing Mechanisms' over 10 years ago, by Manolo Martínez Download

This model does not have any ancestors.

This model does not have any descendants.