Skip to content

PauJimeno/RA_Assignment-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Galton Board Simulator (RA Assignment)

A C++ simulation of a Galton Board, with support for automated experiments and analysis via a Python notebook.


1. Setup

Clone the repository:

git clone https://github.com/PauJimeno/RA_Assignment-1.git
cd RA_Assignment-1

2. Compiling and Running the Simulation

2.1 Compilation

Compile the C++ code using g++:

g++ -o galton_board galtonBoard.cpp

No external libraries have been used.

2.2 Simulation Parameters

The simulation supports several parameters. Use --help or -h to view usage:

./galton_board --help

Example output:

FLAG TYPE DESCRIPTION DEFAULT
-d / --min <int> Minimum number of balls/layers 1000
-u / --max <int> Maximum number of balls/layers 10000
-s / --step <double> Step value (linear or multiplier in log mode) 1000
-n / --nfixed <int> value of fixed vaiable 100
-p / --prob <double> Probability of right side 0.5
-v / --vlayers Set balls to be the fixed variable false
-l / --logstep Use logarithmic steps false

Notes:

  • You can fix one variable (balls or layers) and vary the other.
  • The free variable progresses from --min to --max.
  • Step size is controlled by --step. Use --logstep for logarithmic progression.

2.3 Examples

  1. Fixed layers (300) with increasing balls (5–10000) in linear steps of 100:
./galton_board --nfixed 300 --min 5 --max 10000 --step 100
  1. Fixed balls (300) with increasing layers (5–10000) in linear steps of 100:
./galton_board --nfixed 300 --min 5 --max 10000 --step 100 --vlayers

2.4 Output

The simulation prints results in CSV format, where each column represents a final bin and the value is the number of balls in that bin.

Example (55 balls, 15 layers):

0;0;0;0;1;4;10;6;17;8;5;3;1;0;0;0

3. Python Notebook for Analysis

A Python notebook (GaltonBoard_graphs.ipynb) is provided to run simulations, analyze results, compute errors, and generate plots. Requires numpy, scipy, matplotlib.

3.1 Example Usage

exec_name = "galton_board"  # Name of the compiled executable

n = 100             # Fixed quantity (layers or balls)
min_value = 5       # Minimum for variation
max_value = 10000   # Maximum for variation
step = 1.3          # Step value (>1)
log = True          # Use logarithmic steps
vl = False          # If True, balls are fixed; otherwise, layers are fixed
p = 0.5             # Probability to go left
n_s = 25            # Number of samples

main(exec_name, n, min_value, max_value, step, vl, log, p, n_it)

The main function:

  1. Runs the C++ simulation in a subprocess.
  2. Collects results.
  3. Generates plots for analysis.

More details can be found in the notebook.


3.2 Example Plots

The notebook produces plots such as:

image image image image

Group

Pau Jimeno Román Thomas Aubertier


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors