#' Transform psi to param
#'
#' @param psi A vector of all the real hyper-parameters
#' @param mdl The specified sigex model, a list object
#' @param data.ts A T x N matrix ts object (with no missing values)
#' corresponding to N time series of length T
#'
#' @return param: model parameters entered into
#' a list object with an intuitive structure.
#' @export
#'
sigex.psi2par <- function(psi,mdl,data.ts)
{
##########################################################################
#
# sigex.psi2par
# Copyright (C) 2017 Tucker McElroy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
############################################################################
################# Documentation #####################################
#
# Purpose: transform psi to param
# Background:
# param is the name for the model parameters entered into
# a list object with a more intuitive structure, whereas
# psi refers to a vector of real numbers containing all
# hyper-parameters (i.e., reals mapped bijectively to the parameter manifold)
# Notes: this is a functional inverse to sigex.par2psi
# Format: psi has three portions, psi = [xi,zeta,beta]
# xi ~ all hyper-parameters for covariance matrices
# zeta ~ all hyper-parameters for t.s. models
# beta ~ all regression parameters
# Inputs:
# psi: see background.
# mdl: the specified sigex model, a list object
# data.ts: a T x N matrix ts object,
# corresponding to N time series of length T
# Outputs:
# param: see background. Will have form specified by mdl
# Requires: sigex.param2gcd, sigex.zeta2par, sigex.zetalen
#
####################################################################
x <- t(data.ts)
N <- dim(x)[1]
T <- dim(x)[2]
L.par <- mdl[[3]]
D.par <- mdl[[3]]
zeta.par <- vector("list",length(mdl[[3]]))
# get xi portion
ind <- 0
A.mat <- matrix(0,N,N)
A.mat[lower.tri(A.mat)] <- 1
for(i in 1:length(mdl[[3]]))
{
vrank <- mdl[[1]][[i]]
D.dim <- length(vrank)
L.dim <- sum(A.mat[,as.vector(vrank)])
L.psi <- NULL
if(L.dim > 0) L.psi <- psi[(ind+1):(ind+L.dim)]
ind <- ind+L.dim
D.psi <- psi[(ind+1):(ind+D.dim)]
ind <- ind+D.dim
L.mat <- sigex.param2gcd(L.psi,N,as.vector(vrank))
L.par[[i]] <- L.mat
D.par[[i]] <- D.psi
}
# get beta portion
beta.len <- 0
for(i in 1:N)
{
beta.len <- beta.len + dim(mdl[[4]][[i]])[2]
}
beta.par <- as.vector(psi[(length(psi)-beta.len+1):length(psi)])
# get zeta portion
if(length(psi)-beta.len-ind > 0) {
zeta <- psi[(ind+1):(length(psi)-beta.len)] }
ind <- 0
for(i in 1:length(mdl[[3]]))
{
mdlType <- mdl[[2]][[i]]
zetalen <- sigex.zetalen(mdlType,N)
if(zetalen > 0) {
subzeta <- zeta[(ind+1):(ind+zetalen)]
zeta.par[[i]] <- sigex.zeta2par(subzeta,mdlType,N)
}
ind <- ind + zetalen
}
return(list(L.par,D.par,zeta.par,beta.par))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.