CodingĬreate a new folder and within it create these empty source code files. The latter file can be replaced with any other providing it has a set of functions with the same parameters. When any of these things happens the specified function will be called, the Galton Board code itself having no responsilibity for or knowledge of how the visual output is handled.Īside from the file containing the main function there are two other files, one for the Galton Board code and one for the functions which draw the output. Specifically there are three things a Galton Board can do which require an update to the visual output: The code can therefore be used with any form of output by just passing the appropriate functions. These will be called when something happens requiring the graphical output to be updated. The actual mechanism I will use to do this is to pass functions to the functions controlling the board. To this end I will keep the data structures and logic completely separate from the visual output so a new output can be "plugged in". I will use the very rudimentary graphical and animation abilities of the terminal for this project, but the data structure and associated logic can be used with any environment offering graphical output such as more sophisticated terminal output using curses, or perhaps Tkinter. We also need to keep a running total of how many balls have taken each path, and finally some kind of visual display of what is happening. Implementing a software simulation of a Galton Board is straightforward: we just need a data structure representing the board and code simulating the random passage of balls through it. There are plenty of images and videos if you want to do a quick search. There also need to be containers of some kind to catch the balls from each final destination so they can be counted. It is a bit like a simple pinball machine with pegs arranged in the pattern of a Pascal's Triangle and mounted vertically to let gravity do the work of propelling balls from one peg to the next. This is all very abstract but the concept can be made physical with a contraption called a Galton Board, named after Sir Francis Galton but also called a bean machine of quincunx. Another key characteristic of Pascal's Triangle is that the probabilities build up row by row into an approximation of the normal distribution. Probabilities always add up to 1, indicating certainty - if you start at the top and keep going, whatever path you take and wherever you end up, you are certain to get to one of the numbers in the last row. The total number of paths is 16 so the total probability isĥ-Row Pascal's Triangle Total Path Probabilities So for example in the 5-row triangle above the probability of taking a particular path is (We subtract 1 from the row count as there is no choice involved on the first row, there only being one number.) This is the graphic I used in the previous post to illustrate a five-row Pascal's Triangle.Ī key characteristic of Pascal's Triangle is that if you start at the top and than trace a path downwards, randomly choosing to go left or right, each number you land on tells you how many different paths there are to that number. CC BY-SA 3.0 Creative Commons Attribution-Share Alike 3.I recently wrote a post on Pascal's Triangle and in this post I will write a program in Python to implement a Galton Board simulator, a Galton Board being an actual physical gadget following the Pascal Triangle's probabilistic characteristics. This licensing tag was added to this file as part of the GFDL licensing update. share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made.to share – to copy, distribute and transmit the work.This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license. GFDL GNU Free Documentation License true true A copy of the license is included in the section entitled GNU Free Documentation License. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. I, the copyright holder of this work, hereby publish it under the following licenses:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |