% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/GEMSS.R
\name{gemss_remove}
\alias{gemss_remove}
\title{Redundant Data Removal via GEMSS}
\usage{
gemss_remove(
  X,
  Y,
  X_val,
  Y_val,
  n_remove,
  covtype,
  c1 = NULL,
  threshold = 0.01,
  verbose = TRUE
)
}
\arguments{
\item{X}{an \code{n x p} matrix of input design locations.}

\item{Y}{an \code{n x 1} numeric vector of observed responses.}

\item{X_val, Y_val}{validation data used to evaluate predictive performance.
\code{X_val} must have the same number of columns as \code{X}.}

\item{n_remove}{an integer specifying the maximum number of data points to sequentially remove.}

\item{covtype}{a character string specifying the covariance kernel type. Must be
one of "Gaussian", "Matern5_2", or "Matern3_2".}

\item{c1}{a numeric value between 0 and 1 representing the weight of the first
term in the GEMSS criterion (\eqn{c_2 = 1 - c_1}). The default (\code{NULL})
uses the adaptive weighting proposed in the paper. A smaller \code{c1} places
greater emphasis on the space-filling properties of the reduced subset.}

\item{threshold}{a numeric value specifying the minimum required value of predictive
R-squared to justify removing points. Default is \code{0.01}.}

\item{verbose}{a logical value; if \code{TRUE}, progress is printed at each iteration.}
}
\value{
a list containing:
\itemize{
\item \code{index}: an integer vector of the indices of the retained training data points.
\item \code{remove}: an integer vector of the indices of the removed data points.
\item \code{eval_matrix}: a matrix detailing the removal sequence, including the step \code{j},
the \code{removed_id}, and the resulting out-of-sample \code{R2_pred}.
}
}
\description{
Implements a backward elimination process to sequentially remove redundant
data points from a Gaussian Process model using the GEMSS criterion.
}
\details{
In each iteration, the leave-one-out GEMSS criterion is computed for every point
in the training set. The point that yields the smallest criterion value
is removed. The predictive R-squared
is then calculated on the validation set to evaluate the performance of the reduced dataset.

If there exists a reduced dataset with a predictive R-squared value
greater than the specified \code{threshold}, the algorithm reports
the subset that maximizes the R-squared. Otherwise, no removal
is suggested.
}
\examples{
# Generate 1D data with intentionally clustered (redundant) points
set.seed(123)
X_reg <- seq(0, 1, length.out = 20)
X_cluster <- rnorm(10, mean = 0.5, sd = 0.01) # Redundant points tightly packed around x=0.5
X <- as.matrix(c(X_reg, X_cluster))
Y <- sin(2 * pi * X) + rnorm(30, sd = 0.05)

# Generate validation data
X_val <- as.matrix(seq(0.05, 0.95, length.out = 20))
Y_val <- sin(2 * pi * X_val) + rnorm(20, sd = 0.05)

# Run GEMSS removal
res <- gemss_remove(X, Y, X_val, Y_val, n_remove = 10,
covtype = "Matern3_2", verbose = TRUE)

# View the indices of the removed points
print(res$remove)
print(res$eval_matrix)

# Plot the removal data points (red)
plot(X, Y, main = "GEMSS Data Removal")
points(X[res$remove], Y[res$remove], pch = 19, col = 2)

# Compare GP predictions before and after removal
x_seq <- as.matrix(seq(0, 1, 0.02))
gp_bf <- hetGP::mleHomGP(X, Y, covtype = "Matern3_2")
lines(x_seq, predict(gp_bf, x_seq)$mean, col = 1, lty = 2)
gp_af <- hetGP::mleHomGP(X[-res$remove, , drop = FALSE],
Y[-res$remove], covtype = "Matern3_2")
lines(x_seq, predict(gp_af, x_seq)$mean, col = 3)

}
\references{
Chang, M. C., Hua, S. Z., & Wu, C. F. J. (2026). GEMSS-Driven Subsampling
for Information Extraction and Redundancy Elimination. \emph{Technometrics},
1–20. \doi{10.1080/00401706.2026.2670596}
}
