These lecture notes are intended to cover some introductory topics in stochastic simulation for scientific computing courses offered by the IT department at Uppsala University, as taught by the author. Basic concepts in probability theory are provided in the Appendix A, which you may review before starting the upcoming sections or refer to as needed throughout the text.
Stochastic Simulation and Monte Carlo Method Paper ID : 2501.00997Title : Stochastic Simulation and Monte Carlo MethodAuthor : Davoud Mirzaei (Uppsala University)Classification : math.NA cs.NA stat.CO stat.OTPublication Date : November 1, 2024 (2nd Edition)Paper Link : https://arxiv.org/abs/2501.00997 This is a set of teaching lecture notes for the scientific computing course in the IT department at Uppsala University. The content covers introductory topics in stochastic simulation, including Monte Carlo methods, random variable generation, stochastic processes, and Markov Chain Monte Carlo (MCMC). Appendix A provides fundamental concepts in probability theory as the theoretical foundation for understanding subsequent chapters.
The lecture notes aim to address the selection and application of deterministic versus stochastic models in scientific computing:
Modeling Method Selection : How to choose appropriate methods between deterministic and stochastic modelingStochastic Simulation Techniques : How to efficiently generate and utilize random variables for complex system simulationParameter Estimation : How to conduct Bayesian parameter estimation in uncertain environmentsStochastic simulation holds important significance in modern scientific computing:
Real System Modeling : Many real-world systems contain inherent randomness and uncertaintyHigh-Dimensional Integration : Monte Carlo methods possess unique advantages in high-dimensional integrationComplex System Analysis : Complex systems such as biological systems, financial markets, and epidemic propagation require stochastic modelingDeterministic Methods : Cannot capture system stochastic fluctuations and uncertaintyTraditional Numerical Methods : Computational complexity grows dramatically for high-dimensional problemsParameter Estimation Challenges : Complex posterior distributions are difficult to compute directlySystematic Teaching Framework : Provides a complete pedagogical system from fundamental probability theory to advanced MCMC methodsPractical Algorithm Implementation : Presents Python implementations of key algorithms, including random variable generation, Gillespie algorithm, and MCMCMulti-Domain Application Examples : Covers applications in radioactive decay, epidemic propagation, financial option pricing, and biochemical reactionsTheory-Practice Integration : Organically combines mathematical theory with practical programming implementationThe lecture notes primarily address the following core tasks:
Random Variable Generation : Efficiently generate random samples from given distributionsMonte Carlo Integration : Compute complex integrals using random sampling methodsStochastic Process Simulation : Model Markov chains, Brownian motion, and other stochastic processesParameter Estimation : Conduct Bayesian parameter inference through MCMC methodsInverse Transform Method
# Basic idea: If U ~ U(0,1), then X = F^(-1)(U) ~ f
def inverse_transform_sampling(cdf_inverse, n):
U = np.random.uniform(0, 1, n)
return cdf_inverse(U)
Acceptance-Rejection Method
Use proposal distribution g(x) and constant C to bound target distribution f(x) Acceptance probability: α = min{f(X)/(Cg(X)), 1} Efficiency: P(acceptance) = 1/C Basic Monte Carlo Estimation
For integral I = ∫g(x)f(x)dx:
I ≈ (1/N) Σ g(xi), xi ~ f
Importance Sampling
I = ∫g(x)f(x)dx = ∫g(x)[f(x)/ℓ(x)]ℓ(x)dx
I ≈ (1/N) Σ g(xi)w(xi), xi ~ ℓ, w(xi) = f(xi)/ℓ(xi)
Markov Chain Generation
State transition matrix P = (pij) Stationary distribution π satisfies πP = π Brownian Motion Generation
# Wt+1 = Wt + √(Δt) * Z, Z ~ N(0,1)
def brownian_motion(t_vec, dim):
W = np.zeros([dim, len(t_vec)])
for k in range(len(t_vec)-1):
Z = np.random.normal(0, 1, dim)
dt = t_vec[k+1] - t_vec[k]
W[:, k+1] = W[:, k] + np.sqrt(dt) * Z
return W
Core Steps :
Compute total propensity function: a(y) = Σ wj(y) Generate waiting time: τ ~ Exp(a(y)) Select reaction: k ~ DD(1,...,m , p1,...,pm ) Update state: y ← y + vk Dimension-Independent Convergence : Monte Carlo convergence rate O(N^(-1/2)) is independent of dimensionAdaptive Sampling : Importance sampling improves efficiency through appropriate proposal distribution selectionStochastic Differential Equation Solving : Euler-Maruyama method for solving diffusion processesMCMC Convergence : Ensures convergence to target distribution through detailed balance equationsRadioactive Decay Model Deterministic model: dy/dt = -λy(t) Stochastic model: y →^λ z (Gillespie algorithm) SIR Epidemic Model States: S (susceptible), I (infected), R (recovered) Parameters: μ (birth-death rate), β (infection rate), γ (recovery rate) Financial Option Pricing Geometric Brownian motion: dSt = μStdt + σStdWt European call option: C0 = e^(-rT)Emax(ST-K, 0) Convergence Analysis : Error variation with sample size NConfidence Intervals : Error bounds at 95% probabilityComputational Efficiency : Algorithm runtime and memory usageVariance Comparison : Variance analysis across different sampling strategiesBasic MC Method : Convergence rate O(N^(-0.5))Importance Sampling : Significant precision improvement in rare event estimationExample : When estimating Φ(-4.5), importance sampling achieves 3-4 orders of magnitude higher precision than basic MCBrownian Particle : Expected time to hit boundary ≈ 0.4856 ± 0.0061Gambler's Ruin : High consistency between theoretical and simulation resultsOption Pricing : Black-Scholes model simulation result C0 ≈ 10.03 ± 0.29Recovery Rate Estimation : Posterior mean θ ≈ 0.1489 ± 0.0009Portfolio Risk : Large loss probability ≈ 1.08%Monte Carlo Error Bounds :
For estimator Y = (1/N)Σg(Xi):
Variance: Var(Y) = σ²/N 95% Confidence interval: μ ± 1.96σ/√N MCMC Diagnostics :
Burn-in period: Discard first 1000-2000 samples Autocorrelation analysis: Ensure sufficient sample mixing Monte Carlo Origins : Invented by von Neumann and Ulam during World War IIMetropolis Algorithm : Proposed by Metropolis et al. in 1953Hastings Extension : Hastings proposed asymmetric proposal distributions in 1970Gillespie Algorithm : Developed in 1977 for biochemical reaction network simulationLaw of Large Numbers : Guarantees consistency of Monte Carlo estimationCentral Limit Theorem : Provides asymptotic distribution of errorsMarkov Chain Theory : Theoretical foundation for MCMC convergenceMethod Applicability :Deterministic methods suitable for large systems and predictable behavior Stochastic methods suitable for small systems and uncertain environments Computational Efficiency :Monte Carlo possesses advantages for high-dimensional problems Importance sampling significantly improves rare event estimation precision Practical Value :Provides complete algorithm implementation framework Covers multiple important application domains Convergence Speed : Monte Carlo methods converge slowly, requiring large sample sizesVariance Control : Variance may be large for certain problems, affecting estimation precisionMCMC Diagnostics : Convergence diagnostics and burn-in period selection remain challengingAdvanced MCMC Methods : Hamiltonian Monte Carlo, variational inference, etc.Parallel Algorithms : Leverage modern computing architectures for efficiency improvementAdaptive Methods : Dynamically adjust sampling strategiesEducational Value :Clear structure with progressive advancement from basics to advanced topics Equal emphasis on theory and practice with complete code implementation Covers multiple application domains with strong practical utility Technical Completeness :Covers core stochastic simulation methods Provides convergence analysis and error estimation Includes modern MCMC methods Implementation Quality :Well-structured Python code, easy to understand and use Correct algorithm implementations, verified Provides visualization results Depth Limitations : As teaching material, certain advanced topics lack sufficient depthModern Methods : Lacks recent variational inference and deep learning-related methodsComputational Optimization : Limited discussion of parallel computing and GPU accelerationEducational Value : Provides high-quality resources for stochastic simulation teachingPractical Reference : Practical handbook for researchers and engineersCode Contribution : Provides reproducible algorithm implementationsTeaching Purposes : Scientific computing, statistics, and applied mathematics coursesResearch Applications : Bioinformatics, financial engineering, physics simulationEngineering Practice : Risk assessment, system simulation, optimization problemsThe lecture notes cite classical textbooks in the field:
DeGroot & Schervish: Probability and Statistics Ross: Simulation Rubinstein & Kroese: Simulation and the Monte Carlo Method Robert & Casella: Monte Carlo Statistical Methods Overall Assessment : This is a high-quality teaching material on stochastic simulation with strong systematicity and practical utility, providing learners with a complete learning pathway from theory to practice. While as teaching lecture notes it has certain limitations in cutting-edge methods, its educational and practical value are both high, making it an excellent reference resource in this field.