Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sphinx:
- sphinx_exercise
- teachbooks_sphinx_grasple
- sphinx_tudelft_theme
- sphinxcontrib.bibtex

bibtex_bibfiles:
- references.bib
4 changes: 2 additions & 2 deletions book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ format: jb-book
root: intro.md

parts:
- caption: Subjects
- caption: Contents
chapters:
- file: simulation/overview.md
sections:
- file: simulation/Simulating_Dice.ipynb
- file: simulation/Birth_Month_Simulation.ipynb
- caption: Miscallaneous
- caption: Miscellaneous
chapters:
- file: references.md
#- file: changelog.md
Expand Down
13 changes: 13 additions & 0 deletions book/intro.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
(intro)=
# Probability and Statistics - Code Companion
This online book is designed to complement the Probability and Statistics courses taught at TU Delft. It explains how the visualisations and data analyses used in the course were created and guides you in making your own.

```{tip}
You can interact with coding sections of the book by clicking the rocket icon ({fa}`rocket`) found in the top right of the page.
```
<!-- TODO: Fill in the desired sections -->
## Additional Resources

## Reporting Mistakes

## Questions and Answers

## Book Layout

46 changes: 40 additions & 6 deletions book/references.bib
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
@misc{jason_moore,
title={Learn Multibody Dynamics, SymPy},
author={Moore, Jason},
howpublished={\url{https://moorepants.github.io/learn-multibody-dynamics/sympy.html}},
year={2023}
}
@misc{mysarahmadbhat_ford,
author = {mysarahmadbhat},
title = {Ford Used Car Listing},
howpublished = {Kaggle dataset},
year = {n.d.},
note = {Accessed: 2025-09-26}
}

@misc{quinlan_1993_autompg,
author = {Quinlan, R.},
title = {Auto MPG},
howpublished = {UCI Machine Learning Repository},
year = {1993},
doi = {10.24432/C5859H},
note = {Accessed: 2025-09-26}
}

@misc{ukveteran_michelson,
author = {ukveteran},
title = {Michelson --- Speed of Light Data},
howpublished = {Kaggle dataset},
year = {n.d.},
note = {Accessed: 2025-09-26}
}

@misc{cdc_brfss_2014,
author = {{Centers for Disease Control and Prevention}},
title = {Behavioral Risk Factor Surveillance System --- 2014 data (ASCII \& SAS files)},
howpublished = {U.S. Department of Health \& Human Services},
year = {2015},
note = {Accessed: 2025-09-26}
}

@misc{uci_pima,
author = {{UCI Machine Learning Repository}},
title = {Pima Indians Diabetes Database},
howpublished = {University of California, Irvine},
year = {n.d.},
note = {Accessed: 2025-09-26}
}
14 changes: 10 additions & 4 deletions book/simulation/Birth_Month_Simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"source": [
"# Birth Month Simulation\n",
"\n",
"We can use the built in random choice feature of numpy to simulate non-uniformly distributed events. For instance below we consider the situation where we want to simulate the choice of a costumer at a chips shop. The costumer can chooce to have mayonaise, ketchup, curry or peanut sauce on their chips. We simulate the choice the costumer makes by assigning each choice a certain probability. "
"We can use the built in random choice feature of [numpy](https://numpy.org/doc/) to simulate non-uniformly distributed events. \n",
"\n",
"To illustrate the `np.random.choice` functionality, consider a toy example where we want to simulate the choice of a customer at a fries shop. The customer can choose to have mayonnaise, ketchup, curry or peanut sauce on their fries. We simulate the choice the customer makes by assigning each choice a certain probability. "
]
},
{
Expand Down Expand Up @@ -42,7 +44,7 @@
"metadata": {},
"outputs": [],
"source": [
"food = [\"mayonaise\", \"ketchup\", \"curry\", \"peanut sauce\"]\n",
"food = [\"mayonnaise\", \"ketchup\", \"curry\", \"peanut sauce\"]\n",
"p = [0.6, 0.1, 0.15, 0.15]\n",
"food_choice = np.random.choice(food, p=p)\n",
"print(food_choice)"
Expand All @@ -52,7 +54,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's consider simulation of the birth months. So we will simulate a town of people together with their birth months. We use three different models for the birth months distributions. Namely, the uniform distribution over months, a uniform model over days that does not take leap days into account and a uniform model over days that does take leap days into account. "
"Now let's consider simulation of the birth months. We will simulate a town of people together with their birth months. We use three different models for the birth months distributions: the uniform distribution over months, a uniform model over days that does not take leap days into account, and a uniform model over days that does take leap days into account. "
]
},
{
Expand Down Expand Up @@ -117,7 +119,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally let's have a look at our simulated distribution. For more on plotting have a look at the visualiation chapter. Below we load our simulated data into a dataframe and subsquently plot the proportions of each model into a histogram. "
"Finally let's have a look at our simulated distribution. Below we load our simulated data into a dataframe and subsequently plot the proportions of each model into a histogram. \n",
"\n",
"```{tip}\n",
"For more on plotting have a look at the visualisation chapter.\n",
"```{tip}"
]
},
{
Expand Down
20 changes: 14 additions & 6 deletions book/simulation/Simulating_Dice.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
" The most basic building blocks are uniform random variables. We will gloss over the mechanics of how random number generators are produced and simply call them, using the `numpy` package. \n",
" ## Uniform Random Variables\n",
" \n",
" The most basic building blocks are uniform random variables. We will gloss over the mechanics of how random number generators are produced and simply call them, using the [`numpy`](https://numpy.org/doc/) package. \n",
"Below is our first simulated $X\\sim U(0,1)$ random variable. "
]
},
Expand All @@ -52,9 +54,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The function np.random.uniform can be supplied two parameters, a lower limit and an upper limit, which are by default set to $0$ and $1$. Above you can enter these parameter to produce instead a uniformly distributed real number between for instance $-1$ and $4$ by entering $-1, 4$ in the brackets. \n",
"The function `np.random.uniform` can be supplied two parameters, a lower limit ($\\alpha$) and an upper limit ($\\beta$), which are by default set to $0$ and $1$. You can enter these parameter to produce a uniformly distributed real number between $\\alpha$ and $\\beta$. For instance, you can produce a uniformly distributed real number between $-1$ and $4$ using the following line of code:\n",
"\n",
"We can use this uniformly distributed random variable to simulate various other distributions. For instance we may simulate a six sided die:"
"```python\n",
"np.random.uniform(-1,4)\n",
"```\n",
"\n",
"We can use this uniformly distributed random variable to simulate various other distributions. For instance we may simulate a six-sided die:"
]
},
{
Expand All @@ -72,9 +78,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Indeed in the code above we randomly generate a uniformly distributed number between 1 and 7 then round down to the nearest integer, which produces a(n ideal) die. You may want to try to change the code to simulate a $4$ or $8$ sided die. \n",
"Indeed in the code above we randomly generate a uniformly distributed number between $1$ and $7$ then round down to the nearest integer, which produces a(n ideal) die. You may want to try to change the code to simulate a $4$ or $8$ sided die. \n",
"\n",
"Very often we will need to simulate not one die, but many dice at the same time. The third parameter of the uniform distribution is the size. We may use this parameter to produce an array of many random numbers at once. Each random number is independently uniformly distributed. \n",
"\n",
"Very often we will need to simulate not one die, but many dice at the same time. The third parameter of the uniform distribution is the size. We may use this parameter to produce an array of many random numbers at once. Each random number is independently uniformly distributed. "
"The code below simulates rolling a six-sided die ten times."
]
},
{
Expand Down Expand Up @@ -117,7 +125,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally we can now simulate not just individual die rolls, but also sums of dice rolls leading to simulations of non-uniformly distributed random variables. For example below we simulate many rolls of a pair of $4$ sided die rolls and check that we obtain the expected distribution of sums. "
"Finally we can now simulate not just individual die rolls, but also sums of dice rolls leading to simulations of non-uniformly distributed random variables. For example, below we simulate many rolls of a pair of four-sided die rolls and check that we obtain the expected distribution of sums. "
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions book/simulation/overview.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Simulation
<!-- TODO: Give an intro to the chapter, explain a bit what simulation is/how it relates to the Prob Stat course -->

This is the file simulation/overview.md .

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

## Chapter Overview
<!-- TODO: Explain subsections contained in this chapter -->