Monte-Carlo Nystrom method in NumPy / PyTorch
Project description
Monte-Carlo Nystrom
Documentation: https://montecarlo-nystrom.readthedocs.io
Source Code: https://github.com/ultrasphere-dev/montecarlo-nystrom
Monte-Carlo Nystrom method in NumPy / PyTorch
Installation
Install this via pip (or your favourite package manager):
pip install montecarlo-nystrom
Usage
Solve integral equations of the second kind of the following form.
$\forall d \in \mathbb{N}.$
$\forall \Omega \in \mathbb{R}^d [\Omega \text{ is bounded Lipschitz}].$
$\forall p \in L^\infty(\Omega, {\mathbb{R}}_{\geq 0}) [\int_\Omega p(y) dy = 1].$
$\forall f, z \in L^2(\Omega,\mathbb{C}).$
$\forall k \in L^2(\Omega,L^2(\Omega,\mathbb{C}))$
$[z(y) + \int_\Omega k(y, y') z(y') p(y') dy' = f(y)].$
Let $N \in \mathbb{N}$, $(y_i)_{i=1}^N$ be i.i.d. samples drawn from $p$.
Let $(z_{N,i})_{i=1}^N$ be the solution of the linear system
$$ z_{N,i} + \frac{1}{N} \sum_{j=1}^N k(y_i, y_j) z_{N,j} = f(y_i) \quad i \in {1, \ldots, N} $$
and
$$ z_N(y) := f(y) - \frac{1}{N} \sum_{i=1}^N k(y, y_i) z_{N,i} \quad y \in \Omega $$
Then $z_N$ would approximate $z$ as $N \to \infty$.
The below example solves the case where $d = 1$, $\Omega = [0, 1]$, $p$ (random_samples) is the uniform distribution on $[0, 1]$, $k(x, y) = |x - y|^{-0.4}$ (kernel), and $f(x) = 1$ (rhs), and evaluates the solution at $x = (0.5,)$.
>>> import numpy as np
>>> from montecarlo_nystrom import montecarlo_nystrom
>>> rng = np.random.default_rng(0)
>>> def random_samples(n):
... return rng.uniform(0, 1, size=(n, 1))
>>> def kernel(x, y):
... return np.linalg.vector_norm(x - y, axis=-1) ** -0.4
>>> def rhs(x):
... x0 = x[..., 0]
... return np.ones_like(x0)
>>> z_N = montecarlo_nystrom(
... random_samples=random_samples,
... kernel=kernel,
... rhs=rhs,
... n=100,
... n_mean=10,
... )
>>> np.round(z_N(np.asarray((0.5,))), 6) # Evaluate at x=0.5
np.float64(0.272957)
References
- Feppon, F., & Ammari, H. (2022). Analysis of a Monte-Carlo Nystrom Method. SIAM J. Numer. Anal. Retrieved from https://epubs.siam.org/doi/10.1137/21M1432338
Contributors ✨
Thanks goes to these wonderful people (emoji key):
ultrasphere-dev 💻 🤔 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits
This package was created with Copier and the browniebroke/pypackage-template project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file montecarlo_nystrom-1.1.0.tar.gz.
File metadata
- Download URL: montecarlo_nystrom-1.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
847327384af73959b283256ca43d1839ab5d65fb18f91b01c7c2b1886fee598c
|
|
| MD5 |
182409c4dd731f7a4d06f3c4e8c8b089
|
|
| BLAKE2b-256 |
cd961bed7bef7e4d05f35b4c8952ed63fc18e2310eef975e9be105d97aab82bc
|
Provenance
The following attestation bundles were made for montecarlo_nystrom-1.1.0.tar.gz:
Publisher:
ci.yml on ultrasphere-dev/montecarlo-nystrom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
montecarlo_nystrom-1.1.0.tar.gz -
Subject digest:
847327384af73959b283256ca43d1839ab5d65fb18f91b01c7c2b1886fee598c - Sigstore transparency entry: 790215602
- Sigstore integration time:
-
Permalink:
ultrasphere-dev/montecarlo-nystrom@43a01bb398c722382f284085e28ebf493ac28bba -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ultrasphere-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@43a01bb398c722382f284085e28ebf493ac28bba -
Trigger Event:
push
-
Statement type:
File details
Details for the file montecarlo_nystrom-1.1.0-py3-none-any.whl.
File metadata
- Download URL: montecarlo_nystrom-1.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6dc6cef117b66b26e968ea032303d9fe8f7f1e3ae1890c388d7e54c936df37d
|
|
| MD5 |
b515846f4cddd76b98a2742488012631
|
|
| BLAKE2b-256 |
e059a075a8e669d06141297f575208ccb905700e4e57fcf210f0ee1b8f454c65
|
Provenance
The following attestation bundles were made for montecarlo_nystrom-1.1.0-py3-none-any.whl:
Publisher:
ci.yml on ultrasphere-dev/montecarlo-nystrom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
montecarlo_nystrom-1.1.0-py3-none-any.whl -
Subject digest:
c6dc6cef117b66b26e968ea032303d9fe8f7f1e3ae1890c388d7e54c936df37d - Sigstore transparency entry: 790215619
- Sigstore integration time:
-
Permalink:
ultrasphere-dev/montecarlo-nystrom@43a01bb398c722382f284085e28ebf493ac28bba -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ultrasphere-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@43a01bb398c722382f284085e28ebf493ac28bba -
Trigger Event:
push
-
Statement type: