The Mathematics of Sample Paths and Finite-Dimensional Distributions

Environment

Python 3.14.6, NumPy 2.4.6, SciPy 1.18.1, Matplotlib 3.11.2 (Jupyter Notebook).

This article is a rewrite of a post from around 2021, with calculations performed in the environment described above.

Overview

We study stochastic processes through sample paths and joint distributions at several times. The examples cover counting random-walk paths, calculating Brownian covariance, and a counterexample concerning path continuity.

This article corresponds to Chapter 1, “Foundations of Stochastic Processes,” of Theory and Practice of Stochastic Processes. It assumes basic knowledge of joint distributions and covariance. The references provide the proof of the extension theorem.

Preparation

Run the code cells in order. Round numerical values to three significant figures only for display.

Check the environment, import libraries, and configure plots
from pathlib import Path
from pprint import pprint
import platform

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import scipy
from scipy import stats
from IPython.display import Math, display
from matplotlib.ticker import FuncFormatter, MaxNLocator
from matplotlib_inline.backend_inline import set_matplotlib_formats

set_matplotlib_formats("svg")


def sig(value):
    # 表示だけを3桁に丸める。
    return "0" if value == 0 else format(float(value), "#.3g")


np.set_printoptions(formatter={"float_kind": sig})
plt.rcParams.update({"font.size": 10, "svg.fonttype": "none",
                     "axes.spines.top": False, "axes.spines.right": False})
cwd = Path.cwd()
base = cwd / "series/stochastic-processes/102" if (cwd / "pyproject.toml").exists() else cwd
image_dir = base / "102_nb_files"
image_dir.mkdir(parents=True, exist_ok=True)


def save(fig, name):
    fig.savefig(image_dir / name, format="svg", bbox_inches="tight",
                metadata={"Date": None})
    plt.show()
    plt.close(fig)


def ticks(ax, which="y"):
    for name in which:
        getattr(ax, name + "axis").set_major_formatter(
            FuncFormatter(lambda value, _: sig(value)))


print("カーネル: wa-src(3.14.6)")
print("Python:", platform.python_version())
print("NumPy:", np.__version__, "SciPy:", scipy.__version__)
print("Matplotlib:", matplotlib.__version__)
assert platform.python_version() == "3.14.6"
カーネル: wa-src(3.14.6)
Python: 3.14.6
NumPy: 2.4.6 SciPy: 1.18.1
Matplotlib: 3.11.2

1. A Sample Path Fixes the Outcome

A stochastic process $X_t(\omega)$ has two arguments: time $t$ and outcome $\omega$.

$$ \begin{aligned} t\text{ fixed}:&\quad \omega\longmapsto X_t(\omega)\quad\text{(random variable)},\\ \omega\text{ fixed}:&\quad t\longmapsto X_t(\omega)\quad\text{(sample path)}. \end{aligned} $$

Consider the random walk $S_n=\sum_{j=1}^{n}\xi_j$, $S_0=0$, whose independent increments $\xi_j$ take values $-1$ and $1$ with probability $1/2$ each. There are $2^3=8$ paths of three steps, each with probability $1/8$.

from itertools import product

# 増分を全列挙する。
steps = np.array(list(product([-1, 1], repeat=3)))
paths = np.column_stack([np.zeros(8, dtype=int), steps.cumsum(axis=1)])
pprint(paths)

fig, axes = plt.subplots(1, 2, figsize=(9, 3), layout="constrained")
axes[0].plot(np.arange(4), paths.T, "o-", alpha=0.350)
axes[0].plot(np.arange(4), paths[3], "o-", color="black", label="One outcome")
axes[0].set(xlabel="Time n", ylabel="S(n)", xticks=range(4))
axes[0].legend()
axes[1].hist(paths[:, 3], bins=np.arange(-4, 5, 2), weights=np.full(8, 1 / 8),
             rwidth=0.700)
axes[1].set(xlabel="S(3)", ylabel="Probability", xticks=[-3, -1, 1, 3])
ticks(axes[1])
save(fig, "01_paths_and_marginal.svg")
array([[ 0, -1, -2, -3],
       [ 0, -1, -2, -1],
       [ 0, -1,  0, -1],
       [ 0, -1,  0,  1],
       [ 0,  1,  0, -1],
       [ 0,  1,  0,  1],
       [ 0,  1,  2,  1],
       [ 0,  1,  2,  3]])

In Figure 1, several paths share an endpoint. The distribution on the right cannot recover the order of the preceding steps.

2. Finite-Dimensional Distributions Are Joint Distributions at Several Times

Choose any finite collection of times $t_1,\ldots,t_k$ and form the column vector

$$ \mathbf{X}_{\mathbf{t}}=(X_{t_1},\ldots,X_{t_k})^{\mathsf T} $$

The family of joint distributions of these vectors is called the finite-dimensional distributions. “Finite” refers to the number of selected times, not to the number of states.

We calculate the probability of $S_1=a$ and $S_3=b$ in the random walk. The first increment equals $a\in\{-1,1\}$ with probability $1/2$. If $+1$ occurs $r$ times in the remaining two steps, their sum is $r-(2-r)=2r-2$, so $r=(b-a+2)/2$. Independence gives

$$ \begin{aligned} \mathbb{P}(S_1=a,S_3=b) &=\mathbb{P}(S_1=a)\mathbb{P}(\xi_2+\xi_3=b-a)\\ &=\frac12\binom{2}{r}\left(\frac12\right)^r \left(\frac12\right)^{2-r} =\frac18\binom{2}{r}. \end{aligned} $$

The probability is $0$ unless $r$ belongs to $0,1,2$. With rows ordered as $a=-1,1$ and columns as $b=-3,-1,1,3$, the joint probabilities are

$$ \mathbf{P}=\frac18 \begin{bmatrix}1&2&1&0\\0&1&2&1\end{bmatrix}. $$

Adding the four entries in the first row gives $\mathbb{P}(S_1=-1)=(1+2+1+0)/8=1/2$. Adding the two entries in each column gives the probabilities $(1,3,3,1)/8$ for $S_3$. Summing over unwanted times in this way gives marginal distributions.

first, last = np.array([-1, 1]), np.array([-3, -1, 1, 3])
joint = np.array([[( (paths[:, 1] == a) & (paths[:, 3] == b)).mean()
                   for b in last] for a in first])
expected = np.array([[1, 2, 1, 0], [0, 1, 2, 1]]) / 8
np.testing.assert_allclose(joint, expected)
np.testing.assert_allclose(joint.sum(axis=0), stats.binom.pmf(np.arange(4), 3, 1 / 2))
np.testing.assert_allclose(joint.sum(axis=1), [1 / 2, 1 / 2])
pprint(joint)

fig, ax = plt.subplots(figsize=(6, 3), layout="constrained")
ax.imshow(joint, cmap="Blues", vmin=0, vmax=0.300)
for (i, j), value in np.ndenumerate(joint):
    ax.text(j, i, sig(value), ha="center", va="center")
ax.set(xticks=range(4), xticklabels=last, yticks=range(2), yticklabels=first,
       xlabel="S(3)", ylabel="S(1)", title="Joint probability")
save(fig, "02_joint_distribution.svg")
array([[0.125, 0.250, 0.125, 0],
       [0, 0.125, 0.250, 0.125]])

$$ \displaystyle \mathbb{P}(S_1=-1,S_3=1)=\frac18=0.125 $$

3. Identical One-Time Distributions Can Describe Different Processes

Compare independent $A_n\sim\operatorname{Bernoulli}(1/2)$ with $D_n=Z$, which uses a single $Z\sim\operatorname{Bernoulli}(1/2)$ at every time. Both have success probability $1/2$ at each time. However, with rows corresponding to the time-1 values $0,1$ and columns to the time-2 values $0,1$,

$$ \mathbf{P}_A=\begin{bmatrix}1/4&1/4\\1/4&1/4\end{bmatrix},\qquad \mathbf{P}_D=\begin{bmatrix}1/2&0\\0&1/2\end{bmatrix}. $$

Independence gives $\mathbb{P}(A_1=1,A_2=1)=(1/2)(1/2)=1/4$. Reusing the same $Z$ gives $\mathbb{P}(D_1=1,D_2=1)=\mathbb{P}(Z=1)=1/2$. Therefore,

$$ \begin{aligned} \operatorname{Cov}(A_1,A_2)&=1/4-(1/2)(1/2)=0,\\ \operatorname{Cov}(D_1,D_2)&=1/2-(1/2)(1/2)=1/4. \end{aligned} $$

Each row in Figure 3 is one path. The time average of $D_n$ is either $0$ or $1$, rather than its expectation $1/2$ at each time.

rng = np.random.default_rng(102)
independent = rng.binomial(1, 0.500, size=(4000, 40))
shared = np.repeat(rng.binomial(1, 0.500, size=(4000, 1)), 40, axis=1)
fig, axes = plt.subplots(1, 2, figsize=(9, 3), layout="constrained")
for ax, values, title in zip(axes, [independent, shared], ["Independent A(n)", "Shared D(n)"]):
    ax.imshow(values[:12], aspect="auto", cmap="Blues", vmin=0, vmax=1,
              extent=[0.500, 40.5, 12.5, 0.500])
    ax.set(title=title, xlabel="Time n (white: 0, blue: 1)", ylabel="Path index")
    ax.yaxis.set_major_locator(MaxNLocator(integer=True))
save(fig, "03_same_marginals.svg")

4. The Finite-Dimensional Distributions of Brownian Motion

Consider standard Brownian motion $W_t$. If $0\le s\le t$, then $W_t=W_s+(W_t-W_s)$. The variables $W_s$ and $W_t-W_s$ are independent and both have mean $0$. Thus,

$$ \begin{aligned} \operatorname{Cov}(W_s,W_t) &=\mathbb{E}[W_sW_t]\\ &=\mathbb{E}[W_s^2]+\mathbb{E}[W_s(W_t-W_s)]\\ &=s+\mathbb{E}[W_s]\mathbb{E}[W_t-W_s]=s. \end{aligned} $$

Covariance is symmetric when $s>t$ as well, so in general $\operatorname{Cov}(W_s,W_t)=\min(s,t)$.

Write $0=t_0<t_1<\cdots<t_k$ and $\Delta t_j=t_j-t_{j-1}$. Adding the independent increments $\Delta W_j\sim\mathcal{N}(0,\Delta t_j)$ gives

$$ \mathbf{W}_{\mathbf{t}}\sim\mathcal{N}_k(\mathbf{0},\mathbf{K}),\qquad K_{ij}=\min(t_i,t_j). $$

This is a linear transformation of a Gaussian vector and therefore has a multivariate normal distribution. For a general process, the mean and covariance do not determine the distribution.

For times $(1/4,1/2,1)$, the covariance matrix is

$$ \mathbf{K}=\begin{bmatrix} 1/4&1/4&1/4\\1/4&1/2&1/2\\1/4&1/2&1 \end{bmatrix}. $$

The joint density also follows from the increments. Set $x_0=0$ and transform increments into positions by $x_j=\sum_{i=1}^{j}d_i$. The transformation matrix is lower triangular with all diagonal entries equal to $1$, so the absolute Jacobian is $1$. Multiplying the independent increment densities therefore gives

$$ f_{\mathbf{t}}(x_1,\ldots,x_k) =\prod_{j=1}^{k}\frac{1}{\sqrt{2\pi\Delta t_j}} \exp\left[-\frac{(x_j-x_{j-1})^2}{2\Delta t_j}\right] $$

The following code generates values at three times from the increments.

times = np.array([1 / 4, 1 / 2, 1])
delta = np.diff(np.r_[0, times])
w = rng.normal(size=(20000, 3)) * np.sqrt(delta)
w = w.cumsum(axis=1)
kernel = np.minimum.outer(times, times)
estimated = np.cov(w, rowvar=False)
pprint({"理論共分散": kernel, "標本共分散": estimated})
# 共分散の2通りの計算を照合する。
lower = np.tril(np.ones((3, 3)))
np.testing.assert_allclose(lower @ np.diag(delta) @ lower.T, kernel)

fig, ax = plt.subplots(figsize=(6, 4), layout="constrained")
ax.scatter(w[:2000, 0], w[:2000, 2], s=4, alpha=0.200)
xx, yy = np.meshgrid(np.linspace(-2, 2, 120), np.linspace(-4, 4, 120))
covariance = kernel[np.ix_([0, 2], [0, 2])]
density = stats.multivariate_normal.pdf(np.dstack([xx, yy]), mean=[0, 0], cov=covariance)
ax.contour(xx, yy, density, levels=[0.0200, 0.0800, 0.200, 0.300], colors="black")
ax.set(xlabel="W(0.250)", ylabel="W(1)", title="Samples and theoretical density")
ticks(ax, "xy")
save(fig, "04_brownian_joint.svg")
{'標本共分散': array([[0.249, 0.248, 0.248],
       [0.248, 0.504, 0.509],
       [0.248, 0.509, 1.02]]),
 '理論共分散': array([[0.250, 0.250, 0.250],
       [0.250, 0.500, 0.500],
       [0.250, 0.500, 1.00]])}

$$ \displaystyle \det\mathbf{K}=\frac14\cdot\frac14\cdot\frac12=\frac1{32} $$

Figure 4 shows pairs at times $0.250$ and $1$. They are correlated because they share increments. The sample covariance has finite-sample error, while the theoretical formula follows from the calculation above.

5. Consistency and Path Continuity

Removing a time must agree with marginalization, and reordering times must agree with reordering coordinates. These requirements are called consistency. When densities exist, for example,

$$ f_{t_1,t_3}(x_1,x_3)=\int_{\mathbb{R}} f_{t_1,t_2,t_3}(x_1,x_2,x_3)\,dx_2 $$

For real-valued processes, Kolmogorov’s extension theorem guarantees a process when consistent distributions are given for every finite set of times. Its law is unique on the product $\sigma$-algebra of $\mathbb{R}^{T}$: the events generated by finite-time observation conditions. This does not guarantee continuous paths. See Chapter 2 of Shalizi’s notes .

Let $U\sim\operatorname{Uniform}(0,1)$ and define, for $t\in[0,1]$,

$$ X_t=0,\qquad Y_t=\mathbf{1}_{\{t=U\}} $$

For any fixed $t$, we have $\mathbb{P}(U=t)=0$. For any finite collection of fixed times,

$$ \mathbb{P}\bigl(\exists j:Y_{t_j}\ne0\bigr) =\mathbb{P}\bigl(U\in\{t_1,\ldots,t_k\}\bigr) \le\sum_{j=1}^{k}\mathbb{P}(U=t_j)=0. $$

Thus $X$ and $Y$ have the same finite-dimensional distributions. Yet every path of $X$ is continuous, whereas every path of $Y$ is discontinuous at time $U$.

u = rng.uniform()
grid = np.linspace(0, 1, 11)
fig, axes = plt.subplots(1, 2, figsize=(9, 3), layout="constrained")
axes[0].plot([0, 1], [0, 0], color="C0")
axes[0].scatter([u], [0], facecolors="white", edgecolors="C0", zorder=3)
axes[0].scatter([u], [1], color="C1", zorder=3)
axes[0].annotate("Y(U) = 1", (u, 1), xytext=(0.100, 0.750),
                 arrowprops={"arrowstyle": "->"})
axes[0].set(title="One path: zero except at U")
axes[1].scatter(grid, (grid == u).astype(int), color="C0")
axes[1].set(title="Values on a fixed observation grid")
for ax in axes:
    ax.set(xlabel="Time t", ylabel="Y(t)", ylim=(-0.100, 1.20), yticks=[0, 1])
    ticks(ax, "x")
save(fig, "05_random_spike.svg")

Figure 5 explicitly plots $Y_U=1$. A fixed grid misses this single point almost surely. The figure is schematic: a finite-precision random experiment cannot prove a probability of $0$.

The following two statements can both hold:

$$ \begin{aligned} &\text{each }t:\quad\mathbb{P}(X_t=Y_t)=1,\\ &\mathbb{P}(X_t=Y_t\text{ for all }t)=0. \end{aligned} $$

The first relation makes the processes modifications of each other. They are indistinguishable if the probability in the second relation is $1$. For an uncountable set of times, “probability one at each time” cannot be interchanged with “probability one simultaneously at all times.” If both processes have continuous paths, agreement at rational times extends to all times. See Chapter 7 of Shalizi’s notes .

This example does not contradict uniqueness on the product $\sigma$-algebra. To discuss continuity, we must also specify a path space and its measurable events.

Conclusion

This article examined sample paths and finite-dimensional distributions through counting, covariance calculations, and a counterexample concerning continuity.

One-time distributions do not determine dependence. Finite-dimensional distributions require consistency, and path continuity needs a separate check. Distinguishing properties on a grid from properties of the entire path helps avoid confusion.

References

  • Shalizi, C. R., Stochastic Processes, Chapter 2 (linked above): finite-dimensional distributions, consistency, and the extension theorem.
  • The same notes, Chapter 7 (linked above): modifications, indistinguishability, and path continuity.