From a32a4515c1dae2cc1abaee447cabc01dda7568a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Wed, 3 Dec 2025 21:50:37 +0100 Subject: [PATCH 01/15] Update cosine.jl --- src/univariate/continuous/cosine.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index 4d11a9ddde..9c9e17fe7a 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -93,3 +93,21 @@ 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::Real) + μ, σ = params(d) + return π^2 * exp(μ*t) * sinh(σ*t) / (σ*t*(π^2 + (σ*t)^2)) +end + +function cgf(d::Cosine{T}, t) where T<:Real + μ, σ = params(d) + t ≈ 0. && return one(complex(T)) + σ*abs(t) ≈ π && return cis(μ*t) / 2 + + return π^2 * cis(μ*t) * sin(σ*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.σ) From 0ef458c8c209d820923b0ce2d09a33cd25f176f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Wed, 3 Dec 2025 22:09:05 +0100 Subject: [PATCH 02/15] Update cosine.jl --- src/univariate/continuous/cosine.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index 9c9e17fe7a..3294f9320f 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -96,6 +96,7 @@ quantile(d::Cosine, p::Real) = quantile_bisect(d, p) function mgf(d::Cosine, t::Real) μ, σ = params(d) + t ≈ 0. && return exp(μ*t) return π^2 * exp(μ*t) * sinh(σ*t) / (σ*t*(π^2 + (σ*t)^2)) end From 9739851afc9541cab38fe084ab96c8137b27bfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Wed, 3 Dec 2025 22:10:36 +0100 Subject: [PATCH 03/15] Update cosine.jl --- src/univariate/continuous/cosine.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index 3294f9320f..16d8df3054 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -104,7 +104,6 @@ function cgf(d::Cosine{T}, t) where T<:Real μ, σ = params(d) t ≈ 0. && return one(complex(T)) σ*abs(t) ≈ π && return cis(μ*t) / 2 - return π^2 * cis(μ*t) * sin(σ*t) / (σ*t*(π^2 - (σ*t)^2)) end From e7f7d4526038cc1aab73f28dd0ddf226f6dc786c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Wed, 3 Dec 2025 22:35:57 +0100 Subject: [PATCH 04/15] Update cosine.jl --- src/univariate/continuous/cosine.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index 16d8df3054..bd37564824 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -94,17 +94,17 @@ end quantile(d::Cosine, p::Real) = quantile_bisect(d, p) -function mgf(d::Cosine, t::Real) +function mgf(d::Cosine{T}, t::Real) where T<:Real μ, σ = params(d) t ≈ 0. && return exp(μ*t) - return π^2 * exp(μ*t) * sinh(σ*t) / (σ*t*(π^2 + (σ*t)^2)) + return T(π^2) * exp(μ*t) * sinh(σ*t) / (σ*t*(T(π^2) + (σ*t)^2)) end -function cgf(d::Cosine{T}, t) where T<:Real +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 π^2 * cis(μ*t) * sin(σ*t) / (σ*t*(π^2 - (σ*t)^2)) + return T(π)^2 * cis(μ*t) * sin(σ*t) / (σ*t*(T(π)^2 - (σ*t)^2)) end #### Affine transformations From c687dbbe71474d71436b5088b14e52e0f61dc86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Thu, 4 Dec 2025 19:48:55 +0100 Subject: [PATCH 05/15] add cgf --- src/univariate/continuous/cosine.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index bd37564824..1bf536b975 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -100,6 +100,12 @@ function mgf(d::Cosine{T}, t::Real) where T<:Real 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)) From 1d43ceadbb73736b57a87cd90e0095b61544a7d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Thu, 4 Dec 2025 22:27:42 +0100 Subject: [PATCH 06/15] Update src/univariate/continuous/cosine.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Müller-Widmann --- src/univariate/continuous/cosine.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index 1bf536b975..c549f4ad34 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -95,7 +95,7 @@ end quantile(d::Cosine, p::Real) = quantile_bisect(d, p) function mgf(d::Cosine{T}, t::Real) where T<:Real - μ, σ = params(d) + (; μ, σ) = d t ≈ 0. && return exp(μ*t) return T(π^2) * exp(μ*t) * sinh(σ*t) / (σ*t*(T(π^2) + (σ*t)^2)) end From ccae0fb5014c148cfbd5fb5d100c7ee2d398520b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Thu, 4 Dec 2025 22:28:19 +0100 Subject: [PATCH 07/15] Update src/univariate/continuous/cosine.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Müller-Widmann --- src/univariate/continuous/cosine.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index c549f4ad34..e910e74de6 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -94,7 +94,7 @@ end quantile(d::Cosine, p::Real) = quantile_bisect(d, p) -function mgf(d::Cosine{T}, t::Real) where T<:Real +function mgf(d::Cosine, t::Real) (; μ, σ) = d t ≈ 0. && return exp(μ*t) return T(π^2) * exp(μ*t) * sinh(σ*t) / (σ*t*(T(π^2) + (σ*t)^2)) From 58a05996249c338b73fb44ac32037e416cc8d8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Thu, 4 Dec 2025 22:28:56 +0100 Subject: [PATCH 08/15] Update src/univariate/continuous/cosine.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Müller-Widmann --- src/univariate/continuous/cosine.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index e910e74de6..8911c020c5 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -96,8 +96,9 @@ quantile(d::Cosine, p::Real) = quantile_bisect(d, p) function mgf(d::Cosine, t::Real) (; μ, σ) = d - t ≈ 0. && return exp(μ*t) - return T(π^2) * exp(μ*t) * sinh(σ*t) / (σ*t*(T(π^2) + (σ*t)^2)) + σt = σ * t + z = iszero(σt) ? one(float(σt)) : sinh(σ*t)/(σ*t) + return exp(μ*t) * (z / (1 + (IrrationalConstants.invπ * σt)^2)) end function cgf(d::Cosine{T}, t::Real) where T<:Real From e688e375271d5a2d8df903e227677ddc5023965a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Thu, 4 Dec 2025 22:29:36 +0100 Subject: [PATCH 09/15] Update src/univariate/continuous/cosine.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Müller-Widmann --- src/univariate/continuous/cosine.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index 8911c020c5..ceaa062101 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -101,10 +101,11 @@ function mgf(d::Cosine, t::Real) return exp(μ*t) * (z / (1 + (IrrationalConstants.invπ * σ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) +function cgf(d::Cosine, t::Real) + (; μ, σ) = d + σt = σ * t + z = iszero(σt) ? zero(float(σt)) : LogExpFunctions.logabssinh(σt) - log(σt) + return μ*t + z - LogExpFunctions.log1psq(invπ * σt) end function cf(d::Cosine{T}, t::Real) where T<:Real From 430e71395c2dd3857330224ab8f45293fbf01e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Thu, 4 Dec 2025 23:12:02 +0100 Subject: [PATCH 10/15] Update cosine.jl --- src/univariate/continuous/cosine.jl | 46 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index ceaa062101..d9dc788210 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -59,34 +59,37 @@ kurtosis(d::Cosine{T}) where {T<:Real} = 6*(90-T(π)^4) / (5*(T(π)^2-6)^2) #### Evaluation -function pdf(d::Cosine{T}, x::Real) where T<:Real +function pdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} + W = promote_type(T, S) if insupport(d, x) z = (x - d.μ) / d.σ return (1 + cospi(z)) / (2d.σ) else - return zero(T) + return zero(W) end end logpdf(d::Cosine, x::Real) = log(pdf(d, x)) -function cdf(d::Cosine{T}, x::Real) where T<:Real +function cdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} + W = promote_type(T, S) if x < d.μ - d.σ - return zero(T) + return zero(W) end if x > d.μ + d.σ - return one(T) + return one(W) end z = (x - d.μ) / d.σ (1 + z + sinpi(z) * invπ) / 2 end -function ccdf(d::Cosine{T}, x::Real) where T<:Real +function cdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} + W = promote_type(T, S) if x < d.μ - d.σ - return one(T) + return one(W) end if x > d.μ + d.σ - return zero(T) + return zero(W) end nz = (d.μ - x) / d.σ (1 + nz + sinpi(nz) * invπ) / 2 @@ -94,25 +97,26 @@ end quantile(d::Cosine, p::Real) = quantile_bisect(d, p) +import IrrationalConstants: invπ +import LogExpFunctions: logabssinh, log1psq + function mgf(d::Cosine, t::Real) - (; μ, σ) = d - σt = σ * t - z = iszero(σt) ? one(float(σt)) : sinh(σ*t)/(σ*t) - return exp(μ*t) * (z / (1 + (IrrationalConstants.invπ * σt)^2)) + σt, μt = d.σ * t, d.μ*t + z = iszero(σt) ? one(float(σt)) : sinh(σt)/σt + return exp(μt) * (z / (1 + (invπ * σt)^2)) end function cgf(d::Cosine, t::Real) - (; μ, σ) = d - σt = σ * t - z = iszero(σt) ? zero(float(σt)) : LogExpFunctions.logabssinh(σt) - log(σt) - return μ*t + z - LogExpFunctions.log1psq(invπ * σt) + σt, μt = d.σ * t, d.μ*t + z = iszero(σt) ? zero(float(σt)) : logabssinh(σt) - log(σt) + return μt + z - log1psq(invπ * σt) 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)) +function cf(d::Cosine, t::Real) + σt, μt = d.σ * t, d.μ*t + abs(σt) ≈ π && return cis(μt) / 2 + z = iszero(σt) ? one(float(σt)) : sin(σt)/σt + return π^2 * cis(μt) * z / (π^2 - (σt)^2) end #### Affine transformations From 10394b93dd4c4176779cfebfad0b7d9f2a425401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Fri, 5 Dec 2025 00:13:34 +0100 Subject: [PATCH 11/15] test + dependencies --- src/Distributions.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Distributions.jl b/src/Distributions.jl index fcf6994347..b0d540fdb8 100644 --- a/src/Distributions.jl +++ b/src/Distributions.jl @@ -25,8 +25,9 @@ import StatsBase: kurtosis, skewness, entropy, mode, modes, import PDMats: dim, PDMat, invquad using SpecialFunctions +import LogExpFunctions: logabssinh, log1psq using Base.MathConstants: eulergamma - +import IrrationalConstants: invπ import AliasTables export From 2c4edb5d6b8522b6beb44d56a8a437e8f615b12e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Fri, 5 Dec 2025 00:15:58 +0100 Subject: [PATCH 12/15] test + dependencies --- Project.toml | 4 ++++ test/univariate/continuous/cosine.jl | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/univariate/continuous/cosine.jl diff --git a/Project.toml b/Project.toml index 643ea0f47e..e4bf95ef41 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,8 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d" FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688" +IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6" PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" @@ -43,6 +45,8 @@ FiniteDifferences = "0.12" ForwardDiff = "0.10, 1" JSON = "0.21" LinearAlgebra = "<0.0.1, 1" +LogExpFunctions = "0.3.29" +IrrationalConstants = "0.2.6" OffsetArrays = "1" PDMats = "0.11.35" Printf = "<0.0.1, 1" diff --git a/test/univariate/continuous/cosine.jl b/test/univariate/continuous/cosine.jl new file mode 100644 index 0000000000..db4496fe19 --- /dev/null +++ b/test/univariate/continuous/cosine.jl @@ -0,0 +1,13 @@ +@testset "Cosine" begin + @testset "mgf, cgf, cf" begin + @test cf(Cosine(1, 1), 1) ≈ cis(1) * sin(1)/(1 - π^-2) + @test mgf(Cosine(-1, 2), -1) ≈ exp(1) * sinh(-2) / (-2*(1 + 4π^-2)) + @test cgf(Cosine(-1, 2), 2) ≈ -2 + log(sinh(4)) - log(4) - log(1 + 16π^-2) + end + + @testset "affine transfomations" begin + @test -Cosine(1, 1) == Cosine(-1, 1) + @test 3Cosine(1, 2) == Cosine(3, 6) + @test Cosine(0, 2) + 42 == Cosine(42, 2) + end +end \ No newline at end of file From ce1016e22c7445f2a79212f156a55c5cf81e6133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Fri, 5 Dec 2025 00:47:51 +0100 Subject: [PATCH 13/15] logpdf + tweaks --- src/univariate/continuous/cosine.jl | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index d9dc788210..e2d4b712f7 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -60,46 +60,45 @@ kurtosis(d::Cosine{T}) where {T<:Real} = 6*(90-T(π)^4) / (5*(T(π)^2-6)^2) #### Evaluation function pdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} - W = promote_type(T, S) if insupport(d, x) z = (x - d.μ) / d.σ return (1 + cospi(z)) / (2d.σ) else - return zero(W) + return zero(promote_type(T, S)) end end -logpdf(d::Cosine, x::Real) = log(pdf(d, x)) +function logpdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} + if insupport(d, x) + z = (x - d.μ) / d.σ + return log1p(cospi(z)) - log(2d.σ) + else + return typemin(promote_type(T, S)) + end +end function cdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} W = promote_type(T, S) - if x < d.μ - d.σ - return zero(W) - end - if x > d.μ + d.σ - return one(W) - end + + x < d.μ - d.σ && return zero(W) + x > d.μ + d.σ && return one(W) + z = (x - d.μ) / d.σ (1 + z + sinpi(z) * invπ) / 2 end -function cdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} +function ccdf(d::Cosine{T}, x::S) where {T<:Real, S<:Real} W = promote_type(T, S) - if x < d.μ - d.σ - return one(W) - end - if x > d.μ + d.σ - return zero(W) - end + + x < d.μ - d.σ && return one(W) + x > d.μ + d.σ && return zero(W) + nz = (d.μ - x) / d.σ (1 + nz + sinpi(nz) * invπ) / 2 end quantile(d::Cosine, p::Real) = quantile_bisect(d, p) -import IrrationalConstants: invπ -import LogExpFunctions: logabssinh, log1psq - function mgf(d::Cosine, t::Real) σt, μt = d.σ * t, d.μ*t z = iszero(σt) ? one(float(σt)) : sinh(σt)/σt From 2f37977c14846b6a209f8cafe5f27e5012c8d08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Fri, 5 Dec 2025 01:16:10 +0100 Subject: [PATCH 14/15] Update cosine.jl --- test/univariate/continuous/cosine.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/univariate/continuous/cosine.jl b/test/univariate/continuous/cosine.jl index db4496fe19..e05b86da6d 100644 --- a/test/univariate/continuous/cosine.jl +++ b/test/univariate/continuous/cosine.jl @@ -5,7 +5,7 @@ @test cgf(Cosine(-1, 2), 2) ≈ -2 + log(sinh(4)) - log(4) - log(1 + 16π^-2) end - @testset "affine transfomations" begin + @testset "affine transformations" begin @test -Cosine(1, 1) == Cosine(-1, 1) @test 3Cosine(1, 2) == Cosine(3, 6) @test Cosine(0, 2) + 42 == Cosine(42, 2) From f3d5850bca3fe70e39a71bdbcebce0332aff3b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=9Al=C4=99zak?= <128084860+jaksle@users.noreply.github.com> Date: Fri, 5 Dec 2025 23:35:31 +0100 Subject: [PATCH 15/15] add invpi to cf --- src/univariate/continuous/cosine.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/univariate/continuous/cosine.jl b/src/univariate/continuous/cosine.jl index e2d4b712f7..33a6527e7a 100644 --- a/src/univariate/continuous/cosine.jl +++ b/src/univariate/continuous/cosine.jl @@ -100,22 +100,22 @@ end quantile(d::Cosine, p::Real) = quantile_bisect(d, p) function mgf(d::Cosine, t::Real) - σt, μt = d.σ * t, d.μ*t + σt, μt = d.σ * t, d.μ * t z = iszero(σt) ? one(float(σt)) : sinh(σt)/σt return exp(μt) * (z / (1 + (invπ * σt)^2)) end function cgf(d::Cosine, t::Real) - σt, μt = d.σ * t, d.μ*t + σt, μt = d.σ * t, d.μ * t z = iszero(σt) ? zero(float(σt)) : logabssinh(σt) - log(σt) return μt + z - log1psq(invπ * σt) end function cf(d::Cosine, t::Real) - σt, μt = d.σ * t, d.μ*t + σt, μt = d.σ * t, d.μ * t abs(σt) ≈ π && return cis(μt) / 2 z = iszero(σt) ? one(float(σt)) : sin(σt)/σt - return π^2 * cis(μt) * z / (π^2 - (σt)^2) + return cis(μt) * z / (1 - (invπ * σt)^2) end #### Affine transformations