Skip to content
24 changes: 24 additions & 0 deletions src/univariate/continuous/cosine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,27 @@ function ccdf(d::Cosine{T}, x::Real) where T<:Real
end

quantile(d::Cosine, p::Real) = quantile_bisect(d, p)

function mgf(d::Cosine{T}, t::Real) where T<:Real
μ, σ = params(d)
t ≈ 0. && return exp(μ*t)
return T(π^2) * exp(μ*t) * sinh(σ*t) / (σ*t*(T(π^2) + (σ*t)^2))
end

function cgf(d::Cosine{T}, t::Real) where T<:Real
μ, σ = params(d)
t ≈ 0. && return μ*t
return 2log(π) + μ*t + σ*abs(t) + log1p(-exp(-2σ*abs(t))) - log(2) - log(σ*abs(t)) - log(T(π^2) + (σ*t)^2)
end

function cf(d::Cosine{T}, t::Real) where T<:Real
μ, σ = params(d)
t ≈ 0. && return one(complex(T))
σ*abs(t) ≈ π && return cis(μ*t) / 2
return T(π)^2 * cis(μ*t) * sin(σ*t) / (σ*t*(T(π)^2 - (σ*t)^2))
end

#### Affine transformations

Base.:+(d::Cosine, a::Real) = Cosine(d.μ + a, d.σ)
Base.:*(c::Real, d::Cosine) = Cosine(c * d.μ, abs(c) * d.σ)
Loading