| loss_fun | R Documentation |
Computes prediction loss for kernel process models (BKP binary / DKP multi-class) during kernel hyperparameter tuning. Supports Brier score (MSE) and log-loss (cross-entropy) with leave-one-out cross-validation (LOOCV).
loss_fun(
gamma,
Xnorm,
y = NULL,
m = NULL,
Y = NULL,
model = c("BKP", "DKP"),
prior = c("noninformative", "fixed", "adaptive"),
r0 = 2,
p0 = NULL,
loss = c("brier", "log_loss"),
kernel = c("gaussian", "matern52", "matern32")
)
gamma |
Numeric vector; log10-transformed kernel lengthscale parameters. |
Xnorm |
Numeric matrix; normalized input matrix (values in [0,1]). |
y |
Numeric vector; observed success counts (BKP model only). |
m |
Numeric vector; number of trials (BKP model only). |
Y |
Numeric matrix; observed class counts (DKP model only). |
model |
Character string; model type: |
prior |
Character string; prior type: |
r0 |
Numeric scalar; prior precision (default = 2). |
p0 |
Numeric; global prior mean (for fixed prior). |
loss |
Character string; loss type: |
kernel |
Character string; kernel function: |
This function is used internally to optimize kernel lengthscales.
It converts log10 hyperparameters gamma to lengthscales theta,
computes the kernel matrix, applies LOOCV (diag(K)=0), and calculates loss
between estimated and empirical probabilities.
Numeric scalar; loss value to minimize during optimization.
Zhao J, Qing K, Xu J (2025). BKP: An R Package for Beta Kernel Process Modeling. arXiv. https://doi.org/10.48550/arXiv.2508.10447
get_prior, kernel_matrix
# -------------------------- BKP Example --------------------------
set.seed(123)
n <- 10
Xnorm <- matrix(runif(2 * n), ncol = 2)
m <- rep(10, n)
y <- rbinom(n, size = m, prob = runif(n))
loss_fun(gamma = rep(0, 2), Xnorm = Xnorm, y = y, m = m, model = "BKP")
# -------------------------- DKP Example --------------------------
set.seed(123)
n <- 10
q <- 3
Xnorm <- matrix(runif(2 * n), ncol = 2)
Y <- matrix(rmultinom(n, size = 10, prob = rep(1/q, q)), nrow = n, byrow = TRUE)
loss_fun(gamma = rep(0, 2), Xnorm = Xnorm, Y = Y, model = "DKP")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.