This repository contains an interactive application that demonstrates how Bayesian inference can be applied to estimate the bias of a coin based on a series of coin tosses. The application is built using Python and utilizes matplotlib widgets for interactivity.
Bayesian inference is a cornerstone of modern statistics and machine learning. This project showcases its power and simplicity by focusing on a classic example: estimating the bias
The project is both educational and interactive, making it an excellent resource for learners and enthusiasts who want to deepen their understanding of Bayesian concepts.
- Bayesian Update Rule: The application uses Bayes' Theorem to update the posterior probability density of the coin bias after each toss.
-
Interactive Features:
- Adjust the coin's bias
$\theta$ using a slider. - Toss the coin and watch the probability density function (PDF) update dynamically.
- Clear the experiment to start over.
- Adjust the coin's bias
-
Theoretical Foundation: The probability density follows a Beta distribution, which depends on the number of tosses
$n$ and the number of heads$k$ observed.
For more details, consult the theory document.
- Visualize the Bayesian updating process in real time.
- Experiment with different coin biases.
- Educational tool for learning Bayesian inference and the Beta distribution.
Ensure you have Python 3.8 or later installed. The required libraries are listed in requirements.txt.
- Clone the repository:
git clone https://github.com/cego669/CoinBiasExperiment.git cd CoinBiasExperiment - Install the dependencies:
pip install -r requirements.txt
- Run the application:
python coin_toss_experiment.py
The following Python libraries are required:
- matplotlib
- sympy
- numpy
- scipy
For a full list of dependencies and their versions, refer to requirements.txt.
- Use the slider to set the bias of the coin.
- Click "Toss next coin" to add a toss and observe the updated posterior distribution.
- Clear the experiment to reset.
For a detailed mathematical explanation of the Bayesian model and Beta distribution, refer to:
- Carlos Eduardo Gonçalves de Oliveira
- LinkedIn: linkedin.com/in/cego669
- GitHub: github.com/cego669
This project is licensed under the MIT License. See the LICENSE file for details.
