36-467/36-667
19 November 2020 (Lecture 23)
\[ \newcommand{\Prob}[1]{\mathbb{P}\left( #1 \right)} \]
\(\Prob{X(t+1)=x(t+1)|S(t)=s, X(1:t)=x(1:t)}\) \[\begin{eqnarray} & = & \sum_{r}{\Prob{X(t+1)=x(t+1)|S(t+1)=r, S(t)=s, X(1:t)=x(1:t)}\Prob{S(t+1)=r|S(t)=s,X(1:t)=x(1:t)}}\\ & = & \sum_{r}{\Prob{X(t+1)|S(t+1)=r}\Prob{S(t+1)=r|S(t)=s}} \end{eqnarray}\]
\(\Prob{X(t+1)=x(t+1)|X(1:t)=x(1:t)}\) \[\begin{eqnarray} & = & \sum_{s}{\Prob{X(t+1)=x(t+1)|S(t)=s,X(1:t)=x(1:t)}\Prob{S(t)=s|X(1:t)=x(1:t)}}\\ & = & \sum_{s}{\left(\sum_{r}{\Prob{X(t+1)|S(t+1)=r}\Prob{S(t+1)=r|S(t)=s}}\right) \Prob{S(t)=s|X(1:t)=x(1:t)}} \end{eqnarray}\]
\(\Rightarrow\) Given \(X(t)\), the only way \(X(t-1)\) can matter for \(X(t+1)\) is by changing the conditional distribution of \(S(t)\)
(for continuous variables, replace PMFs by pdfs as needed)
\[ \Prob{X(1:n)=x(1:n)} = \sum_{s(1:n)}{ \Prob{S(1)=s(1)} \prod_{t=2}^{n}{q(s(t-1), s(t))}\prod_{t=1}^{n}{g(s(t), x(t))}} \]
particle.filter <- function(x, rinitial, rtransition, dobs, m) {
n <- length(x)
particles <- replicate(m, rinitial())
particle.history <- matrix(0, nrow = m, ncol = n)
for (t in 1:n) {
weights <- dobs(state = particles, observation = x[t])
particles <- sample(particles, size = m, replace = TRUE, prob = weights)
particle.history[, t] <- particles
particles <- sapply(particles, rtransition)
}
return(particle.history)
}
sim.pf <- particle.filter(x=sim$x,
rinitial=function() { sample(-1,+1, size=1) },
rtransition=function (x) {
stay <- sample(c(TRUE, FALSE), size=1, prob=c(0.75, 0.25))
if (stay) { return(x) }
if (!stay) { return(-x) }
},
dobs=function(state, observation) {
dnorm(x=observation, mean=state, sd=1)
},
m=100)
Many more details in the handout on the website
toy.indirect.inference <- function(x, starting.q, s) {
n <- length(x)
aux.data <- aux.estimator(x)
discrepency <- function(param) {
q <- param
aux.mean <- aux.from.sim(q = q, s = s, n = n)
return(sum((aux.data - aux.mean)^2))
}
fit <- optim(par = starting.q, fn = discrepency, method = "Brent", lower = 0,
upper = 1)
return(fit$par)
}
## [1] 0.7092326
Remember we set the true \(q\) to \(0.75\)
This isn’t a fluke:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.6929 0.7037 0.7108 0.7110 0.7167 0.7332
+ All the variation here is from simulation to simulation