# Compute the generalized Huber scoring function.
set.seed(12345)
n <- 10
df <- data.frame(
x = runif(n, -2, 2),
y = runif(n, -2, 2),
p = runif(n, 0, 1),
a = runif(n, 0, 1),
b = runif(n, 0, 1)
)
df$ghuber_penalty <- ghuber_sf(x = df$x, y = df$y, p = df$p, a = df$a, b = df$b)
print(df)
# Equivalence of the generalized Huber scoring function and the asymmetric
# piecewise quadratic scoring function (expectile scoring function), when
# a = Inf and b = Inf.
set.seed(12345)
n <- 100
x <- runif(n, -20, 20)
y <- runif(n, -20, 20)
p <- runif(n, 0, 1)
a <- rep(x = Inf, times = n)
b <- rep(x = Inf, times = n)
u <- ghuber_sf(x = x, y = y, p = p, a = a, b = b)
v <- expectile_sf(x = x, y = y, p = p)
max(abs(u - v)) # values are slightly higher than 0 due to rounding error
min(abs(u - v))
# Equivalence of the generalized Huber scoring function and the Huber scoring
# function when p = 1/2 and a = b.
set.seed(12345)
n <- 100
x <- runif(n, -20, 20)
y <- runif(n, -20, 20)
p <- rep(x = 1/2, times = n)
a <- runif(n, 0, 20)
u <- ghuber_sf(x = x, y = y, p = p, a = a, b = a)
v <- huber_sf(x = x, y = y, a = a)
max(abs(u - v)) # values are slightly higher than 0 due to rounding error
min(abs(u - v))
Run the code above in your browser using DataLab