biogeme.models.boxcox_old module

Implements the Box-Cox model

author:

Michel Bierlaire

date:

Wed Oct 25 08:52:44 2023

biogeme.models.boxcox_old.boxcox_old(x, ell)[source]

Box-Cox transform. Old implementation, with Elem. Does not work for Bayesian estimation

\[B(x, \ell) = \frac{x^{\ell}-1}{\ell}.\]

It has the property that

\[\lim_{\ell \to 0} B(x,\ell)=\log(x).\]

To avoid numerical difficulties, if \(\ell < 10^{-5}\), the McLaurin approximation is used:

\[\log(x) + \ell \log(x)^2 + \frac{1}{6} \ell^2 \log(x)^3 + \frac{1}{24} \ell^3 \log(x)^4.\]
Parameters:
  • x (Expression | float | int | bool) – a variable to transform.

  • ell (Expression | float | int | bool) – parameter of the transformation.

Return type:

Expression

Returns:

the Box-Cox transform

biogeme.models.boxcox_old.boxcox_wrong(x, ell)[source]

Smooth approximate Box–Cox transform without piecewise control flow.

B(x, λ) = log(x) * [expm1(λ log x)] / (λ log x)

Return type:

Expression

Parameters:
Implementation details (all smooth; no Elem / no pt.switch):
  • Use log(x + ε_x) to avoid log(0).

  • Use expm1(z) / (z + ε_z) to avoid 0/0 at z ≈ 0.

  • Multiply by 1[x > 0] so the value is exactly 0 at x == 0.

Parameters

xExpressionOrNumeric

Variable to transform (assumed nonnegative; zeros are allowed).

ellExpressionOrNumeric

Box–Cox shape parameter.

Returns

Expression

Smooth approximation to the Box–Cox transform.