Description Usage Arguments Details Run time arguments Author(s) Examples
Builds a particle filter for a scalar state-space model.
1 | buildParticleFilter(model, orderedNodeVector)
|
model |
A state space model for which the particle filter will be applied |
orderedNodeVector |
A character vector of the hidden
state space for which the particles will be simulated
for. Must be correctly ordered, i.e. |
A particle filter approximates the log-likelihood of a state-space model using simulations. At each time step, a sample of latent state values is simulated forward, weighted by the probability density of the observation, and resampled according to those weights for the next time step. The average of the weights is a factor in the likelihood. This version is for scalar states and observations.
m
number of particles to use
for each time step
Clifford Anderson-Bergman
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | timeModelCode <- nimbleCode({
x[1] ~ dnorm(mu_0, 1)
y[1] ~ dnorm(x[1], 1)
for(i in 2:t){
x[i] ~ dnorm(x[i-1] * a + b, 1)
y[i] ~ dnorm(x[i] * c, 1)
}
a ~ dunif(0, 1)
b ~ dnorm(0, 1)
c ~ dnorm(1,1)
mu_0 ~ dnorm(0, 1)
})
t = 25 #number of hidden spaces
mu_0 = 1
x = rnorm(1 ,mu_0, 1)
y = rnorm(1, x, 1)
a = 0.5
b = 1
c = 1
for(i in 2:t){
x[i] = rnorm(1, x[i-1] * a + b, 1)
y[i] = rnorm(1, x[i] * c, 1)
}
rTimeModel <- nimbleModel(timeModelCode, constants = list(t = t), data = list(y = y) )
cTimeModel <- compileNimble(rTimeModel)
xNodes = paste0('x[', 1:t, ']') #Ordered list of hidden nodes. Equivalent to xTimeModel$expandNodeNames('x[1:t]')
rPF <- buildParticleFilter(rTimeModel, xNodes)
# Setting initial values (true parameter values of simulated data)
cTimeModel$mu_0 = 1
cTimeModel$x = cTimeModel$y
cTimeModel$a = 0.5
cTimeModel$b = 1
cTimeModel$c = 1
cTimeModel$mu_0 = 1
cPF = compileNimble(rPF,project = rTimeModel)
cPF(m = 5000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.