Random Basic
Model was written in NetLogo 5.0.4
•
Viewed 501 times
•
Downloaded 95 times
•
Run 1 time
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
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 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.