# Compute the Bregman scoring function (type 2).
df <- data.frame(
y = rep(x = 2, times = 6),
x = rep(x = 1:3, times = 2),
b = rep(x = c(-3, 3), each = 3)
)
df$bregman2_penalty <- bregman2_sf(x = df$x, y = df$y, b = df$b)
print(df)
# The Bregman scoring function (type 2) is half the squared error scoring
# function, when b = 2.
df <- data.frame(
y = rep(x = 5.5, times = 10),
x = 1:10,
b = rep(x = 2, times = 10)
)
df$bregman2_penalty <- bregman2_sf(x = df$x, y = df$y, b = df$b)
df$squared_error <- serr_sf(x = df$x, y = df$y)
df$ratio <- df$bregman2_penalty/df$squared_error
print(df)
# When a = b > 1 the Bregman scoring function (type 2) coincides with the
# Bregman scoring function (type 1) up to a multiplicative constant.
df <- data.frame(
y = rep(x = 5.5, times = 10),
x = 1:10,
b = rep(x = c(3, 4), each = 5)
)
df$bregman2_penalty <- bregman2_sf(x = df$x, y = df$y, b = df$b)
df$bregman1_penalty <- bregman1_sf(x = df$x, y = df$y, a = df$b)
df$ratio <- df$bregman2_penalty/df$bregman1_penalty
print(df)
Run the code above in your browser using DataLab