Sample Stalagmite

Sample Stalagmite preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Dor Abrahamson (Author)

Tags

mathematics 

Tagged by Reuven M. Lerner about 11 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 613 times • Downloaded 80 times • Run 0 times
Download the 'Sample Stalagmite' 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?

9-Block Stalagmite draws on and connects several central ideas in the study of probability, both theoretical and empirical: combinatorics, sample space, binomial distributions, and frequency distribution function. In the related curricular material, students use crayons and paper to build the Combinations Tower. The Combinations Tower is a giant bell-shaped histogram of all the 512 different combinations of a 3-by-3 array of squares that can each be either green or blue.

In the tower, these combinations are grouped in columns according to how many green squares there are in each. 9-Block Stalagmite accompanies these curricular activities.

The model generates random samples (with repetitions), counts how many green squares are in each sample, and collects these samples into columns, creating a histogram that grows up like a stalagmite. If enough samples are taken, then the stalagmite approximates a bell curve. When the probability in the model is set at .5, the shape of this histogram resembles the combinations tower. If all repeating samples are removed from this histogram as it grows up, the model eventually exhausts the sample space at each run of the experiment, providing the view allows the tower to grow tall enough.

This model is a part of the ProbLab curriculum. The ProbLab Curriculum is currently under development at the CCL. For more information about the ProbLab Curriculum please refer to http://ccl.northwestern.edu/curriculum/ProbLab/.

HOW IT WORKS

At the top of the view, a square array of "patches" (the NetLogo square agents that don't move) generates green and blue "turtles" (the NetLogo agents that move). These turtles' colors --- whether they are green or blue --- are determined randomly according to probabilities set by the user. For instance, an 80% chance for each turtle to be green (so 20% chance for each turtle to be blue). Next, the model moves this turtle-sample towards the right so that it arrive in a column that matches the number of green turtles in the sample. Lastly, the model moves the sample down along the column and stacks it on top either of the bottom of the column or a previous sample that has already been positioned there. When the turtles stop, they mark their color onto the patches, and then they "die". For each sample that is generated, a larger duplicate appears on the side for the user's viewing convenience.

Note that for a 9-block there are 10 columns in the view. This is because we need a column for all combinations that have 0 greens, a column for 1 green, a column for 2 green, ..., and a columns for 9 green for a total of 10 columns (9 + 1).

HOW TO USE IT

Buttons

'Setup' - prepares the view, including erasing the coloration from a previous run of the experiment.
'Go' - a forever button that runs the experiment according to the values you have set in the sliders.
'Go Once' - a button that runs the experiment only once.

Sliders

'side' - determines the size of the square sample arrays. For instance, for a value of 3, the model will create a 3-by-3 square (9 turtles).
'probability-to-be-target-color' - determines the chance of each turtle in the sample array to be green (or any other color you have set the model to). A value of 50 means that each turtle has an equal chance of being green or blue, a value of 80 means that each turtle has a 80% chance of being green (so each has a 20% chance of being blue).

Switches

'keep-repeats?' - when "Off," each column will have only different combinations with no repetitions; when "On," there will most probably be repetitions in at least some of the columns. (For 2-by-2 samples, there will be very rare cases that the whole sample space will be discovered without repetitions. For 3-by-3 samples, the cases are so rare that you probably won't ever see it!! Actually, how rare are they?..)
'magnify?' - when "On," you get a larger version of the sample on the side. This helps when you're working with very small patch sizes, such as when you want to have very tall columns so as to exhaust the sample space corresponding to the value of 'side,' e.g,. 512 for 'side = 3.'
'stop-at-all-found?' - when "On," each run will end if all the different combinations have been discovered. When "Off," the run will continue until one of the columns reaches the top.

Monitors

'#-target-color' - displays the total number of squares of target-color, e.g., 'green.'
'#-other-color' - displays the total number of squares of other-color, e.g., 'blue.'
'%-target-color' - displays as a percentage the proportion of target-color squares out of all colored squares.
'combinations found' - displays the proportion of the sample space that has been revealed
'?-blocks' shows the square of 'side.' So if 'side' is set to 3, '?-blocks' will show 9. This means that each sample of side 3 has 9 squares.

Plots

'filling-up-sample-space' - plots the total number of combinations that have been discovered as a proportion of the sample space that has been discovered.

How to use it

Set the sliders according to the values you want, press Setup, and then press Go.

Note that once you have pressed Go, changing the slider values would "confuse" the model. Instead, you should un-press Go, wait until the button jumps back up, and only then change the sliders as you wish, press Setup, and then press Go

THINGS TO NOTICE

Setup the model in its default settings ('side' slider set to the value of 3; 'probability' slider set to the value of .5), slow down the model with the speed slider at the top left of the view, and press Go. Note the following: the more green squares there are in the random sample the further to the right the block will move before descending down. See that at the bottom of each column there is a number. This number tells you the type of sample that will be collected in this column. For instance, in the column labeled '2,' samples that have exactly 2 green patches will stop moving to the right and will descend. So, as the columns grow up, note that each sample will descend over a previous sample that has exactly as many green squares. Overall, the columns on the right are greener than the columns on the left. As you shift your gaze from side to side, the color density changes.

Run the model over and over and watch the shape of the colorful histogram that is plotted. Note any consistencies in the shape of this histogram.

THINGS TO TRY

Work in the 'side' = 2 setup. Set 'keep-duplicates?' to Off. How many samples do you need to fill the entire sample space? Does this change according to the settings of 'probability'? If so, why might this be so? If the probability is set at 80%, does it take as many trials to fill the sample space as compared to a setting of 50%? If not, why not?

Setup the model with the 'side' value at 2 and the 'probability' at 70%. Press Setup and then Go. (If you have previously slowed down the model, you're welcome to speed it up now.) Note that the %-target-color tends to 70%. Also note that more sample combinations collect up in the column of 3 green patches than any other column. So '3' is the mode. We have found it interesting and perhaps somewhat confusing to shift between thinking about the 'mode' and thinking about the 'mean.' For instance, if you set the 'probability' to 83%, you might think that 83% of 4 is 3.32 and so the mode should still be '3.' Is it? What is going on here? So for some probability setting, the 3-column will most often get to the top before other columns. For other probability settings, the 4-column wins. Try to determine the probability ranges in which each column "rules." Hint: How many ranges should there be?

Edit the view so that the y-axis value is 260 and the patch size is 1 pixel. Now, if you set up in 'side = 3,' all 512 different 9-blocks will fit in. Try this.

EXTENDING THE MODEL

Add monitors and/or graphs that will feature aspects of the experiments that are difficult to see in the current version. For instance:

  • How many samples does it take for the experiment to produce an all-green sample? How is this dependent on the various settings?
  • Are there more samples with an even number of green squares as compared to those with an odd number of green squares?
  • How symmetrical is the histogram? How would you define "symmetry?" How would you quantify and display its change over time?

NETLOGO FEATURES

Turtle Shapes --- The top panel of the view features a red arrow-like turtle shape. Pressing on this button toggles between Turtles-Shape "On" and "Off." In many NetLogo models, turtles represent specific agents ("creatures") in the situation or phenomenon that is being modeled. So in many models the turtles have distinctive shapes (icons) that approximate or at least suggest what they are modeling. However, this model is an example of a case where we do not want any special turtle shape. In fact, we actually want the turtles to look like the patches --- just squares. So we have turned the Turtle-Shapes to "Off." Try running the model with the Turtles-Shapes "On" (you can change this while running the model) and see which mode you prefer. The difference between these two modes will be most noticeable when you are running the model slowly and/or when the 'magnify?' switch is turned to 'On." You could also edit the size of the turtles. Perhaps you will discover that you prefer having the turtles be some special shape. How might that affect the histogram?

RELATED MODELS

Some of the other ProbLab (curricular) models, including SAMPLER --- HubNet Participatory Simulation --- feature related visuals and activities. In Stochastic Patchwork and especially in 9-Blocks you will see the same 3-by-3 array of green-or-blue squares. In the 9-Block Stalagmite model, when 'keep-duplicates?' is set to 'Off' and the y-axis value of the view is set to 260, we get the whole sample space without any duplicates. In the Stochastic Patchwork model and especially in 9-Blocks model, we see frequency distribution histograms. These histograms compare in interesting ways with the shape of the combinations tower in this model.

CREDITS AND REFERENCES

This model is a part of the ProbLab curriculum. The ProbLab Curriculum is currently under development at Northwestern's Center for Connected Learning and Computer-Based Modeling. . For more information about the ProbLab Curriculum please refer to http://ccl.northwestern.edu/curriculum/ProbLab/.

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. (2004). NetLogo Sample Stalagmite model. http://ccl.northwestern.edu/netlogo/models/SampleStalagmite. 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 2004 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.

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

Comments and Questions

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

Click to Run Model

globals [
         ;; colors of the background of the view and of the two possible colors in samples
         background-color column-color target-color other-color
         num-columns ;; how many columns there are in the graphics-window histogram
         num-target-color  ;; how many of the squares (patches) in the sample are of the favored color
         sample-right-xcor ;; the x-coordinate of the moving sample (not the magnified sample)
         sample-location-patch-agentset ;; patches where the moving sample will sprout
         token-sample-dude ;; bottom-left turtle in the moving sample
         stop-all? ;; Boolean variable for stopping the experiment
         ]
patches-own [ column ]

breed [ column-kids column-kid ]
breed [ sample-dudes sample-dude ]
breed [ baby-dudes baby-dude ]

sample-dudes-own [distance-for-jump ]
column-kids-own [ binomial-coefficient sample-list ]

;; This procedure colors the view, divides patches into columns of equal length ( plus a single partition column),
;; and numbers these columns, beginning from the left, 0, 1, 2, 3, etc.

to setup
  clear-all
  set-default-shape turtles "square big"
  set background-color white - 1
  set column-color gray
  set target-color green
  set other-color blue
  set-plot-x-range 0 ( 2 ^ ( side ^ 2 ) ) ;; the max of the range is set to be large enough to begin with

  ;; num-columns is how many columns (bars) there are in the graphics-window histogram.
  ;; We need side ^ 2 + 1 columns in a histogram. For example, 3-by-3 samples (9 patches)
  ;; have 10 -- that is, 3 ^ 2 + 1 -- different possible counts of target-color (0, 1, 2, 3, ...9).
  set num-columns ( side ^ 2 + 1)

  ;; determines the location of the sample array beginning one column to the left of the histogram
  set sample-right-xcor -1 * round ( ( num-columns / 2 ) * ( side + 1 ) )

  ;; assigns each patch with a column number. Each column is as wide as the value set in the 'side' slider
  ask patches
  [
    set pcolor background-color
    ;; The following both centers the columns and assigns a column number to each patch
    ;; We use "side + 1" and not just "side" so as to create an empty column between samples
    set column floor ( ( pxcor + ( ( num-columns * ( side + 1 ) ) / 2 ) ) / ( side + 1 ) )
    if column < 0 or column >= num-columns
      [ set column -100 ]
  ]

  ;; leave one-patch strips between the columns empty
  ask patches with
  [ [column] of patch-at -1 0 != column ]
  [
    set column -100  ;; so that they do not take part in commands that report relevant column numbers
  ]

   ;; colors the columns with two shades of some color, alternately
   ask patches
   [
     if column != -100
     [
       ifelse int ( column / 2 ) = column / 2
       [ set pcolor column-color ][ set pcolor column-color - 1 ]
     ]
   ]

  ;; This draws the yellow base-line and creates a sample-kids turtle at the base of each column
  ask patches with
  [ ( pycor = -1 * max-pycor + side + 3 ) and  ;; The base line is several patches above the column labels.
    ( column != -100 ) ]
  [
    set pcolor yellow
    if [column] of patch-at -1 0 != column   ;; find the leftmost patch in the column...
    [
      ask patch (pxcor + side - 1)  ;; ...then move over to the right of the column
                ( -1 * max-pycor + 1 )
        [ set plabel column ]
      ask patch (pxcor + floor (side / 2))  ;; ...then move over to the middle of the column
                ( -1 * max-pycor + 1 )
      [
       sprout 1
        [
          hide-turtle
          set color pcolor
          set breed column-kids
          set sample-list []

          ;; each column-kid knows how many different combinations his column has
          set binomial-coefficient item column binomrow (num-columns - 1)
        ]
      ]
    ]
  ]
  set stop-all? false
  set num-target-color false
  reset-ticks
end 

to go
  if stop-all? [stop]
  ;; The model keeps track of which different combinations have been discovered. Each
  ;; column-kid reports whether or not its column has all the possible combinations. When bound? is true,
  ;; a report from ALL column-kids that their columns are full will stop the run.
  if stop-at-all-found? [if count column-kids with [length sample-list = binomial-coefficient] = count column-kids
    [stop]]
  sample
  ifelse magnify? [ magnify-on-side ] [ ask baby-dudes [ die ] ]
  drop-in-bin
  ;; the counter keeps track of how many samples have been taken (not how many different samples have been discovered)
  tick
  if plot? [ plot %-full ]
end 

;; This procedure creates a square sample of dimensions side-times-side, e.g., 3-by-3,
;; located to the left of the columns. Each patch in this sample sprouts a turtle.
;; The color of the sample-dudes in this square are either target-color or other-color,
;; based on a random algorithm (see below)

to sample
  ;; creates a square agentset of as many sample-dudes as determined by the 'side' slider,
  ;; positioning these sample sample-dudes at the top of the view and to the left of the histogram columns
  set sample-location-patch-agentset patches with
  [
    ( pxcor <= sample-right-xcor ) and
    ( pxcor > sample-right-xcor - side ) and
    ( pycor > ( max-pycor - side ) ) ]
  ask sample-location-patch-agentset
  [
    sprout 1
    [
      ht
      set breed sample-dudes
      setxy pxcor pycor

    ;; Each turtle in the sample area chooses randomly between the target-color and the other color.
    ;; The higher you have set the probability slider, the higher the chance the turtle will get the target color
    ifelse random 100 < probability-to-be-target-color
      [ set color target-color ]
      [ set color other-color ]
    st
    ]
  ]
  ;; num-target-color reports how many sample-dudes in the random sample are of the target color
  set num-target-color count sample-dudes with [ color = target-color ]
end 

;; procedure in which the sample turtles create an enlarged duplicate on the left side of the view and this enlarged sample makes
;; a large duplicate of the sample. This helps users see the samples that may otherwise be too small to see comfortably.
;; Samples are small for side = 3 because we want the entire sample space to fit into the view.

to magnify-on-side
  ask baby-dudes [die] ;; clears the way for new magnified sample
  ask sample-dudes
  [
    hatch-a-big-baby
  ]
end 

to hatch-a-big-baby ;; sample-dudes procedure
  hatch 1
  [
    set breed baby-dudes
    set size 12 * ( 8 - side ) / side
    ;; This is tricky.  We want to center the new turtles vertically, and
    ;; put them to the right of all the columns, with a little space between.
    setxy -1 * ( size * .75 ) + ( sample-right-xcor + ( size * ( xcor - sample-right-xcor ) ) )
          ( ( side - 1 ) * size / 2 ) + ( size * ( ycor + min-pycor ) )
    set size size * .95
  ]
end 

;; This procedure moves the random sample sideways to its column and then down above other previous samples
;; in that column.

to drop-in-bin
  find-your-column
  descend
end 

;; The random sample moves to the right until it is in its correct column, that is, until it is in the column
;; that collects samples which have exactly as many sample-dudes of the target color as this sample has.
;; The rationale is that the as long as the sample is not in its column, it keeps moving sideways.
;; So, if the sample has 9 sample-dudes (3-by-3) and is moving sideways, but 6 of them are not yet in their correct column,
;; the sample keeps moving. When all of the 9 sample-dudes are the sample's correct column, this procedure stops.

to find-your-column
  ask sample-dudes [ set heading 90 ]
  while
  [ count sample-dudes with [ column = num-target-color ] != side ^ 2  ]
  [
    ask sample-dudes
    [ fd 1 ]
  ]
end 

;; Moves the sample downwards along the column until it is either on the base line or
;; exactly over another sample in that column.

to descend
  let lowest-in-sample min [ pycor ] of sample-dudes
  ask sample-dudes
  [ set heading 180 ]

  ;; The lowest row in the square sample is in charge of checking whether or not the sample has arrived all the way down
  ;; In order to determine who this row is -- as the samples keeps moving down -- we find a turtle with the lowest y coordinate
  ;; checks whether the row directly below the sample's lowest row is available to keep moving down
  set token-sample-dude one-of sample-dudes with [ pycor = lowest-in-sample ]
  while
  [
    [pcolor] of [patch-at 0 -2] of token-sample-dude != yellow and
    [pcolor] of [patch-at 0 -2] of token-sample-dude != target-color and
    [pcolor] of [patch-at 0 -2] of token-sample-dude != other-color
  ]
  [
    ;; As in find-your-column, shift the sample one row down
    ask sample-dudes
    [ fd 1 ]
    display
  ;; Instead of establishing again the lowest row in the sample, the y coordinate of the row
  ;; gets smaller by 1 because the sample is now one row lower than when it started this 'while' procedure
  set lowest-in-sample ( lowest-in-sample - 1 )
  ]

  ;; Once sample-dudes have reached as low down in the column as they can go (they are on top of either the base line
  ;; or a previous sample) they might color the patch with their own color before they "die."
  finish-off

  ;; If the column has been stacked up so far that it is near the top of the view, the whole supra-procedure stops
  ;; and so the experiment ends
  if max-pycor - lowest-in-sample < ( side + 1 ) [ set stop-all? true ]
end 

to finish-off
  ;; creates local list of the colors of this specific sample, for instance the color combination of a 9-square,
  ;; beginning from its top-left corner and running to the right and then taking the next row and so on
  ;; might be "green green red green red green"
  let sample-color-combination [ color ] of sample-dudes

  ;; determines which turtle lives at the bottom of the column where the sample is
  let this-column-kid one-of column-kids with [ column = [column] of token-sample-dude]

  ;; accepts to list only new samples and makes a previously encountered sample if keep-duplicates? is on
  ifelse not member? sample-color-combination [sample-list] of this-column-kid
  [
    ask this-column-kid
    [ set sample-list fput sample-color-combination sample-list ]
    ask sample-dudes
    [ set pcolor color die ]
  ]
  [
    ifelse keep-repeats? [
      ask sample-dudes
       [ set pcolor color die ]
    ] [
      ask sample-dudes
        [  die ]
    ]
  ]
end 

;; procedure for calculating the row of coefficients
;; column-kids needs their coefficient so as to judge if their column has all the possible different combinations

to-report binomrow [n]
  if n = 0 [ report [1] ]
  let prevrow binomrow (n - 1)
  report (map [?1 + ?2] fput 0 prevrow
                        lput 0 prevrow)
end 

;;if the model has been run, report the number of patches
;;with the target-color -- otherwise, display "--"

to-report #-target-color
  ifelse ticks != 0.0
  [ report count patches with [ pcolor = target-color ] ]
  [ report "--" ]
end 

;;if has been run, report the number of patches
;;with the other-color -- otherwise, display "--"

to-report #-other-color
  ifelse ticks != 0.0
  [ report count patches with [ pcolor = other-color ] ]
  [ report "--" ]
end 

;; reports the proportion of the sample space that has been generated up to now

to-report %-full
  report precision ( samples-found / ( 2 ^ ( side ^ 2 ) ) ) 3
end 

to-report samples-found
  report sum [ length sample-list ] of column-kids
end 

to-report total-samples-to-find
  report 2 ^ ( side ^ 2 )
end 


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

There are 14 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 almost 12 years ago Updated version tag Download this version
Uri Wilensky almost 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 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 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 Model from NetLogo distribution Download this version

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.