From a25552fa01c9b864288f2c115e291ea35788a371 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 4 Jul 2026 12:05:44 +0000 Subject: [PATCH 1/3] implement shifloNormal_mode --- src/DistributionFits.jl | 2 +- src/univariate/continuous/logitnormal.jl | 25 ++++++++++++++++++++--- test/univariate/continuous/logitnormal.jl | 21 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/DistributionFits.jl b/src/DistributionFits.jl index 023103f..c903dc0 100644 --- a/src/DistributionFits.jl +++ b/src/DistributionFits.jl @@ -35,7 +35,7 @@ export export AbstractΣstar, Σstar, σstar, ScaledLogNormal # LogitNormal -export fit_mode_flat, shifloNormal +export fit_mode_flat, shifloNormal, shifloNormal_mode # dependency inversion: need to define DistributionFits.optimize by user export AbstractDistributionFitOptimizer, optimize diff --git a/src/univariate/continuous/logitnormal.jl b/src/univariate/continuous/logitnormal.jl index 3e55ac3..90c3f25 100644 --- a/src/univariate/continuous/logitnormal.jl +++ b/src/univariate/continuous/logitnormal.jl @@ -113,13 +113,13 @@ true """ function fit_mode_flat(::Type{LogitNormal}, mode::T, - ::Val{nTry} = Val(40); + ntry::Val{nTry} = Val(40); peakedness = 1) where {T <: Real, nTry} - fit_mode_flat(LogitNormal{T}, mode, Val(nTry); peakedness) + fit_mode_flat(LogitNormal{T}, mode, ntry; peakedness) end function fit_mode_flat(::Type{LogitNormal{T}}, mode, - ::Val{nTry} = Val(40); + ntry::Val{nTry} = Val(40); peakedness = 1) where {T <: Real, nTry} mode == 0.5 && return (LogitNormal{T}(zero(T), sqrt(2) / peakedness)) is_right = mode > 0.5 @@ -158,3 +158,22 @@ function shifloNormal(lower, upper) #dln * (upper-lower) + lower Distributions.AffineDistribution{T}(lower, (upper - lower), dln) end + +""" + shifloNormal_mode(lower,upper,mode; peakedness=1.1) + +Shifted LogitNormal where mode and peakedness are specified. +Note, that this requires optimization, while shifloNormal without mode +is a closed form solution. +""" +function shifloNormal_mode(lower, upper, mode, + ntry::Val{nTry} = Val(40); + peakedness = 1.0) where {nTry} + lower, upper, mode = promote(lower, upper, mode / 1) + T = typeof(lower) + mode1 = (mode-lower)/(upper-lower) + dln = fit_mode_flat(LogitNormal{T}, mode1, ntry; peakedness) + #dln * (upper-lower) + lower + Distributions.AffineDistribution{T}(lower, (upper - lower), dln) +end + diff --git a/test/univariate/continuous/logitnormal.jl b/test/univariate/continuous/logitnormal.jl index eadeab0..aea1e2e 100644 --- a/test/univariate/continuous/logitnormal.jl +++ b/test/univariate/continuous/logitnormal.jl @@ -134,3 +134,24 @@ end; #plot(d) #dln = LogitNormal(0f0,sqrt(2f0)); plot!(dln) end; + +@testset "shifloNormal_mode Float32" begin + d32 = shifloNormal_mode(1.0f0, 3.0f0, 1.5f0) + @test partype(d32) == Float32 + @test mean(d32) isa Float32 + # wait until fix in AffineDistribution is merged to Distributions.jl + # @test rand(d32) isa eltype(d32) + m = mode(d32) + @test m isa Float32 + @test isapprox(m, 1.5, atol = 0.1) + dmin = minimum(d32) + @test dmin == 1.0 + @test maximum(d32) == 3.0 + @test scale(d32) == 3 - 1 + @test scale(d32) isa Float32 + @test location(d32) == 1.0 + @test location(d32) isa Float32 + #using StatsPlots + #plot(d32) + #dln = LogitNormal(0f0,sqrt(2f0)); plot!(dln) +end; From 08cd7cf16f5a431d305cbbf6bc2e3ff9b775d1c7 Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 4 Jul 2026 12:12:50 +0000 Subject: [PATCH 2/3] typo --- docs/src/partype.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/partype.md b/docs/src/partype.md index 24ca490..3f35d56 100644 --- a/docs/src/partype.md +++ b/docs/src/partype.md @@ -22,7 +22,7 @@ true If the parametric type is omitted, default Float64 is assumed, or inferred from other parameters of the fitting function. -Since quantiles and median are rather sample-like measures than paraemter-like +Since quantiles and median are rather sample-like measures than parameter-like measures, they do not influence the inferred parameter type. From 56b68c6cfa590896244b0b6080b948ef9603c4eb Mon Sep 17 00:00:00 2001 From: Thomas Wutzler Date: Sat, 4 Jul 2026 12:14:39 +0000 Subject: [PATCH 3/3] update docu --- docs/src/logitnormal.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/logitnormal.md b/docs/src/logitnormal.md index 4ed12fb..de5f38d 100644 --- a/docs/src/logitnormal.md +++ b/docs/src/logitnormal.md @@ -62,8 +62,12 @@ p # hide A shifted and scaled version of this distribution can be used as a moother alternative to the Bounded uniform distribution. +When no information on mode or peakedness is required, prefer the option +without mode, because those does not require optimization. + ```@docs shifloNormal +shifloNormal_mode ```