foreca.EM-aux {ForeCA} | R Documentation |
ForeCA EM auxiliary functions
Description
foreca.EM.one_weightvector
relies on several auxiliary functions:
foreca.EM.E_step
computes the spectral density of
given the weightvector
and the normalized spectrum estimate
.
A wrapper around
spectrum_of_linear_combination
.
foreca.EM.M_step
computes the minimizing eigenvector
() of the weighted
covariance matrix, where the weights equal the negative logarithm of the
spectral density at the current
.
foreca.EM.E_and_M_step
is a wrapper around foreca.EM.E_step
followed by foreca.EM.M_step
.
foreca.EM.h
evaluates (an upper bound of) the entropy of the spectral density as a function
of (or
). This is the objective funcion that should be
minimize
d.
Usage
foreca.EM.E_step(f.U, weightvector)
foreca.EM.M_step(f.U, f.current, minimize = TRUE, entropy.control = list())
foreca.EM.E_and_M_step(
weightvector,
f.U,
minimize = TRUE,
entropy.control = list()
)
foreca.EM.h(
weightvector.new,
f.U,
weightvector.current = weightvector.new,
f.current = NULL,
entropy.control = list(),
return.negative = FALSE
)
Arguments
f.U |
multivariate spectrum of class |
weightvector |
numeric; weights |
f.current |
numeric; spectral density estimate of
|
minimize |
logical; if |
entropy.control |
list; control settings for entropy estimation.
See |
weightvector.new |
weightvector |
weightvector.current |
weightvector |
return.negative |
logical; if |
Value
foreca.EM.E_step
returns the normalized univariate spectral
density (normalized such that its sum
equals ).
foreca.EM.M_step
returns a list with three elements:
-
matrix
: weighted covariance matrix, where the weights are the negative log of the spectral density. If density is estimated by discrete probabilities, then thismatrix
is positive semi-definite, sincefor
. See
weightvector2entropy_wcov
. -
vector
: minimizing (or maximizing ifminimize = FALSE
) eigenvector ofmatrix
, -
value
: corresponding eigenvalue.
Contrary to foreca.EM.M_step
, foreca.EM.E_and_M_step
only returns the optimal
weightvector as a numeric.
foreca.EM.h
returns non-negative real value (see References for details):
entropy, if
weightvector.new = weightvector.current
,an upper bound of that entropy for
weightvector.new
, otherwise.
See Also
Examples
## Not run:
XX <- diff(log(EuStockMarkets)) * 100
UU <- whiten(XX)$U
ff <- mvspectrum(UU, 'mvspec', normalize = TRUE)
ww0 <- initialize_weightvector(num.series = ncol(XX), method = 'rnorm')
f.ww0 <- foreca.EM.E_step(ff, ww0)
plot(f.ww0, type = "l")
## End(Not run)
## Not run:
one.step <- foreca.EM.M_step(ff, f.ww0,
entropy.control = list(prior.weight = 0.1))
image(one.step$matrix)
requireNamespace(LICORS)
# if you have the 'LICORS' package use
LICORS::image2(one.step$matrix)
ww1 <- one.step$vector
f.ww1 <- foreca.EM.E_step(ff, ww1)
layout(matrix(1:2, ncol = 2))
matplot(seq(0, pi, length = length(f.ww0)), cbind(f.ww0, f.ww1),
type = "l", lwd =2, xlab = "omega_j", ylab = "f(omega_j)")
plot(f.ww0, f.ww1, pch = ".", cex = 3, xlab = "iteration 0",
ylab = "iteration 1", main = "Spectral density")
abline(0, 1, col = 'blue', lty = 2, lwd = 2)
Omega(mvspectrum.output = f.ww0) # start
Omega(mvspectrum.output = f.ww1) # improved after one iteration
## End(Not run)
## Not run:
ww0 <- initialize_weightvector(NULL, ff, method = "rnorm")
ww1 <- foreca.EM.E_and_M_step(ww0, ff)
ww0
ww1
barplot(rbind(ww0, ww1), beside = TRUE)
abline(h = 0, col = "blue", lty = 2)
## End(Not run)
## Not run:
foreca.EM.h(ww0, ff) # iteration 0
foreca.EM.h(ww1, ff, ww0) # min eigenvalue inequality
foreca.EM.h(ww1, ff) # KL divergence inequality
one.step$value
# by definition of Omega, they should equal 1 (modulo rounding errors)
Omega(mvspectrum.output = f.ww0) / 100 + foreca.EM.h(ww0, ff)
Omega(mvspectrum.output = f.ww1) / 100 + foreca.EM.h(ww1, ff)
## End(Not run)