Skip to content

Commit 216a87c

Browse files
willtebbuttxukai92
authored andcommitted
Some really minor changes (#578)
1 parent 9a42a06 commit 216a87c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/models/distributions.jl

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# No info
2-
struct Flat <: ContinuousUnivariateDistribution
3-
end
2+
struct Flat <: ContinuousUnivariateDistribution end
43

54
Distributions.rand(d::Flat) = rand()
65
Distributions.logpdf(d::Flat, x::T) where T<:Real= zero(x)
@@ -9,22 +8,21 @@ Distributions.maximum(d::Flat) = +Inf
98

109
# For vec support
1110
Distributions.rand(d::Flat, n::Int) = Vector([rand() for _ = 1:n])
12-
Distributions.logpdf(d::Flat, x::Vector{T}) where T<:Real= zero(x)
11+
Distributions.logpdf(d::Flat, x::AbstractVector{<:Real}) = zero(x)
1312

1413

1514
# Pos
1615
struct FlatPos{T<:Real} <: ContinuousUnivariateDistribution
1716
l::T
18-
FlatPos{T}(l::T) where T = new{T}(l)
1917
end
2018

21-
FlatPos(l::T) where T<:Real = FlatPos{T}(l)
22-
2319
Distributions.rand(d::FlatPos) = rand() + d.l
24-
Distributions.logpdf(d::FlatPos, x::T) where T<:Real = if x <= d.l -Inf else zero(x) end
20+
Distributions.logpdf(d::FlatPos, x::Real) = x <= d.l ? -Inf : zero(x)
2521
Distributions.minimum(d::FlatPos) = d.l
26-
Distributions.maximum(d::FlatPos) = +Inf
22+
Distributions.maximum(d::FlatPos) = Inf
2723

2824
# For vec support
2925
Distributions.rand(d::FlatPos, n::Int) = Vector([rand() for _ = 1:n] .+ d.l)
30-
Distributions.logpdf(d::FlatPos, x::Vector{T}) where T<:Real = if any(x .<= d.l) -Inf else zero(x) end
26+
function Distributions.logpdf(d::FlatPos, x::AbstractVector{<:Real})
27+
return any(x .<= d.l) ? -Inf : zero(x)
28+
end

0 commit comments

Comments
 (0)