Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Homogeneous Spatial Poisson Process — From Scratch and With NumPyro

Open In Colab

A homogeneous spatial Poisson process (also called Complete Spatial Randomness, or CSR) on a domain D⊂RdD \subset \mathbb{R}^d with intensity λ>0\lambda > 0 has

  • count N(D)∼Poisson(λ∣D∣)N(D) \sim \mathrm{Poisson}(\lambda |D|),

  • conditional locations i.i.d. uniform on DD given the count,

  • joint log-likelihood log⁡L=nlog⁡λ−λ∣D∣−nlog⁡∣D∣\log L = n \log \lambda - \lambda |D| - n \log |D|.

It is the null model of spatial statistics: any departure from CSR (clustering, regularity) is the interesting bit. This notebook walks through both faces of xtremax for the spatial HPP.

  1. From scratch — work with the pure-JAX primitives (hpp_spatial_log_prob, hpp_spatial_sample, csr_ripleys_k).

  2. With NumPyro — wrap the same process as a numpyro.distributions.Distribution and run NUTS to recover λ\lambda from data.

Setup

/home/azureuser/localfiles/xtremax/.venv/bin/python: No module named pip
Note: you may need to restart the kernel to use updated packages.
/home/azureuser/localfiles/xtremax/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

1. From scratch — the primitives layer

xtremax.point_processes.primitives ships the spatial HPP as a set of pure JAX functions. Every call takes arrays and a RectangularDomain and returns arrays — no classes, no framework. That’s enough to sample, score, and visualise the process across d∈{1,2,3}d \in \{1, 2, 3\}.

2-D pattern: a square plot

Drew 39 points (uncapped Poisson draw was 39).
|D| = 100.0, so E[N] = λ |D| = 50.0.

Plot the realisation. Padding rows are kept inside the domain (set to domain.lo) but masked out — only the real events show up.

<Figure size 500x500 with 1 Axes>

Log-likelihood

The joint log-likelihood factorises into a Poisson count term plus an iid-uniform location density:

log⁡L=nlog⁡λ−λ∣D∣⏟count  − nlog⁡∣D∣⏟uniform locations.\log L = \underbrace{n \log \lambda - \lambda |D|}_{\text{count}} \,\, \underbrace{-\, n \log |D|}_{\text{uniform locations}}.
log L(39 events | λ=0.5, |D|=100.0) = -256.6344

Theoretical second-order summaries

Under CSR every closed-form summary has a tidy expression in terms of the spatial dimension dd. Ripley’s KK-function K(r)=VdrdK(r) = V_d r^d where VdV_d is the unit-ball volume; Besag’s LL-function L(r)=(K/Vd)1/d=rL(r) = (K/V_d)^{1/d} = r identically; the pair correlation g(r)≡1g(r) \equiv 1. Empirical departures from these flat references diagnose clustering (K(r)>VdrdK(r) > V_d r^d, L(r)>rL(r) > r) or regularity (K(r)<VdrdK(r) < V_d r^d, L(r)<rL(r) < r).

<Figure size 1000x350 with 2 Axes>

Same primitives, d∈{1,2,3}d \in \{1, 2, 3\}

Nothing in the API changes when we move to 3-D. The intensity and the closed-form summaries scale generically.

d=1: |D|=4.0, sampled 3 pts, E[NN dist] under CSR = 0.833
d=2: |D|=16.0, sampled 10 pts, E[NN dist] under CSR = 0.645
d=3: |D|=64.0, sampled 36 pts, E[NN dist] under CSR = 0.657

2. With NumPyro — Bayesian inference for the rate

The same process wraps trivially as a NumPyro Distribution. We can recover the unknown λ\lambda from a single observed pattern using NUTS.

Observed 44 points in a 100 m² plot

                mean       std    median      5.0%     95.0%     n_eff     r_hat
      rate      0.45      0.06      0.45      0.35      0.56    401.03      1.00

Number of divergences: 0

Posterior over λ\lambda should concentrate around the true value, especially for moderate counts (the precision is ∼1/n\sim 1/\sqrt{n} on the log-rate).

<Figure size 800x400 with 1 Axes>
Posterior mean: 0.450, true: 0.5

Where to go from here

  • Inhomogeneous case. Drop the constant λ\lambda and let intensity vary across space — the Inhomogeneous Spatial PP notebook covers thinning samplers, quadrature for Λ(D)\Lambda(D), and posterior inference over a Gaussian-bump intensity field.

  • Marked patterns. Pair each location with a magnitude or category — the Marked Spatial PP notebook walks through the separable factorisation λ(s,m)=λ(s)f(m∣s)\lambda(s, m) = \lambda(s) f(m | s) for tree diameters, earthquake magnitudes, and similar applications.