% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bayesRecon_MixCond.R, R/bayesRecon_TDcond.R
\name{bayesRecon_MixCond}
\alias{bayesRecon_MixCond}
\alias{bayesRecon_TDcond}
\title{Probabilistic reconciliation of mixed hierarchies}
\usage{
bayesRecon_MixCond(models, n_samples = 1000, suppress_warnings = TRUE)

bayesRecon_TDcond(models, n_samples = 1000, suppress_warnings = TRUE)
}
\arguments{
\item{models}{A list of fitted models to reconcile.}

\item{n_samples}{Number of samples to draw from the reconciled distribution.}

\item{suppress_warnings}{If \code{TRUE}, suppress warnings from reconciliation.}
}
\value{
A model specification of class \code{"bayesRecon_MixCond"} or
\code{"bayesRecon_TDcond"} (inheriting from \code{"mdl_lst"})
to be passed to \code{\link[fabletools]{reconcile}}. The reconciliation is
performed when \code{\link[fabletools]{forecast}} is called on
the resulting mable (a model table). The forecast output is a \code{fable} object
containing reconciled probabilistic forecasts represented as
sample distributions (\code{\link[distributional]{dist_sample}}).
}
\description{
\code{bayesRecon_MixCond} specifies Mixed-Conditioning (Mix-Cond) reconciliation for use within
\code{reconcile()}. The method uses importance sampling to draw samples from the reconciled
forecast distribution, obtained via conditioning, in the case of a mixed hierarchy.

\code{bayesRecon_TDcond} specifies Top-Down Conditioning reconciliation for use within
\code{reconcile()}. The method uses a top-down conditioning algorithm: first, upper base forecasts
are reconciled via conditioning using only the hierarchical constraints between the
upper; then, the bottom distributions are updated via a probabilistic top-down procedure.

Reconciliation is performed when \code{forecast()} is called on the resulting model.
Marginal reconciled forecasts follow a sample distribution.
}
\examples{
library(tsibble)
library(dplyr)
library(tibble)
library(fable)
library(fabletools)


# Mixed hierarchy with integer-valued bottom series and one upper aggregate.
# Two low-rate Poisson count series at the bottom; their sum forms the
# continuous-looking upper aggregate. 
set.seed(42)
n <- 60
idx <- tsibble::yearmonth("2019 Jan") + 0:(n - 1)

counts <- dplyr::bind_rows(
   tibble::tibble(Month = idx, Item = "A", Sales = rpois(n, lambda = 3)),
   tibble::tibble(Month = idx, Item = "B", Sales = rpois(n, lambda = 5))) |>
   tsibble::as_tsibble(index = Month, key = Item) |>
   fabletools::aggregate_key(Item, Sales = sum(Sales))
   
# Fit a base model on every level, then reconcile via MixCond:
# the upper (aggregated) forecast is treated as Gaussian, while the
# bottom-level forecast samples are treated as discrete via importance
# sampling.
fit <- counts |>
model(base = ETS(Sales)) |>
reconcile(mc = bayesRecon_MixCond(base))


# Alternative reconciliation via TDcond
fit_TDcond <- counts |>
model(base = ETS(Sales)) |>
reconcile(mc = bayesRecon_TDcond(base))


fc <- forecast(fit, h = 2)
fc


}
\references{
Zambon, L., Azzimonti, D., Rubattu, N., Corani, G. (2024).
\emph{Probabilistic reconciliation of mixed-type hierarchical time series}.
Proceedings of the Fortieth Conference on Uncertainty in Artificial Intelligence,
PMLR 244:4078-4095. \url{https://proceedings.mlr.press/v244/zambon24a.html}.
}
\seealso{
\code{\link[fabletools:reconcile]{fabletools::reconcile()}}, \code{\link[fabletools:aggregate_key]{fabletools::aggregate_key()}},
\code{\link[=bayesRecon_BUIS]{bayesRecon_BUIS()}}, \code{\link[bayesRecon:reconc_MixCond]{bayesRecon::reconc_MixCond()}}, \code{\link[bayesRecon:reconc_TDcond]{bayesRecon::reconc_TDcond()}}
}
