Lecture12 PDEsStochasticProcesses CMU
Lecture12 PDEsStochasticProcesses CMU
METHODS
AND APPLICATIONS
use random walks to solve PDEs solve PDEs to model random walks
where F is any function of the (unknown) function x(t) and its first n
derivatives in time.
e r i n s p ace,
“nth o r d dary condit
h o rd e r i n time” space & time un ion
mt o s
derivatives
b
of any order initial conditions
time
space
domain
solution
could be, e.g., +∞
boundary
Example—1D Heat Equation
Example. Heat equation on the real line: (no boundary conditions:
domain has no boundary)
n c a v e / c o n v e x
Intuition: co ed up/down
p s g e t p u s h
bum
– curl
– Laplacian
– …
• (Also helps to drop arguments…) heat equation (differential operator)
Review: Divergence, Gradient, and Curl
f X Y
Coordinates.
e.g., in 2D:
Differential operators.
Laplacian Gives Deviation from Local Average
More intuitively, can think of u(x) u(x0)
the Laplacian of a function u as
difference between value at a
point x0, and the average value
over a small sphere (or ball)
around x0.
Three basic types of behavior for PDEs, encapsulated by three model equations:
dent” “time-dependent”
“time-indepen
b
– E.g., if we can measure the temperature only on
the exterior of a body, what might we guess the
time
temperature distribution looks like inside? domain
boundary
Dirichlet vs. Neumann Boundary Conditions
Dirichlet Neumann
1D Laplace:
Solutions:
1D Laplace:
Solutions:
TEMPERATURE
BOUNDARY VALUE
ABSORPTION SOURCE
DIFFUSION DRIFT
BOUNDARY
Convection-Diffusion Equation—Coefficients
ABSORPTION SOURCE
DIFFUSION DRIFT
BOUNDARY
f(x)
“first-order
accurate”
forward difference
h
x
x0 x1
Finite Differences—Second Order
Example. Take “difference of differences” to approximate 2nd-order derivative:
Q: Is this a reasonable
approximation?
Feels like we’re piling approxim
ation
on top of approximation…
Finite Differences—Polynomial Fitting
• Similar perspective: fit polynomial to sample sample points sample values
points; derivatives of polynomial then
approximate derivatives of original function. –h 0 +h
• Example. Fit quadratic polynomial p(x) to quadratic fit
three points. Then p’(x) gives centered
difference approximation for 1st derivative of
linear system for a, b, c
f (x) at x0; p’’(x) gives finite difference formula
for 2nd derivative.
f(x) Q: How would we
recover 1st-order
forward difference?
A: Fit a linear O(h 2)
polynomial 1st derivative error
p(x) (centered)
p(x) = ax+b
x 2nd derivative
x0 x1 x2
Finite Differences - Laplacian Notice: approximates
deviation from local average!
*Arises naturally from several perspectives: finite volumes, discrete exterior calculus, …
Gradient—Staggered Grid
• Example. To approximate the
gradient on a 2D staggered grid take
a “horizontal” difference across each
vertical edge, and “vertical”
difference across each horizontal
edge.
– Note: there is no complete vector
defined at any grid node!
– If necessary (e.g., for visualization),
can still (bi-)linearly interpolate
nodal values to get continuous
vector field in space
Finite Difference Solver
• Store values on a regular grid
• Use finite differences to approximate
spatial derivatives
• Use same strategies as with ODEs to
update rule
approximate temporal derivatives
• Now “march forward in time” by
repeatedly solving for uk+1 (update rule)
• Notation:
time
– subscript for space
– superscript for time space
Example — Heat Equation
Update rule: forward Euler, finite difference Laplacian 1
1 -4 1
Initial conditions: all values given at initial time step (k=0) 1
Boundary conditions: values given at boundary nodes for all steps k
function at
previous time
time
function at next step node spacing
moment in time
0.99τstable 1.01τstable
upwind (1D)
see: Osher & Fedkiw, “Level
Set Methods and Dynamic
Implicit Surfaces” §3.2
Numerical Methods for PDEs—Summary
• Only scratched the surface
• Many ways to think about approximating solution, space &
time derivatives
• Many criteria for “good” solver
– stability: how big of a time step can I take?
– accuracy: how fast do I converge under refinement?
• Just comparing stability & accuracy is shallow way of
judging method—in practice have to deal with:
– complex geometry
– complex boundary conditions
– singular or discontinuous functions
– …
• No universally “best” method—pick the right tool for the job!
PDEs and Stochastic Processes
Feynman-Kac Formula — Overview
• Main question: what’s the connection between PDEs and random walks?
• One direction: solution to PDE given by average behavior of many
random walks
– encapsulated by Feynman-Kac formula
• Another direction: behavior of stochastic process (e.g., probability
distribution) can be analyzed by solving a PDE
– encapsulated by Fokker-Planck equation
• Prelude: connection between Brownian motion & heat equation
Review: Donsker’s Theorem
• Consider a sequence of i.i.d. random variables X1, …, Xn
• Can associate these discrete steps with a time-continuous function
2
Ratio τ / h
is a fixed
constant.
spatial step time step
size h size τ = 1/n
I.e., just repeatedly average the four neighbors. I.e., just repeatedly average the four neighbors.
Intuition: accumulate
total “heat” felt by
random walker along
its trajectory.
Absorption Term
ABSORPTION EXPONENTIAL DECAY
differential equation
(convection-diffusion) stochastic representation
boundary
PDE Ω
e
Q: What’s th
solution?
A: Just a linear
function: y
u(x,y) = x
x -1
e
Q: What’s th E? Solution
e s p o n d i n g SD
cor r Q: What’s the Feynman-Kac
A: Just plain representation of the solution?
Brownian motion A: Just the expected boundary
value at the exit time T. So, no quadrature in time
SDE to worry about (for now).
Feynman-Kac—Numerical Example (Laplace)
u ̂ ← 0 initialize estimate
for i = 1,…, N:
x ← x0 start at evaluation point
① Simulate until ∥x∥ > 1: while still in the disk ③ Overall estimate is
random walk average of boundary
using Euler- ξ ∼ 𝒩2D(0,1) sample direction values at exit points
Maruyama x ← x + τξ take a step
u ̂ ← u ̂ + g(x) add boundary value
̂ return the average
return u /N
② Nothing to
integrate in time
Feynman-Kac—Numerical Example (Laplace)
N=1 N = 16 N = 1024
τ = 1/10
u
+1
grid reference
solution -1
Feynman-Kac—Numerical Example (Poisson)
Example. Let’s add a source term: u
+1
x -1
e S DE now?
Q: W h a t ’ s t h Solution
Q: How does the Feynman-
A: Still just Brownian Kac representation change?
motion—we didn’t change
the differential operator (∆) A: We now have to integrate the
source term along each walk
SDE
Integrating the Source Term
Q: Given that we’ve already generated a sequence of points
2
x0, x1, x2…, xK ∈ ℝ at equispaced time intervals 0,τ,2τ, …, Kτ, what
is a reasonable way to numerically approximate the source integral?
?
Integrating the Source Term
Recall: a function of stochastic process is a stochastic process
So, we just n
approximate eed to
th
the curve” on e “area under
the right…
Integrating the Source Term
Q: Given that we’ve already generated a sequence of points
2
x0, x1, x2…, xK ∈ ℝ at equispaced time intervals 0,τ,2τ, …, Kτ, what
is a reasonable way to numerically approximate the source integral?
u
+1
Converging… but
not clearly to the
correct solution!
grid reference
solution -1
What Can Go Wrong?
• Q: Are there any sources of numerical error in our algorithm?
• A: Yes, many!
– number of samples N (Monte Carlo estimate)
Ω
– step size τ (Euler Maruyama)
◦ crude approximation of time integrals (even if N is large!)
◦ final step may be far from boundary
◦ could even “jump” from one part of the domain to another
–…
Later: can nicely address some of these problems with walk on spheres.
Fokker-Planck Equation
Fokker-Planck Equation — Overview
• Main question: what’s the connection between PDEs and random walks?
• One direction: solution to PDE given by average behavior of many random walks
– encapsulated by Feynman-Kac formula
• Another direction: behavior of many random walks can be described by PDE
– encapsulated by Fokker-Planck equation (a.k.a. Kolmogorov forward equation)
• Not one single equation! Rather, for any SDE, can ask for its Fokker-Planck
equation
– often yields a familiar PDE (heat equation, convection-diffusion equation, etc.)
– solution is probability distribution p(x, t) describing location of Xt in space & time
Translating SDE to Fokker-Planck Equation
• Suppose we have an SDE, and want corresponding Fokker-Planck PDE
• We already know how to do this for many SDEs…
– just opposite direction of what we did for Feynman-Kac!
• Q: For instance, what's the PDE for pure Brownian motion?
– A: Heat equation
• Q: What's the PDE for a general diffusion process?
– A: (Screened) convection-diffusion equation
• For general SDE, there may or may not be an established PDE…
Example—Langevin Equation More generally: have to solve
numerically! (e.g., finite differences)
SDE
time evolution damping Langevin just like linear ODE… approaches α2/2γ
of velocity force force
v0
PDE
diffusion convection
starts at v0
Using the Solution of the Fokker-Planck Equation
• Suppose we've solved for the distribution p(x)
• Can now compute, e.g., the expected value of any other quantity a(x)
by integration
– e.g., suppose we want the average temperature of one of our “pollen
grains” at some stopping time T
Will see a lot more of this kind of thing as we develop MCMC algorithms!
Thanks!