Simulating a homogeneous Poisson point process on a rectangle

This is the first of a series of posts about simulating Poisson point processes. I’ll start with arguably the simplest Poisson point process on two-dimensional space, which is the homogeneous one defined on a rectangle. Let’s say that we we want to simulate a Poisson point process with intensity \(\lambda>0\) on a (bounded) rectangular region, for example, the rectangle \([0,w]\times[0,h]\) with dimensions \(w>0\) and \(h>0\) and area \(A=wh\). We assume for now that the bottom left corner of the rectangle is at the origin.

Steps

Number of points

The number of points in the rectangle  \([0,w]\times[0,h]\) is a Poisson random variable with mean \(\lambda A\). In other words, this random variable is distributed according to the Poisson distribution with parameter \(\lambda A\), and not just \(\lambda\), because the number of points depends on the size of the simulation region.

This is the most complicated part of the simulation procedure. As long as your preferred programming language can produce (pseudo-)random numbers according to a Poisson distribution, you can simulate a homogeneous Poisson point process. There’s a couple of different ways used to simulate Poisson random variables, but we will skip the details. In MATLAB, it is done by using the poissrnd function with the argument \(\lambda A\). In R, it is done similarly with the standard  function rpois . In Python, we can use either the scipy.stats.poisson or numpy.random.poisson function from the SciPy or NumPy libraries.

Location of points

The points now need to be positioned randomly, which is done by using Cartesian coordinates. For a homogeneous Poisson point process, the \(x\) and \(y\) coordinates of each point are independent uniform points, which is also the case for the binomial point process, covered in a previous post. For the rectangle \([0,w]\times[0,h]\), the \(x\) coordinates are uniformly sampled on the interval \([0,w]\), and similarly for the \(y\) coordinates. If the bottom left corner of rectangle is located at the point \((x_0,y_0)\), then we just have to shift the random \(x\) and \(y\) coordinates by respectively adding \(x_0\) and \(y_0\).

Every scientific programming language has a random uniform number generator because it is the default random number generator. In MATLAB, R and SciPy, it is respectively rand, runif and scipy.stats.uniform.

Code

Here is some code that I wrote for simulating a homogeneous Poisson point process on a rectangle. You will notice that in all the code samples the part that simulates the Poisson point process requires only three lines of code: one line for the number of points and two lines lines for the \(x\) and \(y\) coordinates  of the points.

MATLAB
%Simulation window parameters
xMin=0;xMax=1;
yMin=0;yMax=1;
xDelta=xMax-xMin;yDelta=yMax-yMin; %rectangle dimensions
areaTotal=xDelta*yDelta;

%Point process parameters
lambda=100; %intensity (ie mean density) of the Poisson process

%Simulate Poisson point process
numbPoints=poissrnd(areaTotal*lambda);%Poisson number of points
xx=xDelta*(rand(numbPoints,1))+xMin;%x coordinates of Poisson points
yy=yDelta*(rand(numbPoints,1))+yMin;%y coordinates of Poisson points

%Plotting
scatter(xx,yy);
xlabel('x');ylabel('y');
R

Note: it is a bit tricky to write “<-” in the R code (as it automatically changes to the html equivalent in the HTML editor I am using), so I have usually used “=” instead of the usual “<-”.

#Simulation window parameters
xMin=0;xMax=1;
yMin=0;yMax=1;
xDelta=xMax-xMin;yDelta=yMax-yMin; #rectangle dimensions
areaTotal=xDelta*yDelta;

#Point process parameters
lambda=100; #intensity (ie mean density) of the Poisson process

#Simulate Poisson point process
numbPoints=rpois(1,areaTotal*lambda);#Poisson number of points
xx=xDelta*runif(numbPoints)+xMin;#x coordinates of Poisson points
yy=yDelta*runif(numbPoints)+yMin;#y coordinates of Poisson points

#Plotting
plot(xx,yy,'p',xlab='x',ylab='y',col='blue');
Python

Note: “lambda” is a reserved word in Python (and other languages), so I have used “lambda0” instead.

import numpy as np
import scipy.stats
import matplotlib.pyplot as plt

#Simulation window parameters
xMin=0;xMax=1;
yMin=0;yMax=1;
xDelta=xMax-xMin;yDelta=yMax-yMin; #rectangle dimensions
areaTotal=xDelta*yDelta;

#Point process parameters
lambda0=100; #intensity (ie mean density) of the Poisson process

#Simulate Poisson point process
numbPoints = scipy.stats.poisson( lambda0*areaTotal ).rvs()#Poisson number of points
xx = xDelta*scipy.stats.uniform.rvs(0,1,((numbPoints,1)))+xMin#x coordinates of Poisson points
yy = yDelta*scipy.stats.uniform.rvs(0,1,((numbPoints,1)))+yMin#y coordinates of Poisson points
#Plotting
plt.scatter(xx,yy, edgecolor='b', facecolor='none', alpha=0.5 )
plt.xlabel("x"); plt.ylabel("y")
Julia

After writing this post, I later wrote the code in Julia. The code is here and my thoughts about Julia are here.

Results

MATLAB

PoissonMatlab

R

PoissonR

Python

PoissonPython

Higher dimensions

If you want to simulate a Poisson point process in a three-dimensional box (typically called a cuboid or rectangular prism), you just need two modifications.

For a box \([0,w]\times[0,h]\times[0,\ell]\), the number of points now a Poisson random variable with mean \(\lambda V\), where \(V= wh\ell\) is the volume of the box. (For higher dimensions, you need to use $n$-dimensional volume.)

To position the points in the box, you just need an additional uniform variable for the extra coordinate. In other words, the \(x\), \(y\) and \(z\) coordinates are uniformly and independently sampled on the respective intervals \([0,w]\), \([0,h]\), \([0,\ell]\). The more dimensions, the more uniform random variables.

And that’s it.

Further reading

For simulation of point processes, see, for example, the books Statistical Inference and Simulation for Spatial Point Processes by Møller and Waagepetersen, or Stochastic Geometry and its Applications by Chiu, Stoyan, Kendall and Mecke.

There are books written by spatial statistics experts such as Stochastic Simulation by Ripley and Spatial Point Patterns: Methodology and Applications with R by Baddeley, Rubak and Turner, where the second book covers the spatial statistics R-package spatstat. Kroese and Botev also have a good introduction in the edited collection Stochastic Geometry, Spatial Statistics and Random Fields : Models and Algorithms by Schmidt, where the relevant chapter (number 12) is also freely available online.

More general stochastic simulation books that cover relevant material include Uniform Random Variate Generation by Devroye and Stochastic Simulation: Algorithms and Analysis by Asmussen and Glynn.

Point process simulation

Point processes are mathematical objects that can represent a collection of randomly located points on some underlying space. There is a rich range of these random objects, and, depending on the type of points process, there are various steps and methods used to sample, simulate or generate them on computers. (I use these three terms somewhat interchangeably.) This is the first of a series of posts in which I will describe how to simulate some of the more tractable point processes defined on bounded regions of two-dimensional Euclidean space.

Finite point processes

A general family of point processes are the finite point processes, which are, as the name suggests, simply point processes with the property that the total number of points is finite with probability one. Usually it is assumed that both the number of points and the positions of these points are random. These two properties give a natural way to describe and to study point processes mathematically, while also giving an intuitive way to simulate them on computers.

If the number and locations of points can be simulated sequentially, such that the number of points is naturally generated first followed by the placing of the points, then the simulation process is usually easier. Such a point process is a good place to start for an example.

Simple example — Binomial point process

The binomial point process is arguably the simplest point process. It is created by scattering \(n\) points uniformly and independently located in some bounded region, say, \(R\) with area \(|R|\). The number of points located in a region \(B\subset R\) is a binomial random variable, say, \(N\), where its probability parameter \(p=\frac{|B|}{|R|}\) is simply the ratio of the  two areas. This implies that

$$ P(N=k)={n\choose k} p^k(1-p)^{n-k}, $$

The total number of points is non-random number \(n\), so we do not need to generate it as it is given. The independence of point locations means that all the points can be positioned in parallel.

For example, to simulate \(n\) points of a binomial point process on the unit square \([0,1]\times[0,1]\), we just need to independently sample the \(x\) and \(y\) coordinates of the points from a uniform distribution on the unit interval \([0,1]\). In other words, we randomly generate or sample two sets of \(n\) uniform random variables corresponding to the \(x\) and \(y\) of the \(n\) points.

To sample on a general \(w \times h\) rectangle, we just need need to multiple the random \(x\) and \(y\) values by the respective dimensions of the rectangle \(w\) and \(h\). Of course the rectangle can also be shifted up or down by adding or subtracting \(x\) and \(y\) values appropriately.

Essentially every programming language has a function for generating uniform random numbers because it is the default random number generator, which all the other random number generators build off, by employing various techniques like applying transformations. In MATLAB, R and Python, it is respectively rand, runif and scipy.stats.uniform, which all generate uniform points on the open interval \((0,1)\).

Code

Here are some pieces of code that illustrates how to simulate a binomial point process on the unit square. I suggest downloading the code directly here from my repository. (Sometimes my webpage editor mangles simulation code.)

MATLAB

n=10; %number of points

%Simulate binomial point process
xx=rand(n,1);%x coordinates of binomial points
yy=rand(n,1);%y coordinates of binomial points

%Plotting
scatter(xx,yy);
xlabel('x');ylabel('y');

R

n=10; #number of points
#Simulate Binomial point process
xx=runif(n);#x coordinates of binomial points
yy=runif(n);#y coordinates of binomial points

#Plotting
plot(xx,yy,'p',xlab='x',ylab='y',col='blue');

Python

import numpy as np
import matplotlib.pyplot as plt

numbPoints = 10; # number of points

# Simulate binomial point process
xx = np.random.uniform(0, 1, numbPoints) # x coordinates of binomial points
yy = np.random.uniform(0, 1, numbPoints) # y coordinates of binomial points

# Plotting
plt.scatter(xx, yy, edgecolor='b', facecolor='none', alpha=0.5)
plt.xlabel('x')
plt.ylabel('y')
plt.show()

More complicated point processes

The binomial point process is very simple. One way to have a more complicated point process is to have a random number of points. The binomial point process is obtained from conditioning on the number of points of a homogeneous Poisson point process, implying its simulation builds directly off the binomial point process. The homogeneous Poisson point process is arguably the most used point process, and it is then in turned used to construct even more complicated points processes. This suggests that the homogeneous Poisson point process is the next point process we should try to simulate.

Further reading

For simulation of point processes, see, for example, the books Statistical Inference and Simulation for Spatial Point Processes by Møller and Waagepetersen, or Stochastic Geometry and its Applications by Chiu, Stoyan, Kendall and Mecke. There are books written by spatial statistics experts such as Stochastic Simulation by Ripley and Spatial Point Patterns: Methodology and Applications with R by Baddeley, Rubak and Turner, where the second book covers the spatial statistics R-package spatstat. Kroese and Botev also have a good introduction in the edited collection Stochastic Geometry, Spatial Statistics and Random Fields : Models and Algorithms by Schmidt, where the relevant chapter (number 12) is also freely available online. More general stochastic simulation books that cover relevant material include Uniform Random Variate Generation by Devroye and Stochastic Simulation: Algorithms and Analysis by Asmussen and Glynn.

For a mathematical introduction to finite point processes, see the standard reference An Introduction to the Theory of Point Processes by Daley and Vere-Jones (Chapter 5 in either the single-volume edition or the first volume of the second two-volume edition). Finite point processes are also covered in a recent tutorial on Palm calculus and Gibbs point processes.

Poisson point process

Balloons in scattered across a morning sky. Sand grains strewn on the ground. Seeds blown over a forest floor. Each of these phenomena can be represented mathematically as an object called a point process or random point field. Although it has a couple of mathematical interpretations, a point process is essentially just a collection of points randomly scattered on some mathematical space*, such as the real line, the Cartesian plane, a sphere, or more abstract spaces.

*The underlying mathematical space is sometimes called the carrier space or the state space, but the second term refers to something different from the state space used in the theory of stochastic processes.

The most important point process is the Poisson point process, which is one of the two most fundamental and studied mathematical objects in probability. (The other is the Wiener process or Brownian motion process, which is a type of random process or stochastic process, and it has been suggested by mathematicians such as John Kingman that the Poisson point process does not attract as much research attention as it should.) This point process can be defined on very general mathematical spaces, but usually the plane gives sufficient intuition. In this setting, each randomly located point can represent, for example, a star, a sand grain or a seed.

The most important defining property of the Poisson point process is that the numbers of points of the point process located in two (or more) non-overlapping (that is, disjoint) regions are two or more independent random variables. This property, sometimes called independent scattering or complete independence, explains the tremendous tractability of this point process, and it is used alongside the property that the random variables have Poisson distributions to define the Poisson point process.

To define a Poisson point process on some mathematical space, only a single mathematical object is needed. This object is applied to a region (or subset) of the underlying space on which the Poisson point process is defined, and returns a non-negative number. This object is a type of measure from measure theory, so it is called the mean measure or intensity measure. The mean measure can be interpreted as the mean or average number of points of a Poisson point process being located in a region of the underlying space.

Definition of a Poisson point process

A point process \(N\) defined on some underlying space \(S\) is a Poisson point process with intensity measure \(\Lambda\) if it has the two following properties:

1 The number of points in a bounded Borel set \(B \subset S\) is a Poisson random variable with mean \(\Lambda(B)\).

2 The number of points in \(n\) disjoint Borel sets forms \(n\) independent random variables.

A simple example of a mean measure of a Poisson point process is when the mean measure is given by the product of a non-negative constant and the area or volume of the region. The constant, often denoted by \(\lambda\), is known as the intensity or rate, which is often can be interpreted as the average density of points. In this setting, the average density does not vary over the underlying space, so the resulting point process is called a homogeneous Poisson point process or uniform Poisson point process, which is the simplest example of a Poisson point process.

If the intensity does change over the underlying space, meaning it is spatially dependent, then the terms inhomogeneous Poisson point process or nonhomogeneous Poisson point process are used. It is usually assumed that the intensity measure \(\Lambda\) has a derivative \(\lambda\), so it can be written as an integral:

$$\Lambda(B)=\int_B \lambda(x) dx, $$

where the set \(B\) is some subregion of the underlying state space \(S\). (As per standard probability assumptions, the set \(B\) has to be Borel measurable, but we do not focus on such details here.)

The Poisson point process is the cornerstone of fields where randomness meets geometry, such as spatial statistics, geometric probability and stochastic geometry. Researchers, scientists, and engineers have proposed using the Poisson point process to model various objects randomly positioned. In recent years, it has been used extensively to mathematically model the locations of transmitters and receivers in wireless communication networks such as cellular or mobile phone networks.

As a mathematical model, the Poisson point process should be used to represent objects or phenomena that have little or, ideally, zero interaction among the points. If that’s not the case, then the Poisson point process can also serve as a null-hypothesis model in statistics, whose rejection implies there is sufficiently strong interaction among the points. For example, the stars influence each other, undoubtedly, through gravity, and trees rely upon absorbing water in their vicinity through root systems, suggesting that non-Poisson models would be more suitable for representing these two examples. Other more sophisticated point processes that incorporate such point interaction have been developed. Many of these point processes build off the Poisson point process.

The Poisson point process is often called simply the Poisson process, where it can be confused with the related stochastic process of the same name. This Poisson process is a continuous-time discrete-valued stochastic process. The points in time where this stochastic process changes (or jumps) form the points of a Poisson point process on the real line. Depending on the literature, interpretation and preference, the Poisson point process is also called the Poisson random field and Poisson random measure.

The Poisson point process is a highly useful and used random object. But we now need to simulate it on a computer, which will be the subject of a future post.

Further reading

The Wikipedia article is a good starting point. The best book on the Poisson point process is the monograph Poisson Processes by Kingman. A recent and more theoretical book is Lecture Notes on the Poisson Process by Last and Penrose (the manuscript is freely available online here). More applied books include the classic Stochastic Geometry and its Applications by Chiu, Stoyan, Kendall and Mecke, and Statistical Inference and Simulation for Spatial Point Processes by Møller and Waagepetersen.

In recent years, there have been various books applying the Poisson point process to wireless networks, which include the two-volume Stochastic geometry and Wireless Networks by Baccelli and Błaszczyszyn, and Stochastic geometry for Wireless Networks by Haenggi. Much more recently, some colleagues and I contributed to this literature with Stochastic Geometry Analysis of Cellular Networks by Błaszczyszyn, Haenggi, Keeler, and Mukherjee.

An Improbable Start

This web log or blog, to the use parlance of our times, is a place for me to discuss and explains problems or research ideas that I am working on or just find interesting. The emphasis will be on words over equations, with the aim of trying to give an intuitive explanation for mathematical concepts encountered in applied probability.

Much of my work involves the use of random simulations, which are also called stochastic or Monte Carlo simulations, so I will often be posting on ideas illustrated with simulations. Most of my experience is using MATLAB, so that will be my default programming language, but I also have experience in the statistics-focused language R, which arguably has the best spatial statistics package spatstat going around. I also use Python coupled with appropriate libraries such as NumPy, especially for machine learning work.

I am considering learning other languages to do random simulation work. A possible candidate here is the relatively new Julia language, although nothing seems to compete against MATLAB in terms of user friendliness.

Feel free to contact me for questions or to point out mistakes. I do appreciate it. I may even reply.

Block arrivals in the Bitcoin blockchain

My collaborators and I recently uploaded a preprint:

  • Bowden, Keeler, Krzesinski, Taylor, Block arrivals in the Bitcoin blockchain, 2018.

The hint is in the title. In this work we study the arrivals of blocks in the Bitcoin blockchain by using both empirical (statistical) methods and mathematical (stochastic) models. To do this, we set up Bitcoin nodes around the world and collected blockchain mining data.

One of the main observations is that, according to standard tests, Bitcoin blocks do not arrive according to a Poisson stochastic process. The Poisson assumption, which seems very reasonable, appeared in the original white paper by the pseudonymous Satoshi Nakamoto:

  • Nakamoto, Bitcoin: A Peer-to-Peer Electronic Cash System, 2008.

Going back to our newly uploaded work, here’s the abstract giving some more details:

Bitcoin is a electronic payment system where payment transactions are verified and stored in a data structure called the blockchain. Bitcoin miners work individually to solve a computationally intensive problem, and with each solution a Bitcoin block is generated, resulting in a new arrival to the blockchain. The difficulty of the computational problem is updated every 2,016 blocks in order to control the rate at which blocks are generated. In the original Bitcoin paper, it was suggested that the blockchain arrivals occur according to a homogeneous Poisson process. Based on blockchain block arrival data and stochastic analysis of the block arrival process, we demonstrate that this is not the case. We present a refined mathematical model for block arrivals, focusing on both the block arrivals during a period of constant difficulty and how the difficulty level evolves over time.

This new work is a spiritual sequel to a paper that some of us published a couple of years ago:

  • Göbel, Keeler, Krzesinski, Taylor, Bitcoin Blockchain Dynamics: the Selfish-Mine Strategy in the Presence of Propagation Delay, 2016.

A preprint of this paper can be found here.