A simple example of Monte Carlo estimation of pi using geometric sampling.
- Estimate pi using random points inside a square and inscribed circle.
- Two implementations:
- Pure Python for-loop based (
generate_estimates_for_loop
) - Vectorized Polars lazy-frame based (
generate_estimates_polars
)
- Pure Python for-loop based (
- Easy creation of interactive scatter plots showing pi convergence.
- Simple wrapper functions for quick experiments.
cd C:/path/to/install/directory
git clone https://github.com/cooper-goodman/monte-carlo-example.git
cd monte-carlo-example
This project was built with pixi a modern python package manager.
If pixi
is installed it should automatically detect the pixi.toml
and download the necessary packages.
cd "C:/path/to/install/directory/monte-carlo-example"
pixi install
Dependencies can also be installed with pip
.
pip install pandas shapely plotly polars pyarrow matplotlib