https://github.com/cheind/monte-carlo-integration
Theory and implementation of Monte Carlo integration techniques
https://github.com/cheind/monte-carlo-integration
monte-carlo-integration python theory
Last synced: 11 months ago
JSON representation
Theory and implementation of Monte Carlo integration techniques
- Host: GitHub
- URL: https://github.com/cheind/monte-carlo-integration
- Owner: cheind
- License: mit
- Created: 2022-06-24T03:41:42.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-21T09:25:06.000Z (almost 4 years ago)
- Last Synced: 2024-10-16T04:06:42.343Z (over 1 year ago)
- Topics: monte-carlo-integration, python, theory
- Language: Python
- Homepage:
- Size: 873 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://doi.org/10.5281/zenodo.7013396)
# Monte Carlo Integration
Theory and implementation of Monte Carlo integration in Python.
## Theory
See [docs/monte_carlo_integration.pdf](docs/monte_carlo_integration.pdf) for a write-up of my research notes.
## Example
Here is an example using indicator functions.
```python
import numpy as np
import mcintegration as mci
# Indicator function for being inside a unit sphere in R^N
i = lambda x: np.sum(x**2, -1) <= 1.0
# Area of unit circle in R^2
A_circle, err_one_sigma = mci.mcintegrate(
i,
lower=[-1.0] * 2,
upper=[1.0] * 2,
n=int(1e5),
)
print(A_circle, err_one_sigma)
# 3.1438 0.00129
# Volume of unit sphere in R^3
V_sphere, err_one_sigma = mci.mcintegrate(
i,
lower=[-1.0] * 3,
upper=[1.0] * 3,
n=int(1e5),
)
print(V_sphere, err_one_sigma)
# 4.1735 0.00157
```