Skip to content

Commit 97c3bc7

Browse files
Noriccpenelopeysm
andauthored
Set minimum of OrderedLogistic distribution to 1 (#2603)
* Set minimum of OrderedLogistic distribution to 1 The minimum of the OrderedLogistic function is supposed to be 1, not 0. This is consistent with the documentation, and the behavior of the distribution when using rand(). * Add test for support of OrderedLogistic We add the test that the support should have the right number of elements, and that the probabilities add up to 1.0. * Format * Bump patch for release --------- Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
1 parent 7ebde76 commit 97c3bc7

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Release 0.39.2
2+
3+
Fixed a bug in the support of `OrderedLogistic` (by changing the minimum from 0 to 1).
4+
15
# Release 0.39.1
26

37
No changes from 0.39.0 — this patch is released just to re-trigger a Documenter.jl run.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Turing"
22
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
3-
version = "0.39.1"
3+
version = "0.39.2"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/stdlib/distributions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function OrderedLogistic(η, cutpoints::AbstractVector)
126126
return OrderedLogistic{typeof(η),typeof(cutpoints)}(η, cutpoints)
127127
end
128128

129-
Base.minimum(d::OrderedLogistic) = 0
129+
Base.minimum(d::OrderedLogistic) = 1
130130
Base.maximum(d::OrderedLogistic) = length(d.cutpoints) + 1
131131

132132
function Distributions.logpdf(d::OrderedLogistic, k::Real)

test/stdlib/distributions.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ using Turing
3232
@test all(((x, y),) -> abs(x - y) < 0.001, zip(p, pmf))
3333
end
3434

35+
@testset "distribution functions" begin
36+
d = OrderedLogistic(0, [1, 2, 3])
37+
38+
K = length(d.cutpoints) + 1
39+
@test support(d) == 1:K
40+
41+
# Adding up probabilities sums to 1
42+
s = sum(pdf.(d, support(d)))
43+
@test s 1.0 atol = 0.0001
44+
end
45+
3546
@testset "distributions functions" begin
3647
λ = 0.01:0.01:5
3748
LLp = @. logpdf(Poisson(λ), 1)

0 commit comments

Comments
 (0)