Histo Blocks

Histo Blocks preview image

3 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Josh3 Josh Unterman (Author)
Dor Abrahamson (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 292 times • Downloaded 56 times • Run 0 times
Download the 'Histo Blocks' 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 is a part of the ProbLab curriculum. The ProbLab Curriculum is currently under development at the Embodied Design Research Laboratory (EDRL), University of California, Berkeley. For more information about the ProbLab Curriculum please refer to http://ccl.northwestern.edu/curriculum/ProbLab/.

Histo-Blocks is a model for exploring the binomial function. The random generator is a "4-Block," a 2-by-2 matrix, in which each of the four squares independently can be either green or blue. The 4-Block is thus just like four coins that each can land either on heads or tails, only that here you can easily adjust the collective chance of these four independent singleton events. For instance, you could adjust the model so that it will behave like four coins that each has a .6 chance of landing on heads. The model shows connections between the random generator's sample space, probabilities of its singleton events, its expected outcome distribution, and the binomial function.

(This model is on theoretical probability only -- not empirical probability -- so there is no simulated experiment here.)

HOW IT WORKS

The View displays the 16 unique elemental events of the green/blue 4-Block, arranged in five columns by the number of green squares in each permutation (0 through 4). Labels on each of the singleton green squares show the current p value, and labels on the blue blocks show the complementary (1 - p) value. The p value can be changed using a slider that is below the View. When you click and hold the mouse button over a column in the View, three monitors to the left of the View display information: the number of blocks in that column (n-choose-k), the compound probability of each of the blocks in that column (the product of the probabilities of the four independent singleton events), and the product of these two latter components. This product -- the number of blocks in a column multiplied by the probability of each block in the column -- represents the chance of randomly getting any one of the blocks in that column, when you operate the random generator (that is, the chance of getting the combination regardless of the particular permutation). For example, the chance of getting any 4-Block with exactly 1 green is the same as the chance of getting exactly one heads when you toss four coins.

The plot shows a special histogram, in which each column is partitioned equally into as many parts as there are blocks in its corresponding View column, below. For example, the "2" column in the histogram in partitioned into 6 equal segments, because there are 6 unique 4-blocks that have two green squares in the block. Whereas the blocks are equal in height within the columns, they differ in height between columns (for p values other than .5). The relative heights index the compound probability. So the histogram blocks -- the "histo-blocks" -- feature both factors at play in the binomial function: the n-choose-k coefficients are represented by the number of blocks in the column, and p^k * (1 - p)^(n - k) is represented by these blocks' individual heights.

HOW TO USE IT

Press on SETUP, then GO. Now, grab the slider and change the p value.

Buttons: SETUP builds the "combinations tower" in the View. GO enables the functioning of clicking on the screen and of the slider.

Switch: PLOT-INDIVIDUAL-BLOCKS? toggles between having or not having the histogram partitioned. AUTO-ADJUST-Y-AXIS? when set to 'On,' the histogram will keep adjusting for new p values so that the tallest column reaches to the top. When off, the max y value is 1.

Sliders: P sets the p value.

Monitors: When you click and hold down the mouse button over a given column in the view, the NUMBER OF ITEMS IN THIS COLUMN, PROBABILITY OF EACH ITEM IN THIS COLUMN, and N-CHOOSE K * COMPOUND P monitors update to provide information about that column.

THINGS TO NOTICE

Note the probability values appearing in little labels on the squares. Also note the shape of the histogram. Both the labels and histogram change with p.

THINGS TO TRY

Set the p value (on the slider) to .6. Looking at the plot, what is special about this p value? Can you find other p values that give this same effect? With p set to .6, click anywhere on the middle column (2-green column). Observe the monitors. Now, with the mouse still down, drag the mouse one column to the right. What happened in the monitors?

Set the auto-adjust-y-axis? to 'Off,' and slide the p value. Look at the histogram as you do this. What is happening to the histogram? -- What is changing?; What is not changing? What does this mean, in terms of the probabilities?

EXTENDING THE MODEL

Add empirical functions to the model: create another histogram that shows actual outcomes of a simulated probability experiment with a 4-block (a sample of 4 independent events that each take on one of two possible values). Place this new histogram on the interface such that it will readily compare to the histo-block histogram. You can partition this histogram, too, according to sub-groups in the outcomes.

NETLOGO FEATURES

This model uses a special procedure in order to partition the histogram columns.

RELATED MODELS

Several of ProbLab's models are related to Histo Blocks, notably Sample Stalagmite.

CREDITS AND REFERENCES

Thanks to Dor Abrahamson for his work on the design of this model and the ProbLab curriculum. Thank you to Josh Unterman for his talent and work on producing this model.

HOW TO CITE

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

  • Abrahamson, D. and Wilensky, U. (2009). NetLogo Histo Blocks model. http://ccl.northwestern.edu/netlogo/models/HistoBlocks. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE

Copyright 2009 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

Comments and Questions

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

Click to Run Model

globals [
  unordered-probabilities
  num-orderings
  expected-results

  number-of-items-in-column-text
  probability-of-items-in-column-text
  number-of-items-in-column
  probability-of-items-in-column
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca reset-ticks
  set-plot-x-range 0 5
  setup-view
  set number-of-items-in-column-text "-"
  set probability-of-items-in-column-text "-"
  set number-of-items-in-column "-"
  set probability-of-items-in-column "-"
  go
end 

to setup-view
  ask patches with [pcolor = black] [set pcolor grey + 1]
  update-unordered-probabilities
  update-num-orderings
  let active-x min-x
  let active-y round min-pycor
  let delta-y round (world-height / 5)
  let possibility-index 0
  foreach n-values 5 [?] [
    foreach n-values item ? num-orderings [?] [
      ask patch active-x active-y [
        let current-4-block item possibility-index all-possibilities
        ask patch-at 0 1 [
          sprout 1 [
            set shape "bordered-square"
            ifelse item 0 current-4-block = 1 [
              set color green
            ] [
              set color blue
            ]
          ]
        ]
        ask patch-at 1 1 [
          sprout 1 [
            set shape "bordered-square"
            ifelse item 1 current-4-block = 1 [
              set color green
            ] [
              set color blue
            ]
          ]
        ]
        ask patch-at 0 0 [
          sprout 1 [
            set shape "bordered-square"
            ifelse item 2 current-4-block = 1 [
              set color green
            ] [
              set color blue
            ]
          ]
        ]
        ask patch-at 1 0 [
          sprout 1 [
            set shape "bordered-square"
            ifelse item 3 current-4-block = 1 [
              set color green
            ] [
              set color blue
            ]
          ]
        ]
      ]
      set active-y active-y + delta-y
      set possibility-index possibility-index + 1
    ]
    set active-y min-pycor
    set active-x active-x + delta-x
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  every .1 [
    handle-mouse
  ]
  update-unordered-probabilities
  update-num-orderings
  set expected-results (map [?1 * ?2] unordered-probabilities num-orderings)
  update-plot
  ask turtles [
    ifelse color = green [
      set label precision p 2
    ] [
      set label precision (1 - p) 2
    ]
    if length (word label) = 3 [ set label word label "0" ] ;; force to 2 decimal places
    if length (word label) = 1 [ set label word label ".00" ] ;; force to 2 decimal places
  ]

  tick
end 

to handle-mouse
  ifelse mouse-down? [
    let column round ((mouse-xcor - min-x) / delta-x)
    if column < 0 [ set column 0 ]
    if column > 4 [ set column 4 ]
    set number-of-items-in-column-text num-items-in-column column
    set probability-of-items-in-column-text chance-of-each-item-in-column column
    set number-of-items-in-column item column num-orderings
    set probability-of-items-in-column item column unordered-probabilities
  ] [
    set number-of-items-in-column-text "-"
    set probability-of-items-in-column-text  "-"
  set number-of-items-in-column "-"
  set probability-of-items-in-column "-"
  ]
end 

to update-unordered-probabilities
  set unordered-probabilities n-values 5 [
    column-prob 4 ?
  ]
end 

to update-num-orderings
  set num-orderings n-values 5 [
    choose 4 ?
  ]
end 

to-report column-prob [n c]
  let result 1
  repeat c [
    set result result * p
  ]
  repeat (n - c) [
    set result result * (1 - p)
  ]
  report result
end 

to-report choose [n c]
  report ((factorial n)/((factorial c) * (factorial (n - c))))
end 

to-report factorial [n]
  report ifelse-value (n = 0) [
    1
  ] [
    n * factorial (n - 1)
  ]
end 

to update-plot
  plot-pen-reset
  let max-expected-result max expected-results
  ifelse auto-adjust-y-axis? [
    set-plot-y-range 0 precision ((max-expected-result * 1000 + 10) / 1000)  3
  ] [
    set-plot-y-range 0 1
  ]
  ifelse plot-individual-blocks? [
    let greenness 0
    (foreach expected-results num-orderings [
      let per-block ?1 / ?2
      let value-to-plot per-block
      repeat ?2 [
        plotxy greenness value-to-plot
        set value-to-plot value-to-plot + per-block
      ]
      set greenness greenness + 1
    ])
  ] [
    foreach expected-results [
      plot ?
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;
;; monitor work is below
;;;;;;;;;;;;;;;;;;;;;;;;

to-report num-items-in-column [index]
  report (word 4 "-choose-" index " = " item index num-orderings)
end 

to-report chance-of-each-item-in-column [index]
  let result ""
  foreach n-values 4 [?] [
    if ? > 0 [
      set result word result " * "
    ]
    ifelse ? < index [
      set result (word result precision p 2)
    ] [
      set result (word result precision (1 - p) 2)
    ]
  ]
  report (word result " ~= " (precision item index unordered-probabilities 4))
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Reporter Procedures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report min-x
  report round (2 * min-pxcor / 3) - 1
end 

to-report delta-x
  report round (world-width / 6)
end 

;; all possible 4-blocks

to-report all-possibilities
  report (list
    [0 0 0 0]

    [0 0 0 1]
    [0 0 1 0]
    [0 1 0 0]
    [1 0 0 0]

    [0 0 1 1]
    [0 1 0 1]
    [0 1 1 0]
    [1 0 0 1]
    [1 0 1 0]
    [1 1 0 0]

    [0 1 1 1]
    [1 0 1 1]
    [1 1 0 1]
    [1 1 1 0]

    [1 1 1 1]
  )
end 


; Copyright 2009 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Histo Blocks Download this version

Attached files

File Type Description Last updated
Histo Blocks.png preview Preview for 'Histo Blocks' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.