Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pietrozanotta/montpy
Python library implementing Monte Carlo and Quasi-Monte Carlo methods for integral evaluation
https://github.com/pietrozanotta/montpy
Last synced: 1 day ago
JSON representation
Python library implementing Monte Carlo and Quasi-Monte Carlo methods for integral evaluation
- Host: GitHub
- URL: https://github.com/pietrozanotta/montpy
- Owner: PietroZanotta
- License: mit
- Created: 2024-04-07T11:00:48.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-03T19:43:55.000Z (8 months ago)
- Last Synced: 2024-11-21T20:03:07.719Z (about 1 month ago)
- Language: Python
- Homepage: https://pypi.org/project/montpy/
- Size: 41 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Montpy: Montecarlo and Quasi-Montecarlo Integration Library
This Python library provides implementations of Monte Carlo and Quasi-Monte Carlo methods for evaluating integrals. Monte Carlo methods are stochastic techniques based on random sampling, while Quasi-Monte Carlo methods use low-discrepancy sequences for sampling. These methods are particularly useful for high-dimensional integrals where other numerical methods may struggle.
## Installation
You can install the library via pip:
```{bash}
pip install montpy
```## Usage
```{Python}
from montpy.mc import MonteCarloSolver, ImportanceSampler
from montpy.qmc import QuasiMonteCarloSolver# Define the function to integrate
def f(samples):
x, y = samples.T
return x**2 + y**2
# Define the domain (multivariate case)
domain = [(0, 1), (0, 1)]# Create the Monte Carlo solver (uniform distribution)
solver_mc = ImportanceSampler(f, domain)
integral_mc = solver_mc.integrate(num_samples=1000)
print("Estimated integral with Monte Carlo:", integral_mc)# Define the function to integrate
def g(x, y):
return x*y
# Create the Quasi-Monte Carlo solver
solver_qmc = QuasiMonteCarloSolver(g, domain)# Perform integration using Sobol sequence
integral_sobol = solver_qmc.integrate_sobol(num_samples=1000)
print("Estimated integral with Sobol sequence:", integral_sobol)
```## Contributing
Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request on GitHub.## License
This library is licensed under the MIT License. See the [LICENSE](https://github.com/ScipioneParmigiano/montpy/blob/main/LICENSE) file for details.