# Compute the Bregman scoring function (type 1).
df <- data.frame(
y = rep(x = 0, times = 7),
x = c(-3, -2, -1, 0, 1, 2, 3),
a = rep(x = 3, times = 7)
)
df$bregman1_penalty <- bregman1_sf(x = df$x, y = df$y, a = df$a)
print(df)
# Equivalence of Bregman scoring function (type 1) and squared error scoring
# function, when a = 2.
set.seed(12345)
n <- 100
x <- runif(n, -20, 20)
y <- runif(n, -20, 20)
a <- rep(x = 2, times = n)
u <- bregman1_sf(x = x, y = y, a = a)
v <- serr_sf(x = x, y = y)
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