Skip to content

Commit

Permalink
fix: ClosedWilliamsProduct for Exponetial on LogNormal
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimrais committed Apr 15, 2024
1 parent 4fd8cc7 commit 2f946ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Exponential/Exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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/λ
Expand Down
9 changes: 4 additions & 5 deletions test/Exponential/williams_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 2f946ce

Please sign in to comment.