# Equidistant Probability

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## WHAT IS IT?

Equidistant Probability connects between probability and geometry. You select two or more squares, and the model searches randomly for squares that are equally distant from the squares you selected. To do this random search, creatures pop out of each one of your selected squares and simultaneously step forward one step in some random direction. If they all land in the same square, that's a hit. Can you guess how often this will happen?

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

The user sets up an experiment by selecting some squares on the view. When the model runs, from each of these selected squares emerges a creature, headed in a random direction, and then all these creatures step forward at the same moment. Because there are exactly as many creatures as there are selected squares, and because they all step forward at the same moment, if all the creatures arrive at the same square at the same moment, then that square is "equidistant" (equally far away) from all the selected squares. In that case, the square where they all landed becomes green and keeps a count of how often, out of all their "attempts," the creatures met there. Note that the creatures don't need to land on the exact same spot in the view (the same pixel) -- it's enough that they land in the same square.

There is a procedure in this model, "Epicenter," that helps think about how often a single creature might land in its neighboring squares. If we knew that, we might be able to figure out how often two or more creatures might land on the same square at the same time. For instance, if one creature has a 1-in-2 chance of landing on some square, and another creature has a 1-in-3 chance of landing on that same square, then there's a 1-in-6 chance that they will land on that square at the same moment. In this procedure, 10,000 creatures pop out of the middle square and take a step forward in some random direction. The other eight squares count up how many creatures landed on them, and these values are shown either as totals or as percentages.

## HOW TO USE IT

Here is a quick way to get familiar with the model. Press "PRESET1," slow down the model (using the slider on the top-left corner of the view), make sure SINGLE-SUCCESS? is at "Off," then press FIND EQUIDISTANT POINT. Watch how two creatures first emerge, each from its red square, and then step one step forward in some random direction. Once you understand this, speed up the model gradually. Quite soon, the creatures will land on the same square at the same time, that square will become green, and it will display a percentage, for instance 5.00% (that is, 1/20). That would mean that it took 20 attempts to find that square. Also, the plot ATTEMPTS UNTIL SUCCESS will show a histogram bar at "20," and the average that is, simply, "20" at this time. Also, the monitor below the plot, MEAN ATTEMPTS TO SUCCESS, will show "20." Now press FIND EQUIDISTANT POINT again. It could be that a different square will be found this time. The plot and monitor will update, again. If you switch the SINGLE-SUCCESS switch to "Off" and press FIND EQUIDISTANT POINT, the model will keep searching and finding. Watch the monitor SAMPLES TAKEN UP TO NOW to see how many attempts have been taken towards completing a sample (the default setting of SAMPLE-SIZE is 1,000). Once a sample has been completed, the plot #SUCCESSES PER SAMPLE will show how many successful attempts there were in that sample.

Buttons: SETUP -- initialize variables SELECT SQUARE -- once you press this, you can click on the view to choose squares that become red. If you click again on a red square, it will be un-selected. When you are through with selecting, un-press the button so as not to make further selections by mistake while the model is running. FIND EQUIDISTANT POINT -- sets off the search procedures. From every red square, dart-like creatures pop up, each headed at some random direction, and then they step forward. PRESET 1 through 6 -- each 'Preset' button sets the model up with a pre-selected configuration of red squares. EPICENTER -- activates a procedure in which 10,000 turtles emerge from the center square at random orientations, and all step forward a single step. Pressing this causes you to lose all data from an experiment that you may have been running.

Switches: SINGLE-SUCCESS -- when "On", the procedure FIND EQUIDISTANT POINT will stop the moment a square has been found that is equally distant from the red squares. When "Off", the procedure will continue again and again, until you un-press FIND EQUIDISTANT POINT.

Monitors: #SUCCESSES -- shows how many successes you have had in this experiment, that is, how many times all the creatures landed at the same time in one and the same square. #ATTEMPTS -- shows how many attempts you have had in this experiment, that is, how many times all the creatures have "tried" to land at the same time in one and the same square. FREQUENCY -- how many successes there have been out of the total number of attempts, expressed as a percentage. This can never be larger than 100 because there cannot be more successes than there are attempts. SAMPLES TAKEN UP TO NOW -- shows how many samples have been completed, for instance of 1,000 attempts each, and how many attempts have been taken in the current sample.

Plots: ATTEMPTS UNTIL SUCCESS -- a histogram that updates each time an equidistant square is found, to show how many attempts were needed to find that square.

SUCCESSES PER SAMPLE -- a histogram that updates each time a sample has been completed, for instance of 1,000 attempts, to show how many successes there were in that sample.

Choice: DISPLAY RESULTS (relates to the 'Epicenter' button) 'by-total' -- squares show the number of creatures that landed on them. 'by-%' -- squares show the percentage of creatures that landed on them out of all landings.

## THINGS TO NOTICE

The creatures' steps are equal in length to the side of a square. If a creature has just emerged in the middle of a square and is heading at 90 degrees, then the step forward will land it at exactly the middle of the square to its right. But if it's headed at 45 degrees, then the step forward will put it in the square that is diagonally neighboring it on the top right, short of the middle of that square.

The values of 'Frequency' and 'Mean #Attempts to Success' are reciprocal:

- Frequency is what you get when you divide #Successes by #Attempts
- Mean #Attempts to Success is what you get by dividing #Attempts by #Successes. So if you multiply these values, you get 1 (or 100, if you ignore the "%" sign).

For Presets 1 and 2, the creatures will find more than a single square that is equally distant from the red squares. But for Presents 3, 4, 5, and 6, they will only find one such square.

When you press EPICENTER with the choice set at "by-%," the percentages you get are such that the North/West/South/East squares each has roughly 1/6 of the creatures (16.7%), and the cornering patches each has 1/12 of the creature (8.33%).

## THINGS TO TRY

Set the model with Preset1 and run the model with SINGLE-SUCCESS? set to "Off." Note that the middle square will register four times as many successes as compared to the center-left square and as compared to the center-right square. Try to come up with a logical explanation for this.

Set the model with Preset3 and run the model with SINGLE-SUCCESS? set to "Off." Track the values you get in the monitor MEAN #ATTEMPTS TO SUCCESS. Try to find a different selection of squares that gives the same value. What does this selection have in common with the Preset3 selection? Repeat this for the preset conditions 4, 5, and 6.

A very big challenge: The experiments in this model are all based on random choices. After enough attempts, the results begin to stabilize around certain values. Can you determine what these numbers will be before you run an experiment? For instance, can you anticipate the value of MEAN #ATTEMPTS TO SUCCESS on the basis of the configuration of squares that you have selected? To do this, you could think about the information you get from the "Epicenter" procedure. Also, you may want to analyze this problem using pencil and paper.

## EXTENDING THE MODEL

Add a plot for the cumulative ratio of '#Successes' to '#Attempts.' The plot should update at every attempt.

Edit the size of the view so as to include more squares. You will be able to create configurations that you could not create before.

For the "Epicenter" procedure, increase the number of squares in the view. Add interface widgets and code that allow for broader experimentation, such as variety in the number of steps the creatures take and the size of these steps.

## RELATED MODELS

The three different ways of looking at the data in this model are the same as in Prob Graphs Basic: cumulative ratio, attempts until success ("waiting time"), and sampling.

## 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/.

Additional reading: Abrahamson, D. & Wilensky, U. (2003). The quest of the bell curve: A constructionist approach to learning statistics through designing computer-based probability experiments. Proceedings of the Third Conference of the European Society for Research in Mathematics Education, Bellaria, Italy, Feb. 28 - March 3, 2003. Available for download at http://ccl.northwestern.edu/ps/papers/Probability/BellCurve.html

## 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 Equidistant Probability model. http://ccl.northwestern.edu/netlogo/models/EquidistantProbability. 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

breed [ wanderers wanderer ] ;; turtles in Equidistant-Point that walk out from green patches breed [ darts dart ] ;; turtles in Epicenter: They all emerge from the middle globals [ num-squares ;; number of selected squares (patches) from which wanderers emerge attempts ;; number of times the wanderers have attempted to convene on the same patch since the previous success attempts-list ;; list of how many attempts it took until a success successes-per-this-sample ;; how many successes occurred in the current sample of attempts successes-per-sample-list ;; list of how many successes occurred in all samples up to the current moment successful-attempt? ;; Boolean variable that is true if an attempt was successful ] patches-own [ counter ;; in Epicenter, this variable keeps track of how many times darts have visited the patch pmy-color ;; "reminds" patches of their color from before it is temporarily changed conventions ;; how many times all the wanderers meet in the patch ] ;; SETTING UP THE MODEL to setup ca set attempts-list [] set successes-per-sample-list [] set successful-attempt? false checker end ;; creates the 9-by-9 "chess-board" appearance of the view with a blue perimeter to checker ask patches [ ;; even patches and odd patches ifelse ( pxcor mod 2 = pycor mod 2 ) [ set pcolor 3 ] [ set pcolor 7 ] if count neighbors != 8 [ set pcolor 104 ] set pmy-color pcolor ] end ;; user uses mouse to paint squares red to select-squares if mouse-down? [ ask patch round mouse-xcor round mouse-ycor [ if pcolor = 104 [ stop ] ifelse pcolor = red [ set pcolor pmy-color ] [ set pcolor red ] ] wait .2 ;; to give the user a chance to retract his/her clicking finger set num-squares count patches with [ pcolor = red ] ] end ;; some preset suggestions for setting up the squares to preset1 ;; two abutters setup ask patch 0 1 [ set pcolor red ] ask patch 0 -1 [ set pcolor red ] set num-squares 2 end to preset2 ;; two corners setup ask patch -1 1 [ set pcolor red ] ask patch 1 -1 [ set pcolor red ] set num-squares 2 end to preset3 ;; three abutters -- mean #attempt to success will be 1/ (6*6*6) =1/216 setup ask patch 1 0 [ set pcolor red ] ask patch 0 -1 [ set pcolor red ] ask patch -1 0 [ set pcolor red ] set num-squares 3 end to preset4 ;; two abutters, one corner -- mean #attempt to success will be 1/ (6*6*12) =1/432 setup ask patch 1 0 [ set pcolor red ] ask patch 0 -1 [ set pcolor red ] ask patch -1 1 [ set pcolor red ] set num-squares 3 end to preset5 ;; one abutter, two corners -- mean #attempt to success will be 1/ (6*12*12) =1/864 setup ask patch 1 0 [ set pcolor red ] ask patch -1 -1 [ set pcolor red ] ask patch -1 1 [ set pcolor red ] set num-squares 3 end to preset6 ;; three corners -- mean #attempt to success will be 1/ (12*12*12) =1/1728 setup ask patch 1 -1 [ set pcolor red ] ask patch -1 -1 [ set pcolor red ] ask patch -1 1 [ set pcolor red ] set num-squares 3 end ;; RUNNING THE MODEL ;; from every red square a wanderer emerges, heads off randomly, and steps forward one step to find-equidistant-point if num-squares < 2 [ stop ] if single-success? and successful-attempt? [ set successful-attempt? false stop ] set attempts attempts + 1 birth-wanderers sprint-straight update-sampling-data end to birth-wanderers ask patches with [pcolor = red] [ sprout-wanderers 1 [ set color magenta ] ] end ;; if there are as many turtles on the same patch as there are red squares, then that means that all ;; our wanderers have convened together. This patch is equidistant from all red squares because ;; all wanderers have traveled as far over the same time. to sprint-straight if not any? wanderers [ stop ] ask wanderers [ fd 1 ] if any? patches with [ ( pcolor != 104 ) and ( count wanderers-here = num-squares ) ] [ set successful-attempt? true ask patches with [ ( pcolor != 104 ) and ( count wanderers-here = num-squares ) ] [set conventions conventions + 1] update-labels do-plots ] ask wanderers [ die ] ;; because we need to start a new attempt now end to update-labels ask patches with [ conventions != 0 ] [ set pcolor green set plabel word precision ( 100 * conventions / ( sum attempts-list + attempts ) ) 2 "%" ] end to do-plots set attempts-list ( fput attempts attempts-list ) set-current-plot "Attempts Until Success" set-plot-x-range 0 ( max attempts-list + 1 ) set-current-plot-pen "attempts until success" histogram attempts-list let maxbar modes attempts-list let maxrange filter [ ? = item 0 maxbar ] attempts-list set-plot-y-range 0 length maxrange set-current-plot-pen "mean attempts" plot-pen-reset plotxy (mean attempts-list) plot-y-min plotxy (mean attempts-list) plot-y-max set attempts 0 end ;; updates each time a sample has ended running to update-sampling-data if ( sum attempts-list + attempts ) mod sample-size = 0 ;; if the number of attempts is a multiple of sample size [ ;; finds increment in successes since last sampling point. ;; note that the length of a list here is in effect how many times the list ;; was updated, that is, how many times whatever it is listing actually happened set successes-per-this-sample ( length attempts-list - sum successes-per-sample-list ) set successes-per-sample-list ( fput successes-per-this-sample successes-per-sample-list ) set-current-plot "#Successes Per Sample" if not empty? ( remove 0 successes-per-sample-list ) [ set-plot-x-range 0 ( max successes-per-sample-list + 1 ) ] set-current-plot-pen "#Successes Per Sample" histogram successes-per-sample-list let maxbar modes successes-per-sample-list let maxrange filter [ ? = item 0 maxbar ] successes-per-sample-list set-plot-y-range 0 length maxrange set-current-plot-pen "mean-successes-per-sample" plot-pen-reset plotxy ( mean successes-per-sample-list ) plot-y-min plotxy ( mean successes-per-sample-list ) plot-y-max ] end to-report cumulative-frequency let cum-probab precision (100 * (length attempts-list / (sum attempts-list + attempts))) 2 report word cum-probab " %" end to-report samples-count let total-attempts ( sum attempts-list + attempts ) let total-samples floor ( total-attempts / sample-size ) report (word total-samples " samples + " ( total-attempts - total-samples * sample-size ) " attempts this sample") end to epicenter setup ; same setup as used in Equidistant-Point ask patch 0 0 [ if pcolor != red [ set pcolor red ] ] birth-darts move-dart ask darts [ die ] label-results end to birth-darts create-darts 10000 [ set size .5 ] end to move-dart ;; the patches keep track of their visits ask darts [ fd 1 ] ask patches [ set counter counter + count turtles-here ] end to label-results let helper sum [ counter ] of patches ask patches with [ ( pcolor != 104 ) and ( pcolor != red ) ] [ set plabel-color pcolor + 5 ifelse Display-Results = "by-%" [ set plabel word precision ( 100 * counter / helper) 2 "%" ] [ set plabel precision counter 0 ] ] 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 | |
---|---|---|---|---|

Equidistant Probability.png | preview | Preview for 'Equidistant Probability' | almost 10 years ago, by Uri Wilensky | Download |

This model does not have any ancestors.

This model does not have any descendants.