From 2f946ce123a1dcb136fcceb2d34bab020bae28ae Mon Sep 17 00:00:00 2001 From: Mykola Lukashchuk Date: Mon, 15 Apr 2024 17:21:25 +0200 Subject: [PATCH] fix: ClosedWilliamsProduct for Exponetial on LogNormal --- src/Exponential/Exponential.jl | 2 +- test/Exponential/williams_tests.jl | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Exponential/Exponential.jl b/src/Exponential/Exponential.jl index 0b39b55..c9eaad8 100644 --- a/src/Exponential/Exponential.jl +++ b/src/Exponential/Exponential.jl @@ -32,7 +32,7 @@ function mean(::ClosedWilliamsProduct, q::Exponential, p::ExpLogSquare) return 1/(2*σ^2)*(-1/λ*(-2*(eulergamma+μ) + log(λ)) - log(λ)/λ) end -function mean(::ClosedFormExpectation, q::Exponential, p::LogNormal) +function mean(::ClosedWilliamsProduct, q::Exponential, p::LogNormal) μ, σ = p.μ, p.σ λ = mean(q) return 1/(2*σ^2)*(-1/λ*(-2*(eulergamma+μ) + log(λ)) - log(λ)/λ) - 1/λ diff --git a/test/Exponential/williams_tests.jl b/test/Exponential/williams_tests.jl index a3e3fea..fe24e3c 100644 --- a/test/Exponential/williams_tests.jl +++ b/test/Exponential/williams_tests.jl @@ -47,7 +47,7 @@ end end end -@testitem "meanlog(::ClosedWilliamsProduct, q::Exponential, p::LogNormal)" begin +@testitem "mean(::ClosedWilliamsProduct, q::Exponential, p::LogNormal)" begin using Distributions using ClosedFormExpectations using StableRNGs @@ -64,12 +64,11 @@ end μ = rand(rng)*10 σ = rand(rng)*10 λ = rand(rng)*10 - N = 10^7 + N = 10^6 samples = rand(rng, Exponential(λ), 10^6) fn(x) = logpdf(LogNormal(μ, σ), x) williams_product = map(x -> score(Exponential(λ), x)*fn(x), samples) - expectation = mean(ClosedWilliamsProduct(), Exponential(λ), ExpLogSquare(μ, σ)) - @show mean(williams_product) - @show expectation + expectation = mean(ClosedWilliamsProduct(), Exponential(λ), LogNormal(μ, σ)) + @test sigma_rule(expectation, mean(williams_product), std(williams_product), N) end end \ No newline at end of file