Skip to main content

A Python library for Monte Carlo N-dimensional integration

Project description

Evaluating N-Dimensional Integration with Monte Carlo Methods

Mathematical Basis

Another problem which can be solved using Monte Carlo's method is numerical integration. From the definition of the average of a function we have:

$$\langle f(x) \rangle = \frac{1}{b-a} \int_a^b f(x) dx$$

which can be rearranged as:

$$\int_a^b f(x) dx = (b-a) \langle f(x) \rangle$$

From this, we can conclude that with a large number of random points, we can approximate the value of the integral. If we have a function $f(x)$ and want to evaluate the integral from $a$ to $b$, we:

  • Generate a large number of random points in the interval $[a,b]$
  • Calculate the average value of $f(x)$ at these random points
  • = Multiply this average by the length of the interval $(b-a)$

Extension to Higher Dimensions

This concept extends to 2D, 3D, and higher dimensional integrals:

For a 2D integral:

$$\langle f(x,y) \rangle = \frac{1}{b_x-a_x} , \frac{1}{b_y-a_y} , \int_{a_y}^{b_y} \int_{a_x}^{b_x} f(x,y) , dx , dy$$

Rearranged as:

$$\int_{a_y}^{b_y} \int_{a_x}^{b_x} f(x,y) , dx , dy = (b_x-a_x)(b_y-a_y) \langle f(x,y) \rangle$$

For a 3D integral:

$$\int_{a_z}^{b_z} \int_{a_y}^{b_y} \int_{a_x}^{b_x} f(x,y,z) , dx , dy , dz = (b_x-a_x)(b_y-a_y)(b_z-a_z) \langle f(x,y,z) \rangle$$

A general pattern emerges for $N$-dimensional integrals:

$$\int_{a_N}^{b_N} \cdots \int_{a_2}^{b_2} \int_{a_1}^{b_1} f(x_1, x_2, \ldots, x_N) , dx_1 , dx_2 , \ldots , dx_N = \left[\prod_{i=1}^N (b_i-a_i) \right] \cdot \langle f(x_1,x_2, \ldots, x_N) \rangle$$

What's impressive is that the difficulty of integrating a higher-order integral doesn't increase significantly with Monte Carlo methods, making it suitable for complex integrals.

License

This project is licensed under the GNU GPLv3.

  • You must:
    • Disclose source code for derivative works.
    • License derivatives under GPL-3.0.
  • Commercial use: Allowed, but derivatives must remain open-source.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onsi_mc-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onsi_mc-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file onsi_mc-0.1.0.tar.gz.

File metadata

  • Download URL: onsi_mc-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.2 Windows/11

File hashes

Hashes for onsi_mc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6d5084162b1ac32a329c8614221903db52453c6c5831b90c75689559036dd3dd
MD5 793d17d0727a41f4dc365a7745fb5aa4
BLAKE2b-256 79d66aac44f4e6304920ac0bd9a7f9d04ad334b263795af3568ec3498cc6cc59

See more details on using hashes here.

File details

Details for the file onsi_mc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: onsi_mc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.2 Windows/11

File hashes

Hashes for onsi_mc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b8de836198392bb1a2a4708f1ea9ceb5654cfdb755051bb7cbbe62cfafc54ea
MD5 41598952d36b1eafa982b0d3ec18a2fb
BLAKE2b-256 ef2a32d31eb1731b3f5916d363e4d211a14813a496a6e9bb916df5b7a7e603ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page