% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/predict_target.R
\name{apply_wrapper}
\alias{apply_wrapper}
\title{Reduce predicted functions to scalars via a user-supplied wrapper}
\usage{
apply_wrapper(F_mat, wrapper = NULL, grid_weights = NULL)
}
\arguments{
\item{F_mat}{An \code{n}-by-\code{G_grid} numeric matrix; each row a function
on a shared grid (e.g. the output of \code{\link[=predict_target]{predict_target()}}).}

\item{wrapper}{Either \code{NULL} (default, weighted mean) or a function that
takes a single numeric vector of length \code{G_grid} and returns a scalar.
Examples: \code{mean}, \code{median}, \code{max}, \code{function(f) f[17]} (point
evaluation), \code{function(f) sum(f^2)}.}

\item{grid_weights}{Optional length-\code{G_grid} non-negative numeric vector.
Used only when \code{wrapper = NULL}. Defaults to uniform \code{1 / G_grid}.}
}
\value{
A length-\code{n} numeric vector of scalar summaries.
}
\description{
Many downstream quantities of interest (average treatment effect,
pointwise predictions, or other functionals of \eqn{f^{(0)}}) are scalar
summaries of the predicted function. \code{apply_wrapper()} applies any
user-supplied reduction to each row of a function matrix, with a default
of the weighted mean with respect to \code{grid_weights} (which coincides with
\eqn{\int f\,d\mu} when \code{grid_weights} represents \eqn{\mu}).
}
\examples{
F_mat <- matrix(1:12, nrow = 3, byrow = TRUE)  # 3 "functions" on a 4-point grid
apply_wrapper(F_mat)                            # row means (uniform grid weights)
apply_wrapper(F_mat, wrapper = max)             # row maxes
apply_wrapper(F_mat, wrapper = function(f) f[2]) # point evaluation at grid idx 2

}
