-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfilter2.Rd
132 lines (131 loc) · 7.02 KB
/
pfilter2.Rd
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
\name{pfilter2}
\alias{pfilter2}
\alias{pfilter2,pomp-method}
\alias{pfilter2-pomp}
\alias{pfilter2,pfilterd2.pomp-method}
\alias{pfilter2-pfilterd2.pomp}
\alias{pfilterd2.pomp-class}
\title{Particle filter}
\description{
Run a plain vanilla particle filter.
Resampling is performed at each observation.
}
\usage{
\S4method{pfilter2}{pomp}(object, params, Np, tol = 1e-17,
max.fail = Inf, pred.mean = FALSE, pred.var = FALSE,
filter.mean = FALSE,
save.states = FALSE,
save.params = FALSE, lag=0, seed = NULL,
verbose = getOption("verbose"), \dots)
\S4method{pfilter2}{pfilterd2.pomp}(object, params, Np, tol, \dots)
}
\arguments{
\item{object}{
An object of class \code{pomp} or inheriting class \code{pomp}.
}
\item{params}{
A \code{npars} x \code{Np} numeric matrix containing the parameters corresponding to the initial state values in \code{xstart}.
This must have a \sQuote{rownames} attribute.
If it desired that all particles should share the same parameter values, one one may supply \code{params} as a named numeric vector.
}
\item{Np}{
the number of particles to use.
This may be specified as a single positive integer, in which case the same number of particles will be used at each timestep.
Alternatively, if one wishes the number of particles to vary across timesteps, one may specify \code{Np} either as a vector of positive integers (\code{length(time(object},\code{t0=TRUE))}) or as a function taking a positive integer argument.
In the latter case, \code{Np(k)} must be a single positive integer, representing the number of particles to be used at the \code{k}-th timestep:
\code{Np(0)} is the number of particles to use going from \code{timezero(object)} to \code{time(object)[1]},
\code{Np(1)}, from \code{timezero(object)} to \code{time(object)[1]},
and so on, while when \code{T=length(time(object,t0=TRUE))},
\code{Np(T)} is the number of particles to sample at the end of the time-series.
When \code{object} is of class \code{is2}, this is by default the same number of particles used in the \code{is2} iterations.
}
\item{tol}{
positive numeric scalar; particles with likelihood less than \code{tol} are considered to be \dQuote{lost}.
A filtering failure occurs when, at some time point, all particles are lost.
When all particles are lost, the conditional likelihood at that time point is set to \code{tol}.
}
\item{max.fail}{
integer; the maximum number of filtering failures allowed.
If the number of filtering failures exceeds this number, execution will terminate with an error.
By default, \code{max.fail} is set to infinity, so no error can be triggered.
}
\item{pred.mean}{
logical; if \code{TRUE}, the prediction means are calculated for the state variables and parameters.
}
\item{pred.var}{
logical; if \code{TRUE}, the prediction variances are calculated for the state variables and parameters.
}
\item{filter.mean}{
logical; if \code{TRUE}, the filtering means are calculated for the state variables and parameters.
}
\item{save.states, save.params}{
logical.
If \code{save.states=TRUE}, the state-vector for each particle at each time is saved in the \code{saved.states} slot of the returned \code{\link[=pfilterd2.pomp-class]{pfilterd2.pomp}} object.
If \code{save.params=TRUE}, the parameter-vector for each particle at each time is saved in the \code{saved.params} slot of the returned \code{\link[=pfilterd2.pomp-class]{pfilterd2.pomp}} object.
}
\item{lag}{
positive numeric scalar; use for fixed lag smoothing.
}
\item{seed}{
optional; an object specifying if and how the random number generator should be initialized (\sQuote{seeded}).
If \code{seed} is an integer, it is passed to \code{set.seed} prior to any simulation and is returned as the \dQuote{seed} element of the return list.
By default, the state of the random number generator is not changed and the value of \code{.Random.seed} on the call is stored in the \dQuote{seed} element of the return list.
}
\item{verbose}{
logical; if \code{TRUE}, progress information is reported as \code{pfilter2} works.
}
\item{\dots}{
By default, when \code{pfilter2} pfilter is run on a \code{pfilterd2.pomp} object, the settings in the original call are re-used.
This default behavior can be overridden by changing the settings (see Examples below).
}
}
\value{
An object of class \code{\link[=pfilterd2.pomp-class]{pfilterd2.pomp}}.
This class inherits from class \code{\link[=pomp-class]{pomp}} and contains the following additional slots:
\describe{
\item{pred.mean, pred.var, filter.mean}{
matrices of prediction means, variances, and filter means, respectively.
In each of these, the rows correspond to states and parameters (if appropriate), in that order, the columns to successive observations in the time series contained in \code{object}.
}
\item{eff.sample.size}{
numeric vector containing the effective number of particles at each time point.
}
\item{cond.loglik}{
numeric vector containing the conditional log likelihoods at each time point.
}
\item{saved.states}{
If \code{pfilter2} was called with \code{save.states=TRUE}, this is the list of state-vectors at each time point, for each particle.
It is a length-\code{ntimes} list of \code{nvars}-by-\code{Np} arrays.
In particular, \code{saved.states[[t]][,i]} can be considered a sample from \eqn{f[X_t|y_{1:t}]}.
}
\item{saved.params}{
If \code{pfilter2} was called with \code{save.params=TRUE}, this is the list of parameter-vectors at each time point, for each particle.
It is a length-\code{ntimes} list of \code{npars}-by-\code{Np} arrays.
In particular, \code{saved.params[[t]][,i]} is the parameter portion of the i-th particle at time \eqn{t}.
}
\item{seed}{
the state of the random number generator at the time \code{pfilter2} was called.
If the argument \code{seed} was specified, this is a copy;
if not, this is the internal state of the random number generator at the time of call.
}
\item{Np, tol, nfail}{
the number of particles used, failure tolerance, and number of filtering failures, respectively.
}
\item{loglik}{
the estimated log-likelihood.
}
}
These can be accessed using the \code{$} operator as if the returned object were a list.
In addition, \code{logLik} returns the log likelihood.
Note that if the argument \code{params} is a named vector, then these parameters are included in the \code{params} slot of the returned \code{pfilterd2.pomp} object.
That is \code{coef(pfilter2(obj,params=theta))==theta} if \code{theta} is a named vector of parameters.
}
\references{
M. S. Arulampalam, S. Maskell, N. Gordon, & T. Clapp.
A Tutorial on Particle Filters for Online Nonlinear, Non-Gaussian Bayesian Tracking.
IEEE Trans. Sig. Proc. 50:174--188, 2002.
}
\author{{Dao Nguyen \email{nguyenxd at umich dot edu}}, {Edward L. Ionides \email{ionides at umich dot edu}}}
\seealso{\code{\link{is2}}}
\keyword{models}
\keyword{ts}