Skip to content

Link functions

A link function \(g(x)\) is a smooth, monotonic function of \(x\).

For all link functions, we implement

  • the link \(g(x)\)
  • the inverse \(g^{-1}(x)\)
  • the derivative of the link function \(\frac{\partial g(x)}{\partial x}\).
  • the first derivative of the inverse of the link function \(\frac{\partial g(x)^{-1}}{\partial x}\). The choice of the inverse is justified by Equation (7) in Hirsch, Berrisch & Ziel (2024).

The link functions implemented in ondil implemenent these as class methods each. Currently, we have implemented the identity-link, log-link and shifted log-link functions.

Link Function Description
Identity Implements the identity link function \(g(x) = x\).
Log Implements the logarithmic link function \(g(x) = \log(x)\).
LogShiftValue Log link function with a shift value added to the inverse transformation.
LogShiftTwo Log link function ensuring \(\hat{\theta} > 2\).
LogIdent Combines identity and log transformations.
Logit Implements the logit link function \(g(x) = \log(x/(1-x))\).
Sqrt Implements the square root link function \(g(x) = \sqrt{x}\).
SqrtShiftValue Square root link function with a shift value added to the inverse transformation.
SqrtShiftTwo Square root link function ensuring \(\hat{\theta} > 2\).
InverseSoftPlus Implements the inverse softplus link function.
InverseSoftPlusShiftValue Inverse softplus link function with a shift value added to the inverse transformation.
InverseSoftPlusShiftTwo Inverse softplus link function ensuring \(\hat{\theta} > 2\).

Some link functions implement shifted versions. The shifted link function is implemented in the sense that the shift is added to the inverse transformation. This way, we can ensure that distribution parameters can be modelled on the continuous space of the \(\eta = g(\theta)\), but in the inverse transform fullfill certain additional constraints. A common example is the \(t\) distribution, where we can use a LogShift2 or SqrtShift2Link to ensure that \(\hat{\theta} = g^-1(\eta) > 2\) and the variance exists.

Base Class

ondil.base.LinkFunction

Bases: ABC

The base class for the link functions.

link_support: Tuple[float, float]

The support of the distribution.

link(x: ndarray) -> np.ndarray

Calculate the Link

inverse abstractmethod

inverse(x: ndarray) -> np.ndarray

Calculate the inverse of the link function

link_derivative(x: ndarray) -> np.ndarray

Calculate the first derivative of the link function

link_second_derivative(x: ndarray) -> np.ndarray

Calculate the second derivative for the link function

inverse_derivative abstractmethod

inverse_derivative(x: ndarray) -> np.ndarray

Calculate the first derivative for the inverse link function

API Reference

ondil.links.Identity

Bases: LinkFunction

The identity link function.

The identity link is defined as \(g(x) = x\).

ondil.links.Log

Bases: LinkFunction

The log-link function.

The log-link function is defined as \(g(x) = \log(x)\).

ondil.links.LogShiftValue

Bases: LinkFunction

The Log-Link function shifted to a value \(v\).

This link function is defined as \(g(x) = \log(x - v)\). It can be used to ensure that certain distribution paramters don't fall below lower bounds, e.g. ensuring that the degrees of freedom of a Student's t distribtuion don't fall below 2, hence ensuring that the variance exists.

ondil.links.LogShiftTwo

Bases: LogShiftValue

The Log-Link function shifted to 2.

This link function is defined as \(g(x) = \log(x - 2)\). It can be used to ensure that certain distribution paramters don't fall below lower bounds, e.g. ensuring that the degrees of freedom of a Student's t distribtuion don't fall below 2, hence ensuring that the variance exists.

ondil.links.LogIdent

Bases: LinkFunction

The Logident Link function.

The LogIdent Link function has been introduced by Narajewski & Ziel 2020 and can be used to avoid the exponential inverse for large values while keeping the log-behaviour in small ranges. This can stabilize the estimation procedure.

ondil.links.Logit

Bases: LinkFunction

The Logit Link function.

The logit-link function is defined as \(g(x) = \log (x/ (1-x))\).

ondil.links.Sqrt

Bases: LinkFunction

The square root Link function.

The square root link function is defined as \(\(g(x) = \sqrt(x)\)\).

ondil.links.SqrtShiftValue

Bases: LinkFunction

The Sqrt-Link function shifted to a value \(v\).

This link function is defined as \(\(g(x) = \sqrt(x - v)\)\). It can be used to ensure that certain distribution paramters don't fall below lower bounds, e.g. ensuring that the degrees of freedom of a Student's t distribtuion don't fall below 2, hence ensuring that the variance exists.

ondil.links.SqrtShiftTwo

Bases: SqrtShiftValue

The Sqrt-Link function shifted to 2.

This link function is defined as \(\(g(x) = \sqrt(x - 2)\)\). It can be used to ensure that certain distribution paramters don't fall below lower bounds, e.g. ensuring that the degrees of freedom of a Student's t distribtuion don't fall below 2, hence ensuring that the variance exists.

ondil.links.InverseSoftPlus

Bases: LinkFunction

The softplus is defined as $$ \operatorname{SoftPlus(x)} = \log(1 + \exp(x)) $$ and hence the inverse is defined as $$ \log(\exp(x) - 1) $$ which can be used as link function for the parameters on the positive real line. The behavior of the inverse softplus is more graceful on large values as it avoids the exp of the log-link and converges towards a linear behaviour.

The softplus is the smooth approximation of \(\max(x, 0)\).

ondil.links.InverseSoftPlusShiftValue

Bases: LinkFunction

The Inverse SoftPlus function shifted to a value \(v\).

ondil.links.InverseSoftPlusShiftTwo

Bases: InverseSoftPlusShiftValue

The Inverse SoftPlus function shifted to 2.