Logistics.jl
Logistics
— ModuleLogistics.jl
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
The new type Logistic
Logistics.Logistic
— TypeLogistic{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.
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)
.
New functions
Logistics.logisticate
— Functionlogisticate(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
Logistics.complement
— Functioncomplement(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
Logistics.half
— Functionhalf(::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
Logistics.logitexp
— Functionlogitexp(x::Real)
Return logit(exp(x))
evaluated carefully without intermediate calculation of exp(x)
.
Its inverse is the loglogistic
function.
Logistics.loglogistic
— Functionloglogistic(x::Real)
Return log(logistic(x))
evaluated carefully without intermediate calculation of logistic(x)
.
Its inverse is the logitexp
function.
Functions from LogExpFunctions.jl
LogExpFunctions.logit
— FunctionLogExpFunctions.logistic
— Function