% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reconc_TDcond.R
\name{.core_reconc_TDcond}
\alias{.core_reconc_TDcond}
\title{Core Reconciliation via Top-Down Conditioning for Mixed Hierarchies}
\usage{
.core_reconc_TDcond(
  A,
  mean_upper,
  cov_upper,
  L_pmf,
  num_samples,
  return_type,
  return_upper = TRUE,
  suppress_warnings = TRUE,
  min_fraction_samples_ok = .MIN_FRACTION_SAMPLES_OK
)
}
\arguments{
\item{A}{Matrix (n_upper x n_bottom) defining the hierarchy where upper = A \%*\% bottom.}

\item{mean_upper}{Vector of mean forecasts for upper level.}

\item{cov_upper}{Covariance matrix of upper level forecasts.}

\item{L_pmf}{List of PMF objects representing the bottom level base forecasts.}

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

\item{return_type}{Character string specifying return format: 'pmf', 'samples', or 'all'.}

\item{return_upper}{Logical, whether to return reconciled upper forecasts (default TRUE).}

\item{suppress_warnings}{Logical, whether to suppress warnings about samples outside support (default TRUE).}

\item{min_fraction_samples_ok}{Numeric between 0 and 1, minimum fraction of reconciled
upper samples that must lie in the support of the bottom-up distribution (default 0.5).
If the fraction is below this threshold, the function returns an error.}
}
\value{
A list containing:
\itemize{
\item \code{bottom_rec_pmf}: list of PMF objects for each bottom series (only if \code{return_type} is 'pmf' or 'all').
\item \code{bottom_rec_samples}: matrix (n_bottom x num_samples) of reconciled bottom samples (only if \code{return_type} is 'samples' or 'all').
\item \code{upper_rec_pmf}: list of PMF objects for each upper series (only if \code{return_type} is 'pmf' or 'all', and \code{return_upper = TRUE}).
\item \code{upper_rec_samples}: matrix (n_upper x num_samples) of reconciled upper samples (only if \code{return_type} is 'samples' or 'all', and \code{return_upper = TRUE}).
}
}
\description{
Internal function that performs the core reconciliation logic using top-down conditioning
(TD) for mixed hierarchies. First, upper forecasts are reconciled analytically via conditioning
(if necessary), then bottom distributions are updated through probabilistic top-down procedure
by conditioning on the reconciled upper values.
}
\details{
The function internally:
\enumerate{
\item Identifies the "lowest upper" nodes in the hierarchy.
\item If all uppers are lowest-uppers, samples directly from the upper MVN. Otherwise,
analytically reconciles the upper hierarchy and samples from the lowest level.
\item Reconciles bottom distributions by conditioning on the sampled/reconciled upper values
using the probabilistic top-down algorithm.
\item Discards samples that fall outside the support of the bottom-up distribution.
}
}
\keyword{internal}
