Skip to main content

Monte-Carlo Nystrom

CI Status Documentation Status

Test coverage percentage uv Ruff prek

PyPI Version Supported Python versions License


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

Metadata

Release files for montecarlo-nystrom 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for montecarlo-nystrom 1.2.0
File Size Uploaded Provenance Actions
montecarlo_nystrom-1.2.0.tar.gz 8.4 kB With provenance Details for montecarlo_nystrom-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for montecarlo-nystrom 1.2.0
File Interpreter ABI Platform Actions
montecarlo_nystrom-1.2.0-py3-none-any.whl Python 3 none any Details for montecarlo_nystrom-1.2.0-py3-none-any.whl

Total release size: 17.0 kB

Release files / montecarlo_nystrom-1.2.0.tar.gz

Download URL montecarlo_nystrom-1.2.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5f74d270803570876c417345f7198cccbe043d3d7489b64f1ebd05f427d9b68b
BLAKE2b-256 checksum
How to use checksums
e0333f95e740632855b9f5ef534f23cacf9f0c78eb890ff4fbc85303ebcbcefb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / montecarlo_nystrom-1.2.0-py3-none-any.whl

Download URL montecarlo_nystrom-1.2.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12264a16b3c04e82fa96f7180289b2fbba55f1308d3a1bab99fa0fcc40a0817b
BLAKE2b-256 checksum
How to use checksums
cc82f77c2711e0c55b0ee84300dcee995ea6cbea49fed4cca389932b44c1a1aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Security for montecarlo-nystrom 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for montecarlo_nystrom-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page