% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/r2.R
\name{r2_exact}
\alias{r2_exact}
\title{Exact R2 indicator}
\usage{
r2_exact(x, reference, maximise = FALSE)
}
\arguments{
\item{x}{\code{matrix()}|\code{data.frame()}\cr Matrix or data frame of numerical
values, where each row gives the coordinates of a point.}

\item{reference}{\code{numeric()}\cr Reference (ideal) point as a vector of numerical
values.}

\item{maximise}{\code{logical()}\cr Whether the objectives must be maximised
instead of minimised. Either a single logical value that applies to all
objectives or a vector of logical values, with one value per objective.}
}
\value{
\code{numeric(1)} A single numerical value.
}
\description{
Computes the exact R2 indicator with respect to a given ideal/utopian
reference point assuming minimization of all objectives.
}
\details{
The unary R2 indicator is a quality indicator for a set \eqn{A \subset
\mathbb{R}^m}{A in R^m} w.r.t. an ideal or utopian reference point
\eqn{\vec{r} \in \mathbb{R}^m}{r in R^m}.  It was originally proposed by
\citet{HanJas1998} and is defined as the expected Tchebycheff utility under a
uniform distribution of weight vectors (w.l.o.g. assuming minimization):

\deqn{R2(A) := \int_{w \in W} \min_{a \in A} \left\{ \max_{i=1,\dots,m} w_i
(a_i - r_i) \right\} \, dw,}{R2(A) := integral over w in W of min over a in
A of max over i of w_i (a_i - r_i) dw,}

where \eqn{W} denotes the uniform distribution across weights:

\deqn{W = \{w \in \mathbb{R}^m \mid w_i \geq 0, \sum_{i=1}^m w_i = 1\}.}{W
= \{w in R^m | w_i >= 0, sum_i w_i = 1\}.}

The R2 indicator is to be minimized and has an optimal value of 0 when
\eqn{\vec{r} \in A}{r in A}.

The exact R2 indicator is strongly Pareto-compliant, i.e., compatible with
Pareto-optimality:

\deqn{\forall A, B \subset \mathbb{R}^m: A \prec B \Rightarrow R2(A) <
R2(B).}{for all A, B in R^m: A dominates B implies R2(A) < R2(B).}

Given an ideal or utopian reference point, which is available in most
scenarios, all non-dominated solutions always contribute to the value of
the exact R2 indicator.  However, it is scale-dependent and care should be
taken such that all objectives contribute approximately equally to the
indicator, e.g., by normalizing the Pareto front to the unit hypercube.

The current implementation exclusively supports bi-objective solution sets
and runs in \eqn{O(n \log n)} following \citet{SchKer2025r2v2}.
}
\references{
\insertAllCited{}
}
\concept{metrics}
\examples{
dat <- matrix(c(5, 5, 4, 6, 2, 7, 7, 4), ncol = 2, byrow = TRUE)
r2_exact(dat, reference = c(0, 0))

# This function assumes minimisation by default. We can easily specify maximisation:
r2_exact(dat, reference = c(10, 10), maximise = TRUE)

# Merge all the sets of a dataset by removing the set number column:
extdata_path <- system.file(package="moocore","extdata")
dat <- read_datasets(file.path(extdata_path, "example1_dat"))[, 1:2]
nrow(dat)

# Dominated points are ignored, so this:
r2_exact(dat, reference = 0)

# gives the same exact R2 value as this:
dat <- filter_dominated(dat)
nrow(dat)
r2_exact(dat, reference = 0)
}
