Markov Chain example

Markov Chain example preview image

1 collaborator

Default-person benjamin davies (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.5 • Viewed 979 times • Downloaded 65 times • Run 0 times
Download the 'Markov Chain example' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

;;Markov model by Ben Davies
;;For more information see https://simulatingcomplexity.wordpress.com/2015/02/10/fun-with-markov-chains-a-tutorial-using-netlogo/

globals [ weather ]

patches-own [ growth ]

;;clear the model, create weather variable with two states: wet or dry
;;seed patches with random growth and scale their colour accordingly

to setup
  clear-all
  set weather one-of [ "WET" "DRY" ]
  ask patches [
    set growth random 11
    set pcolor scale-color green growth 10 0
  ]
  reset-ticks
end 

to go
  markov-rain
  grow-grass
  tick
  if ticks = 500 [ stop ]
end 

;;if the weather is currently wet AND a randomly drawn value between 0 and 1 is less 
;;than the wet-to-dry transition, transition to dry conditions
;;ELSE
;;if the weather is currently dry AND a randomly drawn value between 0 and 1 is less 
;;than the wet-to-dry transition, transition to wet conditions

to markov-rain
  ifelse weather = "WET" [
    if random-float 1.000 < WTD [
      set weather "DRY"
    ]
  ]
  [
    if random-float 1.000 < DTW [
      set weather "WET"
    ]
  ]
end 

;;if conditions are wet AND grass is not at its maximum, grow grass and recolor patches
;;ELSE
;;if conditions are dry AND grass is not at its minimum, decrease grass and recolor patches

to grow-grass 
  ifelse weather = "WET" [
    ask patches with [ growth < 10 ] [
      set growth growth + 1
      set pcolor scale-color green growth 10 0
    ]
  ]
  [
    ask patches with [ growth > 0 ] [
      set growth growth - 1
      set pcolor scale-color green growth 10 0
    ]
  ]
end 

There is only one version of this model, created over 8 years ago by benjamin davies.

Attached files

File Type Description Last updated
Markov Chain example.png preview Preview for 'Markov Chain example' over 8 years ago, by benjamin davies Download

This model does not have any ancestors.

This model does not have any descendants.