iterative_grid_search {viking}R Documentation

Iterative Grid Search

Description

iterative_grid_search is an iterative method to choose hyper-parameters of the linear Gaussian State-Space Model with time-invariant variances.

Usage

iterative_grid_search(
  X,
  y,
  q_list,
  Q_init = NULL,
  max_iter = 0,
  delay = 1,
  use = NULL,
  restrict = NULL,
  mode = "gaussian",
  p1 = 0,
  ncores = 1,
  train_theta1 = NULL,
  train_Q = NULL,
  verbose = TRUE
)

Arguments

X

the explanatory variables

y

the observations

q_list

the possible values of diag(Q) / sig^2

Q_init

(default NULL) initial value of Q / sig^2, if NULL it is set to 0

max_iter

(optional 0) maximal number of iterations. If 0 then optimization is done as long as we can improve the log-likelihood

delay

(optional, default 1) to predict y[t] we have access to y[t-delay]

use

(optional, default NULL) the availability variable

restrict

(optional, default NULL) if not NULL it allows to specify the indices of the diagonal coefficient to optimize

mode

(optional, default gaussian)

p1

(optional, default 0) coefficient for P1/sig^2 = p1 I

ncores

(optional, default 1) number of available cores for computation

train_theta1

(optional, default NULL) training set for estimation of theta1

train_Q

(optional, default NULL) time steps on which the log-likelihood is computed

verbose

(optional, default TRUE) whether to print intermediate progress

Details

We restrict ourselves to a diagonal matrix Q and we optimize Q / sig^2 on a grid. Each diagonal coefficient is assumed to belong to a pre-defined q_list.
We maximize the log-likelihood on that region of search in an iterative fashion. At each step, we change the diagonal coefficient improving the most the log-likelihood. We stop when there is no possible improvement. This doesn't guarantee an optimal point on the grid, but the computational time is much lower.

Value

a list containing values for P,theta,sig,Q, as well as LOGLIK, the evolution of the log-likelihood during the search.

Examples

set.seed(1)
### Simulate data
n <- 100
d <- 5
Q <- diag(c(0,0,0.25,0.25,0.25))
sig <- 1

X <- cbind(matrix(rnorm((d-1)*n,sd=1),n,d-1),1)
theta <- matrix(rnorm(d), d, 1)
theta_arr <- matrix(0, n, d)
for (t in 1:n) {
  theta_arr[t,] <- theta
  theta <- theta + matrix(mvtnorm::rmvnorm(1,matrix(0,d,1),Q),d,1)
}
y <- rowSums(X * theta_arr) + rnorm(n, sd=sig)

l <- viking::iterative_grid_search(X, y, seq(0,1,0.25))
print(l$Q)
print(l$sig)

[Package viking version 1.0.2 Index]