Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/codecov/codecov-…
Browse files Browse the repository at this point in the history
…action-4
  • Loading branch information
ViralBShah authored Feb 27, 2024
2 parents 5ca92ea + 1376ee3 commit 4c9e968
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Supported distributions:
NoncentralF, NoncentralHypergeometric, NoncentralT, Normal, NormalCanon,
NormalInverseGaussian, Pareto, PGeneralizedGaussian, Poisson, PoissonBinomial,
QQPair, Rayleigh, Rician, Skellam, Soliton, StudentizedRange, SymTriangularDist, TDist, TriangularDist,
Triweight, Truncated, TruncatedNormal, Uniform, UnivariateGMM,
Triweight, Truncated, Uniform, UnivariateGMM,
VonMises, VonMisesFisher, WalleniusNoncentralHypergeometric, Weibull,
Wishart, ZeroMeanIsoNormal, ZeroMeanIsoNormalCanon,
ZeroMeanDiagNormal, ZeroMeanDiagNormalCanon, ZeroMeanFullNormal,
Expand Down
5 changes: 2 additions & 3 deletions src/samplers/aliastable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ end

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

show(io::IO, s::AliasTable) = @printf(io, "AliasTable with %d entries", ncategories(s))
3 changes: 3 additions & 0 deletions src/truncate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ end
Truncated
Generic wrapper for a truncated distribution.
The *truncated normal distribution* is a particularly important one in the family of truncated distributions.
Unlike the general case, truncated normal distributions support `mean`, `mode`, `modes`, `var`, `std`, and `entropy`.
"""
struct Truncated{D<:UnivariateDistribution, S<:ValueSupport, T<: Real, TL<:Union{T,Nothing}, TU<:Union{T,Nothing}} <: UnivariateDistribution{S}
untruncated::D # the original distribution (untruncated)
Expand Down
12 changes: 0 additions & 12 deletions src/truncated/normal.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# Truncated normal distribution
"""
TruncatedNormal(mu, sigma, l, u)
The *truncated normal distribution* is a particularly important one in the family of truncated distributions.
We provide additional support for this type with `TruncatedNormal` which calls `Truncated(Normal(mu, sigma), l, u)`.
Unlike the general case, truncated normal distributions support `mean`, `mode`, `modes`, `var`, `std`, and `entropy`.
"""
TruncatedNormal

@deprecate TruncatedNormal(mu::Real, sigma::Real, a::Real, b::Real) truncated(Normal(mu, sigma), a, b)

### statistics

function mode(d::Truncated{<:Normal{<:Real},Continuous,T}) where {T<:Real}
Expand Down
10 changes: 5 additions & 5 deletions test/ref/continuous_test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ TriangularDist(-4, 14, 3)
TriangularDist(2, 2000, 500)
TriangularDist(1, 3, 2)

TruncatedNormal(0, 1, -2, 2)
TruncatedNormal(3, 10, 7, 8)
TruncatedNormal(27, 3, 0, Inf)
TruncatedNormal(-5, 1, -Inf, -10)
TruncatedNormal(1.8, 1.2, -Inf, 0)
truncated(Normal(0, 1), lower = -2, upper = 2)
truncated(Normal(3, 10), lower = 7, upper = 8)
truncated(Normal(27, 3), lower = 0)
truncated(Normal(-5, 1), upper = -10)
truncated(Normal(1.8, 1.2), upper = 0)

Uniform()
Uniform(0.0, 2.0)
Expand Down
10 changes: 5 additions & 5 deletions test/ref/continuous_test.ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -5157,7 +5157,7 @@
},
{
"expr": "truncated(Normal(0, 1), -2, 2)",
"dtype": "TruncatedNormal",
"dtype": "Truncated",
"minimum": -2,
"maximum": 2,
"properties": {
Expand Down Expand Up @@ -5187,7 +5187,7 @@
},
{
"expr": "truncated(Normal(3, 10), 7, 8)",
"dtype": "TruncatedNormal",
"dtype": "Truncated",
"minimum": 7,
"maximum": 8,
"properties": {
Expand Down Expand Up @@ -5217,7 +5217,7 @@
},
{
"expr": "truncated(Normal(27, 3); lower=0)",
"dtype": "TruncatedNormal",
"dtype": "Truncated",
"minimum": 0,
"maximum": "inf",
"properties": {
Expand Down Expand Up @@ -5247,7 +5247,7 @@
},
{
"expr": "truncated(Normal(-5, 1); upper=-10)",
"dtype": "TruncatedNormal",
"dtype": "Truncated",
"minimum": "-inf",
"maximum": -10,
"properties": {
Expand Down Expand Up @@ -5277,7 +5277,7 @@
},
{
"expr": "truncated(Normal(1.8, 1.2); upper=0)",
"dtype": "TruncatedNormal",
"dtype": "Truncated",
"minimum": "-inf",
"maximum": 0,
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion test/truncate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function verify_and_test_drive(jsonfile, selected, n_tsamples::Int,lower::Int,up

println(" testing truncated($(ex),$lower,$upper)")
d = truncated(eval(Meta.parse(ex)),lower,upper)
if dtype != Uniform && dtype != DiscreteUniform && dtype != TruncatedNormal # Uniform is truncated to Uniform
if dtype != Uniform && dtype != DiscreteUniform # Uniform is truncated to Uniform
@assert isa(dtype, Type) && dtype <: UnivariateDistribution
@test isa(d, dtypet)
# verification and testing
Expand Down
2 changes: 1 addition & 1 deletion test/univariates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function verify_and_test(D::Union{Type,Function}, d::UnivariateDistribution, dct
# Note: properties include all applicable params and stats
#

# D can be a function, e.g. TruncatedNormal
# D can be a function
if isa(D, Type)
@assert isa(d, D)
end
Expand Down

0 comments on commit 4c9e968

Please sign in to comment.