Logistics.jl

LogisticsModule

Logistics.jl

Documentation Documentation CI Codecov Aqua.jl Quality Assurance

Logistics.jl defines the data type Logistic which represents real numbers in $[0, 1]$ (e.g. probabilities) with more numerically stable arithmetic operations.

Examples

The followings are some simple examples illustrating the usage of this package. Please see the documentation for more details of Logistics.jl.

julia> using Logistics

julia> x = Logistic(0)
Logistic{Float64}(0.0) ≈ 0.5

julia> y = logisticate(0.2)
Logistic{Float64}(-1.3862943611198906) ≈ 0.2

julia> x + y
Logistic{Float64}(0.8472978603872037) ≈ 0.7

julia> x - y
Logistic{Float64}(-0.8472978603872037) ≈ 0.3

julia> x * y
Logistic{Float64}(-2.197224577336219) ≈ 0.10000000000000002

julia> y / x
Logistic{Float64}(-0.40546510810816444) ≈ 0.4

julia> x ^ 2
Logistic{Float64}(-1.0986122886681098) ≈ 0.25

julia> mx = x ^ 10000
Logistic{Float64}(-6931.471805599453) ≈ 0.0

julia> my = y ^ 4307
Logistic{Float64}(-6931.84908885367) ≈ 0.0

julia> mx + my
Logistic{Float64}(-6930.949611751832) ≈ 0.0

julia> mx - my
Logistic{Float64}(-6932.629282338215) ≈ 0.0

julia> mx * my
Logistic{Float64}(-13863.320894453122) ≈ 0.0

julia> mx \ my
Logistic{Float64}(0.7801934845449816) ≈ 0.6857218127893691

julia> sqrt(mx)
Logistic{Float64}(-3465.7359027997263) ≈ 0.0

julia> cbrt(mx)
Logistic{Float64}(-2310.490601866484) ≈ 0.0

julia> log(y)
-1.6094379124341003

julia> logit(y)
-1.3862943611198906
source

The new type Logistic

Logistics.LogisticType
Logistic{T<:AbstractFloat} <: Real

Logistic(t::Real)
Logistic{T}(t::Real) where {T<:AbstractFloat}

A type representing real numbers in $[0,1]$ (e.g. probabilities) by their logit values.

Warning

Do not use Logistic to convert number types! For example, Logistic(0.39) equals $\operatorname{logistic}(0.39) \approx 0.60$ rather than $0.39$ in value. To convert a number to an equivalent Logistic instance, use logisticate or convert(Logistic, x).

source

New functions

Logistics.logisticateFunction
logisticate(x::Real) :: Logistic
logisticate(T::Type{<:AbstractFloat}, x::Real) :: Logistic{T}
logisticate(::Type{Logistic}, x::Real) :: Logistic
logisticate(::Type{<:Logistic{T}}, x::Real) 
	where {T<:AbstractFloat} :: Logistic{T}

Convert a Real number to its equivalent Logistic number.

Examples

julia> logisticate(0.39)
Logistic{Float64}(-0.4473122180436648) ≈ 0.39

julia> logisticate(Float32, 0.39)
Logistic{Float32}(-0.4473123) ≈ 0.39

julia> logisticate(Logistic, 0.39)
Logistic{Float64}(-0.4473122180436648) ≈ 0.39

julia> logisticate(Logistic{Float32}, 0.39)
Logistic{Float32}(-0.4473123) ≈ 0.39
source
Logistics.complementFunction
complement(x::Logistic) :: Logistic

Compute the complement, i.e., the difference between one and the argument.

Examples

julia> complement(logisticate(0.2))
Logistic{Float64}(1.3862943611198906) ≈ 0.8

julia> 1 - logisticate(0.2)
0.8
source
Logistics.halfFunction
half(::Type{Logistic}) :: Logistic
half(::Type{Logistic{T}}) where {T<:AbstractFloat} :: Logistic{T}
half(::Logistic{T}) where {T<:AbstractFloat} :: Logistic{T}

Return a Logistic number equal to a half.

Examples

julia> (logisticate(0) + logisticate(1)) / 2
Logistic{Float64}(0.0) ≈ 0.5

julia> half(Logistic{Float64})
Logistic{Float64}(0.0) ≈ 0.5
source
Logistics.logitexpFunction
logitexp(x::Real)

Return logit(exp(x)) evaluated carefully without intermediate calculation of exp(x).

Its inverse is the loglogistic function.

source
Logistics.loglogisticFunction
loglogistic(x::Real)

Return log(logistic(x)) evaluated carefully without intermediate calculation of logistic(x).

Its inverse is the logitexp function.

source

Functions from LogExpFunctions.jl

LogExpFunctions.logitFunction
logit(x)

The logit or log-odds transformation, defined as

\[\operatorname{logit}(x) = \log\left(\frac{x}{1-x}\right)\]

for $0 < x < 1$.

Its inverse is the logistic function.

LogExpFunctions.logisticFunction
logistic(x)

The logistic sigmoid function mapping a real number to a value in the interval $[0,1]$,

\[\sigma(x) = \frac{1}{e^{-x} + 1} = \frac{e^x}{1+e^x}.\]

Its inverse is the logit function.