From 07d0ed520c80e272e1985aa505fc9b3cc20cef84 Mon Sep 17 00:00:00 2001 From: Ruben Seyer Date: Mon, 8 Jan 2024 15:09:20 +0100 Subject: [PATCH 1/2] Fix Gumbel gradlogpdf --- src/univariate/continuous/gumbel.jl | 2 +- test/gradlogpdf.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/univariate/continuous/gumbel.jl b/src/univariate/continuous/gumbel.jl index 92898ca7a2..8f062fa8d5 100644 --- a/src/univariate/continuous/gumbel.jl +++ b/src/univariate/continuous/gumbel.jl @@ -102,4 +102,4 @@ logcdf(d::Gumbel, x::Real) = -exp(-zval(d, x)) quantile(d::Gumbel, p::Real) = d.μ - d.θ * log(-log(p)) -gradlogpdf(d::Gumbel, x::Real) = - (1 + exp((d.μ - x) / d.θ)) / d.θ +gradlogpdf(d::Gumbel, x::Real) = (-1 + exp(-zval(d, x))) / d.θ diff --git a/test/gradlogpdf.jl b/test/gradlogpdf.jl index 5f54340ffd..f4216a67e6 100644 --- a/test/gradlogpdf.jl +++ b/test/gradlogpdf.jl @@ -9,7 +9,7 @@ using Test @test isapprox(gradlogpdf(Chisq(7.0), 12.0) , -0.29166666666666663, atol=1.0e-8) @test isapprox(gradlogpdf(Exponential(2.0), 7.0) , -0.5 , atol=1.0e-8) @test isapprox(gradlogpdf(Gamma(9.0, 0.5), 11.0) , -1.2727272727272727 , atol=1.0e-8) -@test isapprox(gradlogpdf(Gumbel(3.5, 1.0), 4.0) , -1.6065306597126334 , atol=1.0e-8) +@test isapprox(gradlogpdf(Gumbel(3.5, 1.0), 4.0) , -0.3934693402873666 , atol=1.0e-8) @test isapprox(gradlogpdf(Laplace(7.0), 34.0) , -1.0 , atol=1.0e-8) @test isapprox(gradlogpdf(Logistic(-6.0), 1.0) , -0.9981778976111987 , atol=1.0e-8) @test isapprox(gradlogpdf(LogNormal(5.5), 2.0) , 1.9034264097200273 , atol=1.0e-8) From 8f68d065590a4ddba3684ef40509fb71d151a727 Mon Sep 17 00:00:00 2001 From: Ruben Seyer Date: Mon, 8 Jan 2024 15:47:27 +0100 Subject: [PATCH 2/2] Use expm1 Co-authored-by: David Widmann --- src/univariate/continuous/gumbel.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/univariate/continuous/gumbel.jl b/src/univariate/continuous/gumbel.jl index 8f062fa8d5..7977a17027 100644 --- a/src/univariate/continuous/gumbel.jl +++ b/src/univariate/continuous/gumbel.jl @@ -102,4 +102,4 @@ logcdf(d::Gumbel, x::Real) = -exp(-zval(d, x)) quantile(d::Gumbel, p::Real) = d.μ - d.θ * log(-log(p)) -gradlogpdf(d::Gumbel, x::Real) = (-1 + exp(-zval(d, x))) / d.θ +gradlogpdf(d::Gumbel, x::Real) = expm1(-zval(d, x)) / d.θ