Ehrenfest Urn Model

Ehrenfest Urn Model preview image

1 collaborator

Default-person Do Trong Thanh (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 559 times • Downloaded 36 times • Run 0 times
Download the 'Ehrenfest Urn Model' 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

;;;;;;;;;;;;;;;;;;;;;;
;; setup procedures ;;
;;;;;;;;;;;;;;;;;;;;;;

globals
[
  prob
  ratio ;; ratio between number of balls in urn A and total number of balls
  urnA ;; number of balls in urn A
  sum-ratio
  sum-ratio-square
  mean-ratio
  mean-ratio-square
  var
]

;; sets up the patches and creates turtles

to setup
  clear-all
  ask patches [ set pcolor gray + 3 ]
  
  crt 1
  [
    set color black
    set shape "dot"
    set pen-size 3
    setxy 0 0
    set heading 0
    pd
    forward 50
    die
  ]
  init-vars
  setup-turtles
  reset-ticks
end 

to init-vars
  set ratio (ratio-two-urns / (1 + ratio-two-urns))
  set urnA (number-of-particles * ratio)
  set sum-ratio 0
  set sum-ratio-square 0
end 

;; determines the number of turtles and their color

to setup-turtles
  create-turtles urnA
  [
    set size 2
    set shape "dot"
    set ycor (random-float 50)
    set xcor (- (random-float 24)) - 1
    set color blue
  ]
  create-turtles (number-of-particles - urnA)
  [
    set size 2
    set shape "dot"
    set ycor (random-float 50)
    set xcor (random-float 24) + 1
    set color red
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;
;; runtime procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;;

to go
  ask one-of turtles
  [
     ifelse (color = blue)
     [
       set color red
       set xcor (random-float 24) + 1
     ]
     [ 
       set color blue
       set xcor (- (random-float 24)) - 1
     ]
  ]
  set urnA (count turtles with [color = blue])
  set ratio (urnA / number-of-particles)
  tick
end 

There is only one version of this model, created over 10 years ago by Do Trong Thanh.

Attached files

File Type Description Last updated
Ehrenfest Urn Model.png preview Preview for 'Ehrenfest Urn Model' over 10 years ago, by Do Trong Thanh Download

This model does not have any ancestors.

This model does not have any descendants.