I am exploring the use of Nimble in iterative ecological forecasting. The EnKF is particularly exciting in the nimbleSMC package. In the examples provided, the initial conditions for the latent states are defined as distributions within the nimble code and the number of ensemble members is set at the run step (Cmy_enKF$run(m = 1000)). Is it possible to pass the initial value for each ensemble member (i.e., the last step of a previous run of the EnKF is the initial conditions for a new run of the EnKF). This would allow an iterative approach to running the EnKF.
Here is the code I am running with the initial conditions defined within the nimble code
library("nimbleSMC")
## For illustration only.
exampleCode <- nimbleCode({
x0 ~ dnorm(0, var = 1)
x[1] ~ dnorm(a * x0, var = 1)
y[1] ~ dnorm(x[1], var = .5)
for(t in 2:10){
x[t] ~ dnorm(a * x[t-1], var = 1)
y[t] ~ dnorm(x[t], var = .01)
}
})
y <- rnorm(10)
model <- nimbleModel(code = exampleCode, data = list(y = y) , inits = list(x0 = 0, x = rnorm(10)))
model$a <- 0.8
my_enKF <- buildEnsembleKF(model, 'x',
control = list(saveAll = TRUE, thresh = 1))
## Now compile and run, e.g.,
Cmodel <- compileNimble(model)
Cmy_enKF <- compileNimble(my_enKF, project = model)
Cmy_enKF$run(m = 1000)
enKF_X <- as.matrix(Cmy_enKF$mvSamples, 'x')
plot(enKF_X[1, ], type = "l")
for(i in 2:100){
points(enKF_X[i, ], type = "l")
}
points(y, col = "red")