Random Basic
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
Random Basic is the simplest of all the ProbLab models. It can either be used first or as a detour from a more complex model to explain randomness. This model introduces the user to the random generator in NetLogo. Randomness means that in the short term you cannot guess a value but in the long term all possible values will have occurred more or less equally often.
Here we see a bar chart grow reflecting a real-time succession of random events. You can think of the bar chart as a competition between the columns and ask whether one of the columns wins more often than others. Or you can think of it as some goodies being given out and think about whether the goodies are being given out fairly. Or think about it some other way -- that's fine.
You can set the size of the sample space. Also, you can split the bar chart into two sub-regions (red and green) and track the convergence of the distribution on proportion values that you have set.
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 every tick, the computer selects a random number between 1 and "sample-space" (a slider in the interface tab). For instance, if the slider reads 100, then the random number will be between 1 and 100, inclusive. This random number piggy-backs on a virtual dart. In this program the dart is called the 'messenger' because it carries the number from the top of the view to the appropriate column. Each column is associated with one number. Once the messenger gets to its column, the messenger vanishes but the column becomes taller by one square (the squares are called 'frames' in this and other models in ProbLab). The columns grow until one of them reaches the brown half of the view, which stops the run.
HOW TO USE IT
Choose a sample-space (you can leave it at the default value of '100') and press Setup. Now press Go. The messenger (the dart) will obtain a random number and carry it to the correct column. The red-green slider changes which columns are red and which are green. If it's set at 50% and if the sample space is 100 then patches up to 50 will be red and the rest will be green. If it's set at 50% and the sample space is 30 then patches up to 15 will be red. There are cases where this might be confusing: for instance, if it's set at 50% and if the sample space is 5 then patches up to 2 will be red. The '3'-column will be green because it goes further than 50% of 5. That is, all columns up to and including the 3-column are more than 50% of the columns in the sample-space of 5 -- they are actually 60% because each of the 5 columns makes up 20% (and 5 * 20% is 100%). (See the section EXTENDING THE MODEL, below.)
These are the widgets in order of appearance from top to bottom:
SAMPLE-SPACE is a slider for setting how many columns you want to be filling up. Also, it sets the range of numbers that will be randomly selected. If you set the slider to 3 then you will have 3 columns and the values will always be either 1, 2, or 3.
SETUP - prepares the model for running with your sample-space parameter setting.
GO - runs the model with the current settings.
BIGGEST GAP - shows the biggest vertical difference between all columns. For instance, if the highest column is 10 squares high and the lowest is at 3 squares high then this monitor will show '7'.
%-RED - shows what percentage of the squares are red out of all the squares.
COLORS? - when this switch is on the patches get painted either red or green depending on the red-green slider value and their position.
RED-GREEN - sets the cut-off line for which patches are painted red and which green. When your sample-space is 100 then the position of the little handle on the slider (what you grab and move) is exactly at the cut-off line. For sample spaces other than 100 it will be under the cut-off line only when it is set at 50. This is because currently this slider works according to percentage of events and not column value.
%-FULL - the proportion of the yellow area that has been filled up by squares.
THINGS TO NOTICE
What happens to the biggest gap as the model runs. Does it change? Does it get consistently bigger? Smaller? Is this connected to the size of the sample space or not? Come up with an explanation for this. Also, if you keep running the model with the same sample space until it stops, are you getting the same biggest gap each time? Is it "kind of the same"?
THINGS TO TRY
How does the size of the Sample-Space affect your sense of "fairness?" Is it more "fair" when the sample-space is small (narrow) or when it is big (wide)? Try changing the sample-space slider and see if you feel that the events are being equally distributed across the bar chart. You can set the red-green slider at 50%, then at other values, and, looking at the %-red monitor, evaluate how long it takes for the red-green and the %-red values to be more or less the same. Perhaps a good way to go about this is by using a sample-space of size 2. This is much like flipping a coin. Now set it to a sample-space of 6. This is kind of like rolling a die.
Actually, what is fairness? Is the difference between two columns of heights 0 and 3 the same as the difference between two columns of heights 20 and 23?
How does the passage of time -- more and more events -- affect how close the red-green slider and the %-red are?
EXTENDING THE MODEL
Currently, the red-green slider shows you how many patches there are that are smaller than a cut-off value. But you may want to know, for instance, how often the value '1' appeared and compare it to how many times the value '2' appeared. You could just count, but you may want to compare the ratio between these accumulations and see what happens to it as the program runs.
Another idea is to keep track of how many times, on average, a certain value, for instance '1' occurs out of every 10 trials. Partitioning the events into groups of 10 is called "sampling."
Keep track of how long it takes, on average, to get a certain value (for instance, '1'). That's called "waiting time".
Even another thing to check is how often you get a "double," that is, how often you get the same value back to back. How would the sample size affect that?
Build plots of your extensions to the model.
Implement a monitor that shows the smallest gap. There is currently a monitor which shows the biggest gap.
The red-green slider could work differently. For instance, instead of indexing the percentage, it could index the column number. If the red-green were set to 7 then it could index all the columns from 1 through 7.
What would happen if you added more messengers? Perhaps you could sprout them at different locations and have them execute the same code. Would this change the way the type of experimental outcomes?
Add a slider that allows you to choose specific columns and find out how many squares have accumulated in it.
Perhaps you noticed that each time you setup and run the model (each experiment) the random numbers come in a different order. But you may want to explore the same set of random numbers in several experiments where you modify some parameters. To do this, you should try working with the NetLogo primitive "random-seed" (see the NetLogo User Manual for details). If you keep sample-space constant, you should get the same numbers in the same order.
NETLOGO FEATURES
We use the random
primitive a great deal in NetLogo and especially in ProbLab, where we care about probability. But how does NetLogo produce random numbers? Does it roll a die or flip a coin? Actually, NetLogo uses the "Mersenne Twister" random generator. This generator is sometimes called a “pseudo-random” number generator because it uses a certain mathematical algorithm to produce numbers that appear random, but are actually predictable given enough time to figure out the pattern.
RELATED MODELS
All of the ProbLab models use randomness. Having worked with this model, you may now have a better sense of where these random numbers are coming from and what to expect when the random
primitive is used. In particular, note how other ProbLab models use randomness to control the movement of agents.
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 Random Basic model. http://ccl.northwestern.edu/netlogo/models/RandomBasic. 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.
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
globals [ time-to-stop? ;; boolean that discontinues run when columns reach to top the-messenger ;; holds identity of the single turtle of breed 'messengers' ;; (see EXTENDING THE MODEL) max-y-histogram ;; how high the columns can rise (or how far up the yellow goes) ] breed [ column-counters column-counter ] ;; they keep track of their respective histogram columns breed [ frames frame ] ;; square frames that indicate events in histogram columns breed [ messengers messenger ] ;; carry the random value to its column ;; (currently just one single messenger implemented) column-counters-own [ ;; if you choose a sample-space 7 then you get 7 column-counters ;; and their respective my-columns will be 1 thru 7 my-column ;; each column-counter holds all patches that are in its column as an agentset my-column-patches ] to setup clear-all ;; computes the height the user has requested so as to get the value that makes sense ;; in this model because the histogram grows from the negative-y values and not from 0 set max-y-histogram (min-pycor + height) create-histogram-width setup-column-counters set time-to-stop? false reset-ticks end to create-histogram-width ask patches [ ;; deals with both even and odd sample-spaces ;; this is one way of centering the histogram. ;; that means that the '50' of the red-green slider ;; will always be aligned with the middle of the histogram ifelse (pxcor >= (- sample-space) / 2) and (pxcor < sample-space / 2) and (pycor < max-y-histogram) ;; this shapes the top of the yellow zone [ set pcolor yellow ] [ set pcolor brown ] ] end ;; column-counters are turtles who form "place-holders" so that ;; the messenger will "know" where to take its value. ;; they are like the values on the x-axis of your sample space. to setup-column-counters ask patches with [(pycor = min-pycor) ;; bottom of the view and pcolor = yellow] ;; and in the histogram band width [ sprout-column-counters 1 [ ht ;; it is nice to see them but probably visually redundant set heading 0 ;; this assigns a column name to column-counters that ;; corresponds with the parameter setting of sample-space set my-column floor (pxcor + sample-space / 2 + 1) set my-column-patches patches with [ pxcor = [pxcor] of myself ] ] ] end to go ;; forever button if time-to-stop? [ stop ] select-random-value send-messenger-to-its-column ifelse colors? [ paint ] [ ask patches with [pcolor != brown] [ set pcolor yellow ]] tick end ;; 'messenger' is a turtle who carries the random value ;; on its back as a label to select-random-value ask patch 0 (max-y-histogram + 4) [ sprout-messengers 1 [ set shape "default" set color black set heading 180 set size 12 set label 1 + random sample-space ;; currently there is just one messenger, so we assign it to a 'messenger' ;; variable. this will save time when the model run. if the user chooses ;; to add more messengers then this shortcut may have to be done away with set the-messenger self ] ] end ;; messenger is the dart-shaped large turtle that carries the random value ;; on its back. it takes this value directly to the appropriate column to send-messenger-to-its-column ;; 'it' holds the column-counter who is master of the ;; column towards which the messenger orients and advances ;; to dispatch its event let it one-of column-counters with [ my-column = [label] of the-messenger ] ask the-messenger [ face it ;; keep advancing until you're all but covering your destination while [ distance it > 3 ] [ fd 1 ;; to the patch above you to prepare for next event display ] die ] ask it [ create-frame fd 1 ;; if the histogram has become too high, we just stop. ;; this could be extended so as to have the whole population ;; of events collapse down one patch, as in Galton Box if ycor = max-y-histogram [ set time-to-stop? true ] ] end ;; make the square frames that look like accumulating cubes to create-frame ;; turtle procedure ask patch-here [ sprout-frames 1 [ set shape "frame" set color black ] ] end ;; patches are red if they are as far to the right within the sample-space ;; as indexed by the red-green slider; otherwise, the are green ;; Note that currently there is no rounding -- just a cut-off contour. to paint ask column-counters [ ifelse my-column <= (red-green * sample-space / 100) [ ask my-column-patches with [ pycor < [pycor] of myself ] [ set pcolor red ] ] [ ask my-column-patches with [ pycor < [pycor] of myself ] [ set pcolor green ] ] ] end ;; reports the percentage of red patches out of all patches that have frames ;; so we know what percent of events are to the left of the cut off line to-report %-red report precision (100 * count patches with [pcolor = red] / count frames) 2 end to-report %-full report precision ( 100 * (count frames ) / ( height * sample-space ) ) 2 end ;; biggest-gap is the greatest difference in height between all columns to-report biggest-gap let max-column max [count my-column-patches with [pycor < [pycor] of myself] ] of column-counters let min-column min [count my-column-patches with [pycor < [pycor] of myself] ] of column-counters report max-column - min-column end ; Copyright 2004 Uri Wilensky. ; See Info tab for full copyright and license.
There are 15 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Random Basic.png | preview | Preview for 'Random Basic' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.