Skip to content

Commit 6acc3c7

Browse files
committed
attempt at quacrature rules
1 parent fff06a3 commit 6acc3c7

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

docs/src/lecture_12/lecture.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,33 @@ In multivariate setting, the same problem is typically solved with the aim to re
166166

167167
One of the most popular approaches today is based on cubature rules approximating the Gaussian in radial-spherical coordinates.
168168

169-
decomposition of the covariance matrix
169+
## Cubature rules
170+
171+
Consider Gaussian distribution with mean ``\mu`` and covariance matrix ``\Sigma`` that is positive definite with square root ``\sqrt\Sigma``, such that ``\sqrt\Sigma^T \sqrt\Sigma=\Sigma``. The quadrature pints are:
172+
```math
173+
X_q = \mu .+ \sqrt\Sigma Q
174+
```
175+
where ``Q=[q_1,\ldots q_{2d}]`` are constant vectors
176+
```math
177+
Q = \sqrt{d} [ I_d -I_d]
178+
```
179+
with associated weights
170180
```math
181+
w_i = \frac{1}{2d}, i=1,\ldots,sd
182+
```
183+
where ``d`` is dimension of the vectors.
171184

185+
The quadrature points are propogated through the non-linearity and the resulting Gaussian distribution is:
186+
```math
187+
\begin{align}
188+
x' & \sim N(\mu',\Sigma')\\
189+
\mu' & = \frac{1}{2d}\sum_{j=1}^{2d} x_i\\
190+
\Sigma &= \frac{1}{2d}\sum_{j=1}^{2d} (x_i-\mu')^T (X_i-\mu')
191+
\end{align}
172192
```
173193

174-
# Manipulating ODEs
175194

176-
So far, we have considered first-order ODEs. Many ODEs are defined in higher order form, e.g.
195+
## Containing uncertainty in vectors
177196

197+
With vectorized uncertainty, it is now harder to assign which variable is now the first, second, etc.
178198

179-
- check Chris Raucausacc latest blog
180-
https://julialang.org/blog/2021/10/DEQ/

docs/src/lecture_12/ode.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,34 @@ plot!(MX[2,1:30:end],label="y",color=:red)
9898
savefig("LV_Measurements2.svg")
9999

100100

101+
101102
# Plot receipe
102-
# plot(Vector{GaussNum})
103+
# plot(Vector{GaussNum})
104+
105+
using LinearAlgebra
106+
function solve(f,x0::AbstractVector,Σ0, θ,dt,N)
107+
const n = length(x0)
108+
const n2 = 2*length(x0)
109+
const Qp = sqrt(n2)*[I(n) -I(n)]
110+
111+
X = hcat([zero(x0) for i=1:N]...)
112+
S = hcat([zero(x0) for i=1:N]...)
113+
X[:,1]=x0
114+
Σ = Σ0
115+
Σ = Σ* Σ'
116+
S[:,1]= diag(Σ)
117+
for t=1:N-1
118+
Xp = x0 .+ Σ * Qp
119+
for i=1:n2 # all quadrature points
120+
Xp.=X[:,t] + dt*f(Xp[:,i],θ)
121+
end
122+
mXp=mean(Xp,dims=2)
123+
X[:,t+1]=mXp
124+
Σ=(Xp.-mXp)*(Xp.-mXp)'/sqrt(n2)
125+
S[:,t+1]=diag(Σ)
126+
Σ = chol(Σ)
127+
end
128+
X,S
129+
end
130+
131+
## Extension to arbitrary

0 commit comments

Comments
 (0)