Skip to content

Commit 4c9e968

Browse files
authored
Merge branch 'master' into dependabot/github_actions/codecov/codecov-action-4
2 parents 5ca92ea + 1376ee3 commit 4c9e968

File tree

8 files changed

+18
-28
lines changed

8 files changed

+18
-28
lines changed

src/Distributions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Supported distributions:
365365
NoncentralF, NoncentralHypergeometric, NoncentralT, Normal, NormalCanon,
366366
NormalInverseGaussian, Pareto, PGeneralizedGaussian, Poisson, PoissonBinomial,
367367
QQPair, Rayleigh, Rician, Skellam, Soliton, StudentizedRange, SymTriangularDist, TDist, TriangularDist,
368-
Triweight, Truncated, TruncatedNormal, Uniform, UnivariateGMM,
368+
Triweight, Truncated, Uniform, UnivariateGMM,
369369
VonMises, VonMisesFisher, WalleniusNoncentralHypergeometric, Weibull,
370370
Wishart, ZeroMeanIsoNormal, ZeroMeanIsoNormalCanon,
371371
ZeroMeanDiagNormal, ZeroMeanDiagNormalCanon, ZeroMeanFullNormal,

src/samplers/aliastable.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ end
1515

1616
function rand(rng::AbstractRNG, s::AliasTable)
1717
i = rand(rng, 1:length(s.alias)) % Int
18-
u = rand(rng)
19-
@inbounds r = u < s.accept[i] ? i : s.alias[i]
20-
r
18+
# using `ifelse` improves performance here: github.com/JuliaStats/Distributions.jl/pull/1831/
19+
ifelse(rand(rng) < s.accept[i], i, s.alias[i])
2120
end
2221

2322
show(io::IO, s::AliasTable) = @printf(io, "AliasTable with %d entries", ncategories(s))

src/truncate.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ end
8282
Truncated
8383
8484
Generic wrapper for a truncated distribution.
85+
86+
The *truncated normal distribution* is a particularly important one in the family of truncated distributions.
87+
Unlike the general case, truncated normal distributions support `mean`, `mode`, `modes`, `var`, `std`, and `entropy`.
8588
"""
8689
struct Truncated{D<:UnivariateDistribution, S<:ValueSupport, T<: Real, TL<:Union{T,Nothing}, TU<:Union{T,Nothing}} <: UnivariateDistribution{S}
8790
untruncated::D # the original distribution (untruncated)

src/truncated/normal.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
# Truncated normal distribution
2-
"""
3-
TruncatedNormal(mu, sigma, l, u)
4-
5-
The *truncated normal distribution* is a particularly important one in the family of truncated distributions.
6-
We provide additional support for this type with `TruncatedNormal` which calls `Truncated(Normal(mu, sigma), l, u)`.
7-
Unlike the general case, truncated normal distributions support `mean`, `mode`, `modes`, `var`, `std`, and `entropy`.
8-
"""
9-
TruncatedNormal
10-
11-
@deprecate TruncatedNormal(mu::Real, sigma::Real, a::Real, b::Real) truncated(Normal(mu, sigma), a, b)
12-
131
### statistics
142

153
function mode(d::Truncated{<:Normal{<:Real},Continuous,T}) where {T<:Real}

test/ref/continuous_test.lst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ TriangularDist(-4, 14, 3)
195195
TriangularDist(2, 2000, 500)
196196
TriangularDist(1, 3, 2)
197197

198-
TruncatedNormal(0, 1, -2, 2)
199-
TruncatedNormal(3, 10, 7, 8)
200-
TruncatedNormal(27, 3, 0, Inf)
201-
TruncatedNormal(-5, 1, -Inf, -10)
202-
TruncatedNormal(1.8, 1.2, -Inf, 0)
198+
truncated(Normal(0, 1), lower = -2, upper = 2)
199+
truncated(Normal(3, 10), lower = 7, upper = 8)
200+
truncated(Normal(27, 3), lower = 0)
201+
truncated(Normal(-5, 1), upper = -10)
202+
truncated(Normal(1.8, 1.2), upper = 0)
203203

204204
Uniform()
205205
Uniform(0.0, 2.0)

test/ref/continuous_test.ref.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,7 +5157,7 @@
51575157
},
51585158
{
51595159
"expr": "truncated(Normal(0, 1), -2, 2)",
5160-
"dtype": "TruncatedNormal",
5160+
"dtype": "Truncated",
51615161
"minimum": -2,
51625162
"maximum": 2,
51635163
"properties": {
@@ -5187,7 +5187,7 @@
51875187
},
51885188
{
51895189
"expr": "truncated(Normal(3, 10), 7, 8)",
5190-
"dtype": "TruncatedNormal",
5190+
"dtype": "Truncated",
51915191
"minimum": 7,
51925192
"maximum": 8,
51935193
"properties": {
@@ -5217,7 +5217,7 @@
52175217
},
52185218
{
52195219
"expr": "truncated(Normal(27, 3); lower=0)",
5220-
"dtype": "TruncatedNormal",
5220+
"dtype": "Truncated",
52215221
"minimum": 0,
52225222
"maximum": "inf",
52235223
"properties": {
@@ -5247,7 +5247,7 @@
52475247
},
52485248
{
52495249
"expr": "truncated(Normal(-5, 1); upper=-10)",
5250-
"dtype": "TruncatedNormal",
5250+
"dtype": "Truncated",
52515251
"minimum": "-inf",
52525252
"maximum": -10,
52535253
"properties": {
@@ -5277,7 +5277,7 @@
52775277
},
52785278
{
52795279
"expr": "truncated(Normal(1.8, 1.2); upper=0)",
5280-
"dtype": "TruncatedNormal",
5280+
"dtype": "Truncated",
52815281
"minimum": "-inf",
52825282
"maximum": 0,
52835283
"properties": {

test/truncate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function verify_and_test_drive(jsonfile, selected, n_tsamples::Int,lower::Int,up
3939

4040
println(" testing truncated($(ex),$lower,$upper)")
4141
d = truncated(eval(Meta.parse(ex)),lower,upper)
42-
if dtype != Uniform && dtype != DiscreteUniform && dtype != TruncatedNormal # Uniform is truncated to Uniform
42+
if dtype != Uniform && dtype != DiscreteUniform # Uniform is truncated to Uniform
4343
@assert isa(dtype, Type) && dtype <: UnivariateDistribution
4444
@test isa(d, dtypet)
4545
# verification and testing

test/univariates.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function verify_and_test(D::Union{Type,Function}, d::UnivariateDistribution, dct
5454
# Note: properties include all applicable params and stats
5555
#
5656

57-
# D can be a function, e.g. TruncatedNormal
57+
# D can be a function
5858
if isa(D, Type)
5959
@assert isa(d, D)
6060
end

0 commit comments

Comments
 (0)