← Stochastic Differential Equations

10

Programming many independent SDE trajectories

Independent SDE paths turn possible histories into an empirical distribution. A two-dimensional NumPy array makes the ensemble structure explicit.

From one path to an ensemble

Suppose \(M\) independent paths are stored in a rectangular array. Row \(r\) is trajectory \(r\), and column \(n\) is time \(t_n\):

\[X_{r,n}\approx X_r(t_n).\]

Unlike CTMC paths, Euler–Maruyama paths already share the chosen numerical grid, so no separate alignment step is needed.

Independence in the code

At every time step, each path needs its own standard normal draw. The generator is created once before simulation. Reinitialising it with the same seed for each trajectory would create identical paths, not independent ones.

Interactive Python laboratory

Interactive PythonMany independent SIS SDE paths

Output

Run the code to see the result.

Vectorisation

current = I[:, n] selects all paths at one time. NumPy then calculates rates and updates for the whole ensemble together. This is usually clearer and faster than a nested Python loop.

AxisMeaning
axis=0Summarise down paths at each time.
axis=1Summarise across time within each path.

What the displays establish

The twenty path lines illustrate variability but are not the entire experiment. The histogram uses all 300 paths and describes the empirical distribution at one stated time. Neither alone is an uncertainty band; that is the next lesson.

What this lesson adds

You can now store an ensemble as a path-by-time array, generate independent Brownian draws, vectorise Euler–Maruyama, diagnose boundary corrections and distinguish illustrative paths from a full outcome distribution.