Skip to contents

Computes the loss used to fit the BKP model. Supports the Brier score (mean squared error) and negative log-loss (cross-entropy), under different prior specifications.

Usage

loss_fun(
  gamma,
  Xnorm,
  y,
  m,
  prior = c("noninformative", "fixed", "adaptive"),
  r0 = 2,
  p0 = 0.5,
  loss = c("brier", "log_loss"),
  kernel = c("gaussian", "matern52", "matern32")
)

Arguments

gamma

A numeric vector of log-transformed kernel hyperparameters.

Xnorm

A numeric matrix of normalized inputs (each column scaled to [0,1]).

y

A numeric vector of observed successes (length n).

m

A numeric vector of total binomial trials (length n), corresponding to each y.

prior

Type of prior to use. One of "noninformative", "fixed", or "adaptive".

r0

Global prior precision (only used when prior = "fixed" or "adaptive").

p0

Global prior mean (only used when prior = "fixed").

loss

Loss function for kernel hyperparameter tuning. One of "brier" (default) or "log_loss".

kernel

Kernel function for local weighting. Choose from "gaussian", "matern52", or "matern32".

Value

A single numeric value representing the total loss (to be minimized).

Examples

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)
#> [1] 0.009313263