% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/loss.R
\name{nn_mc_loss}
\alias{nn_mc_loss}
\title{Max-Constraint Margin Loss (module)}
\usage{
nn_mc_loss(
  R,
  to_eval = NULL,
  criterion = nnf_binary_cross_entropy_with_logits,
  reduction = "mean"
)
}
\arguments{
\item{R}{Ancestor matrix tensor of shape \verb{(1, n_classes, n_classes)}.}

\item{to_eval}{Optional logical tensor of shape \verb{(n_classes,)} indicating
which classes to include in loss computation.}

\item{criterion}{Loss function module or functional to apply after constraint
propagation. Default: \code{nn_binary_cross_entropy_with_logits()}.}

\item{reduction}{(string, optional): Reduction method: \code{'none'} | \code{'mean'} | \code{'sum'}.}
}
\description{
Module wrapper for \code{\link[=nnf_mc_loss]{nnf_mc_loss()}} with configurable parameters.
Stores the ancestor matrix R and evaluation mask for reuse across batches.
}
\section{Shape}{

\itemize{
\item Input \code{output}: \eqn{(N, C)} where N = batch size, C = number of classes
\item Input \code{target}: \eqn{(N, C)}, same shape as output, binary values
\item Output: scalar by default. If \code{reduction = "none"}, then \eqn{(N, C')}
where C' is the number of evaluated classes
}
}

\examples{
\dontrun{
# Build ancestor matrix from hierarchy
R <- build_ancestor_matrix_from_outcomes(my_tree, processed$outcomes, device = "cuda")

# Create loss module
loss_fn <- nn_mc_loss(R = R, reduction = "mean")

# Forward pass
output <- model(x)  # (batch, n_classes)
loss <- loss_fn(output, labels)
loss$backward()
}

}
\seealso{
\code{\link[=nnf_mc_loss]{nnf_mc_loss()}}, \code{\link[=build_ancestor_matrix_from_outcomes]{build_ancestor_matrix_from_outcomes()}}, \code{\link[=get_constr_output]{get_constr_output()}}
}
