1
1
# No info
2
- struct Flat <: ContinuousUnivariateDistribution
3
- end
2
+ struct Flat <: ContinuousUnivariateDistribution end
4
3
5
4
Distributions. rand (d:: Flat ) = rand ()
6
5
Distributions. logpdf (d:: Flat , x:: T ) where T<: Real = zero (x)
@@ -9,22 +8,21 @@ Distributions.maximum(d::Flat) = +Inf
9
8
10
9
# For vec support
11
10
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)
13
12
14
13
15
14
# Pos
16
15
struct FlatPos{T<: Real } <: ContinuousUnivariateDistribution
17
16
l:: T
18
- FlatPos {T} (l:: T ) where T = new {T} (l)
19
17
end
20
18
21
- FlatPos (l:: T ) where T<: Real = FlatPos {T} (l)
22
-
23
19
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)
25
21
Distributions. minimum (d:: FlatPos ) = d. l
26
- Distributions. maximum (d:: FlatPos ) = + Inf
22
+ Distributions. maximum (d:: FlatPos ) = Inf
27
23
28
24
# For vec support
29
25
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