Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

scoringfunctions (version 1.1)

ghuber_sf: Generalized Huber scoring function

Description

The function ghuber_sf computes the generalized Huber scoring function at a specific level p and parameters a and b, when y materialises and x is the predictive Huber functional at level p.

The generalized Huber scoring function is defined by eq. (4.7) in Taggart (2022) for ϕ(t)=t2.

Usage

ghuber_sf(x, y, p, a, b)

Value

Vector of generalized Huber losses.

Arguments

x

Predictive Huber functional (prediction) at level p. It can be a vector of length n (must have the same length as y).

y

Realisation (true value) of process. It can be a vector of length n (must have the same length as x).

p

It can be a vector of length n (must have the same length as y).

a

It can be a vector of length n (must have the same length as y).

b

It can be a vector of length n (must have the same length as y).

Details

The generalized Huber scoring function is defined by:

S(x,y,p,a,b):=|1{xy}p|(y2(κa,b(xy)+y)2+2xκa,b(xy))

or equivalently

S(x,y,p,a,b):=|1{xy}p|fa,b(xy)

or

S(x,y,p,a,b):=pfa,b(max{(xy),0})+(1p)fa,b(max{xy,0})

where

fa,b(t):=κa,b(t)(2tκa,b(t))

and κa,b(t) is the capping function defined by:

κa,b(t):=max{min{t,b},a}

Domain of function:

xR

yR

0<p<1

a>0

b>0

Range of function:

S(x,y,p,a,b)0,x,yR,p(0,1),a,b>0

References

Taggart RJ (2022) Point forecasting and forecast evaluation with generalized Huber loss. Electronic Journal of Statistics 16:201--231. tools:::Rd_expr_doi("10.1214/21-EJS1957").

Examples

Run this code
# 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