diff --git a/R/reconc.R b/R/reconc.R index 6eaffc0..aff6471 100644 --- a/R/reconc.R +++ b/R/reconc.R @@ -389,6 +389,10 @@ reconc_BUIS <- function(S, #' #' @details #' The order of the base forecast means and covariance is given by the order of the time series in the summing matrix. +#' +#' The function returns only the reconciled parameters of the bottom variables. +#' The reconciled parameters for the upper variables or reconciled samples for the entire hierarchy can be obtained from these. +#' The Examples section shows how. #' #' #' @return A list containing the bottom reconciled forecasts. The list has the following named elements: @@ -396,7 +400,6 @@ reconc_BUIS <- function(S, #' * `bottom_reconciled_mean`: reconciled mean for the bottom forecasts; #' * `bottom_reconciled_covariance`: reconciled covariance for the bottom forecasts. #' -#' How to obtain the reconciled upper parameters is shown in Examples. #' #' @examples #' @@ -433,6 +436,15 @@ reconc_BUIS <- function(S, #'Y_mu_reconc <- S %*% bottom_mu_reconc #'Y_Sigma_reconc <- S %*% bottom_Sigma_reconc %*% t(S) # note: singular matrix #' +#'# Obtain reconciled samples for the entire hierarchy: +#'# i.e., sample from the reconciled bottoms and multiply by S +#'chol_decomp = chol(bottom_Sigma_reconc) # Compute the Cholesky Decomposition +#'Z = matrix(rnorm(n = 2000), nrow = 2) # Sample from standard normal +#'B = chol_decomp %*% Z + matrix(rep(bottom_mu_reconc, 1000), nrow=2) # Apply the transformation +#' +#'U = S %*% B +#'Y_reconc = rbind(U, B) +#' #' @references #' Corani, G., Azzimonti, D., Augusto, J.P.S.C., Zaffalon, M. (2021). *Probabilistic Reconciliation of Hierarchical Forecast via Bayes' Rule*. In: Hutter, F., Kersting, K., Lijffijt, J., Valera, I. (eds) Machine Learning and Knowledge Discovery in Databases. ECML PKDD 2020. Lecture Notes in Computer Science(), vol 12459. Springer, Cham. \doi{10.1007/978-3-030-67664-3_13}. #' diff --git a/man/reconc_gaussian.Rd b/man/reconc_gaussian.Rd index a473b84..abc5151 100644 --- a/man/reconc_gaussian.Rd +++ b/man/reconc_gaussian.Rd @@ -19,14 +19,16 @@ A list containing the bottom reconciled forecasts. The list has the following na \item \code{bottom_reconciled_mean}: reconciled mean for the bottom forecasts; \item \code{bottom_reconciled_covariance}: reconciled covariance for the bottom forecasts. } - -How to obtain the reconciled upper parameters is shown in Examples. } \description{ Closed form computation of the reconciled forecasts in case of Gaussian base forecasts. } \details{ The order of the base forecast means and covariance is given by the order of the time series in the summing matrix. + +The function returns only the reconciled parameters of the bottom variables. +The reconciled parameters for the upper variables or reconciled samples for the entire hierarchy can be obtained from these. +The Examples section shows how. } \examples{ @@ -63,6 +65,15 @@ upper_Sigma_reconc <- A \%*\% bottom_Sigma_reconc \%*\% t(A) Y_mu_reconc <- S \%*\% bottom_mu_reconc Y_Sigma_reconc <- S \%*\% bottom_Sigma_reconc \%*\% t(S) # note: singular matrix +# Obtain reconciled samples for the entire hierarchy: +# i.e., sample from the reconciled bottoms and multiply by S +chol_decomp = chol(bottom_Sigma_reconc) # Compute the Cholesky Decomposition +Z = matrix(rnorm(n = 2000), nrow = 2) # Sample from standard normal +B = chol_decomp \%*\% Z + matrix(rep(bottom_mu_reconc, 1000), nrow=2) # Apply the transformation + +U = S \%*\% B +Y_reconc = rbind(U, B) + } \references{ Corani, G., Azzimonti, D., Augusto, J.P.S.C., Zaffalon, M. (2021). \emph{Probabilistic Reconciliation of Hierarchical Forecast via Bayes' Rule}. In: Hutter, F., Kersting, K., Lijffijt, J., Valera, I. (eds) Machine Learning and Knowledge Discovery in Databases. ECML PKDD 2020. Lecture Notes in Computer Science(), vol 12459. Springer, Cham. \doi{10.1007/978-3-030-67664-3_13}.