Skip to main content

Rare-event simulation for random geometric graphs via importance sampling

Project description

pyregg

Rare-event simulation for random geometric graphs.

pyregg estimates the probability of rare events in Gilbert random geometric graphs using three estimators: Naïve Monte Carlo (NMC), Conditional Monte Carlo (CMC), and Importance Sampling (IS).

Installation

pip install pyregg

Rare Events

Module Rare Event
pyregg.ec Edge count ≤ ℓ
pyregg.md Maximum degree ≤ ℓ
pyregg.mcc Maximum connected component size ≤ ℓ
pyregg.ntg Number of triangles ≤ ℓ
pyregg.mcs Maximum clique size ≤ ℓ
pyregg.planar Graph is planar
pyregg.forest Graph is a forest (acyclic)

Quick Start

Each module is directly callable with an optional method argument ('ismc' by default). All calls return (probability, rel_variance, n_samples).

import pyregg.ec as ec

# Estimate P(EC(G(X)) ≤ 15) on [0,10]² with κ=0.3, r=1
Z, RV, n = ec(wind_len=10, kappa=0.3, int_range=1.0, level=15)
print(f"P ≈ {Z:.4e}  (relative variance {RV:.2f},  {n} samples)")
import pyregg.planar as planar

# Estimate P(G(X) is planar) on [0,10]² with κ=1.2, r=1
Z, RV, n = planar(wind_len=10, kappa=1.2, int_range=1.0)
print(f"P ≈ {Z:.4e}  (relative variance {RV:.2f},  {n} samples)")
import pyregg.forest as forest

# Estimate P(G(X) is a forest) on [0,10]² with κ=0.3, r=1
Z, RV, n = forest(wind_len=10, kappa=0.3, int_range=1.0)
print(f"P ≈ {Z:.4e}  (relative variance {RV:.2f},  {n} samples)")

API

Calling a module

module(wind_len, kappa, int_range, [level,] method='ismc', **kwargs)

method selects the estimator: 'ismc' (Importance Sampling, default), 'cmc' (Conditional Monte Carlo), or 'nmc' (Naïve Monte Carlo). **kwargs are forwarded to the chosen estimator (e.g. grid_res, tol).

The three estimators are also available as named functions: module.naive_mc(...), module.conditional_mc(...), module.importance_sampling(...).

Common parameters

Parameter Description
wind_len Side length of the square window [0, wind_len
kappa Intensity of the Poisson point process (points per unit area)
int_range Connection radius — two points are connected if their distance ≤ int_range
level Threshold ℓ (not used for planar or forest)
method Estimator: 'ismc' (default), 'cmc', or 'nmc'
grid_res IS grid cells per interaction-range interval; total cells = (wind_len / int_range × grid_res)² (IS only, default 10)
max_iter Maximum number of samples (default 10⁸)
warm_up Minimum samples before checking convergence
tol Stop when relative variance / n < tol (default 0.001)

Estimators

'ismc' (default) — Sequential point addition with cells that would violate the rare event blocked; likelihood-ratio correction ensures unbiasedness.

'cmc' — Sequential point addition with analytic conditioning at each step.

'nmc' — Independent realisations; fraction satisfying the rare event.

Dependencies

Python  >= 3.10
NumPy   >= 1.24
SciPy   >= 1.10
Numba   >= 0.57
NetworkX >= 3.0

References

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

pyregg-0.2.11.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

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

pyregg-0.2.11-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

Details for the file pyregg-0.2.11.tar.gz.

File metadata

  • Download URL: pyregg-0.2.11.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pyregg-0.2.11.tar.gz
Algorithm Hash digest
SHA256 74bb292932a10199370c373e0fe126f0abc753f5cb0b9c3bdfc3f89b705cb4bf
MD5 82787f3ced0b52b24a67eeeb62144e76
BLAKE2b-256 1ed1be0e39622a7072b4eb430df4d793fa06fb59281eb05f997c708ec27b6950

See more details on using hashes here.

File details

Details for the file pyregg-0.2.11-py3-none-any.whl.

File metadata

  • Download URL: pyregg-0.2.11-py3-none-any.whl
  • Upload date:
  • Size: 51.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pyregg-0.2.11-py3-none-any.whl
Algorithm Hash digest
SHA256 ee457b9416bd35a1b48af0e26b4869f6fdabbc2c80946b6359d2950772b8cc9c
MD5 31c0670830d0c2254e06e87c81c6e7c9
BLAKE2b-256 6a8a07c248685524d8542b93c4b754de91e0b8358700ec0867b5106951e89082

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