% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/loss.R
\name{nnf_mc_loss}
\alias{nnf_mc_loss}
\title{Max-Constraint Margin Loss (functional)}
\usage{
nnf_mc_loss(
  output,
  target,
  R,
  to_eval = NULL,
  criterion = nnf_binary_cross_entropy_with_logits
)
}
\arguments{
\item{output}{A \code{torch_tensor} of raw network outputs (pre-sigmoid),
shape \verb{(batch_size, n_classes)}.}

\item{target}{Binary target labels, shape \verb{(batch_size, n_classes)}.}

\item{R}{Ancestor matrix tensor of shape \verb{(1, n_classes, n_classes)} where
\code{R[1, i, j] = 1} iff class \code{i} is a descendant of class \code{j}.}

\item{to_eval}{Optional logical tensor of shape \verb{(n_classes,)} indicating
which classes to include in the loss computation. If \code{NULL}, all classes
are evaluated.}

\item{criterion}{Loss function to apply after constraint propagation.
Default: \code{nnf_binary_cross_entropy_with_logits} (expects raw logits).}
}
\value{
A scalar \code{torch_tensor} containing the computed loss, or a tensor
of shape \verb{(batch_size, n_classes)} if \code{reduction = "none"}.
}
\description{
Computes the hierarchy-constrained loss for multi-label classification.
Enforces that if a class is predicted positive, all its ancestors must
also be positive, using the ancestor matrix R.
}
\details{
The loss combines constrained outputs differently for positive and negative
labels:
\itemize{
\item For positive labels: uses constrained output of label-weighted predictions
\item For negative labels: uses constrained raw predictions (penalizes ancestor violations)
}
}
\seealso{
\code{\link[=nn_mc_loss]{nn_mc_loss()}}, \code{\link[=get_constr_output]{get_constr_output()}}
}
