Skip to content

Commit

Permalink
Merge branch 'master' into compathelper/new_version/2023-09-16-00-05-…
Browse files Browse the repository at this point in the history
…54-816-00041392826
  • Loading branch information
ViralBShah authored May 7, 2024
2 parents d7cff06 + 818814f commit 424fd87
Show file tree
Hide file tree
Showing 58 changed files with 718 additions and 317 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v3
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
Expand All @@ -57,15 +57,17 @@ jobs:
Pkg.instantiate()'
- run: julia --project=perf perf/samplers.jl
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
fail_ci_if_error: true
files: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/DocPreviewCleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Delete preview and history + push changes
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/IntegrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ jobs:
#- {user: TuringLang, repo: DistributionsAD.jl, group: ForwardDiff} takes > 1 hour

steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: 1
arch: x64
- uses: julia-actions/julia-buildpkg@latest
- name: Clone Downstream
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
path: downstream
Expand Down
25 changes: 23 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "Distributions"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
authors = ["JuliaStats"]
version = "0.25.100"
version = "0.25.108"

[deps]
AliasTables = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand All @@ -22,24 +23,44 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[extensions]
DistributionsChainRulesCoreExt = "ChainRulesCore"
DistributionsDensityInterfaceExt = "DensityInterface"
DistributionsTestExt = "Test"

[compat]
AliasTables = "1"
Aqua = "0.8"
Calculus = "0.5"
ChainRulesCore = "1"
ChainRulesTestUtils = "1"
DensityInterface = "0.4"
Distributed = "<0.0.1, 1"
FillArrays = "0.9, 0.10, 0.11, 0.12, 0.13, 1"
FiniteDifferences = "0.12"
ForwardDiff = "0.10"
JSON = "0.21"
LinearAlgebra = "<0.0.1, 1"
OffsetArrays = "1"
PDMats = "0.10, 0.11"
Printf = "<0.0.1, 1"
QuadGK = "2"
Random = "<0.0.1, 1"
SparseArrays = "<0.0.1, 1"
SpecialFunctions = "1.2, 2"
StableRNGs = "1"
StaticArrays = "1"
Statistics = "1"
StatsAPI = "1.6"
StatsBase = "0.32, 0.33, 0.34"
StatsFuns = "0.9.15, 1"
Test = "<0.0.1, 1"
julia = "1.3"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
Expand All @@ -55,4 +76,4 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["StableRNGs", "Calculus", "ChainRulesCore", "ChainRulesTestUtils", "DensityInterface", "Distributed", "FiniteDifferences", "ForwardDiff", "JSON", "SparseArrays", "StaticArrays", "Test", "OffsetArrays"]
test = ["Aqua", "StableRNGs", "Calculus", "ChainRulesCore", "ChainRulesTestUtils", "DensityInterface", "Distributed", "FiniteDifferences", "ForwardDiff", "JSON", "SparseArrays", "StaticArrays", "Test", "OffsetArrays"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Distributions.jl
[![Build Status](https://github.com/JuliaStats/Distributions.jl/workflows/CI/badge.svg)](https://github.com/JuliaStats/Distributions.jl/actions)
[![](https://zenodo.org/badge/DOI/10.5281/zenodo.2647458.svg)](https://zenodo.org/record/2647458)
[![Coverage Status](https://coveralls.io/repos/JuliaStats/Distributions.jl/badge.svg?branch=master)](https://coveralls.io/r/JuliaStats/Distributions.jl?branch=master)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)

[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://JuliaStats.github.io/Distributions.jl/latest/)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaStats.github.io/Distributions.jl/stable/)
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"

[compat]
Documenter = "1"
GR = "0.72.1"
GR = "0.72.1, 0.73"
1 change: 1 addition & 0 deletions docs/src/multivariate.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Multinomial
Distributions.AbstractMvNormal
MvNormal
MvNormalCanon
MvLogitNormal
MvLogNormal
Dirichlet
Product
Expand Down
101 changes: 101 additions & 0 deletions ext/DistributionsTestExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
module DistributionsTestExt

using Distributions
using Distributions.LinearAlgebra
using Distributions.Random
using Test

__rand(::Nothing, args...) = rand(args...)
__rand(rng::AbstractRNG, args...) = rand(rng, args...)

__rand!(::Nothing, args...) = rand!(args...)
__rand!(rng::AbstractRNG, args...) = rand!(rng, args...)

"""
test_mvnormal(
g::AbstractMvNormal,
n_tsamples::Int=10^6,
rng::Union{Random.AbstractRNG, Nothing}=nothing,
)
Test that `AbstractMvNormal` implements the expected API.
!!! Note
On Julia >= 1.9, you have to load the `Test` standard library to be able to use
this function.
"""
function Distributions.TestUtils.test_mvnormal(
g::AbstractMvNormal, n_tsamples::Int=10^6, rng::Union{AbstractRNG, Nothing}=nothing
)
d = length(g)
μ = mean(g)
Σ = cov(g)
@test length(μ) == d
@test size(Σ) == (d, d)
@test var(g) diag(Σ)
@test entropy(g) 0.5 * logdet(2π ** Σ)
ldcov = logdetcov(g)
@test ldcov logdet(Σ)
vs = diag(Σ)
@test g == typeof(g)(params(g)...)
@test g == deepcopy(g)
@test minimum(g) == fill(-Inf, d)
@test maximum(g) == fill(Inf, d)
@test extrema(g) == (minimum(g), maximum(g))
@test isless(extrema(g)...)

# test sampling for AbstractMatrix (here, a SubArray):
subX = view(__rand(rng, d, 2d), :, 1:d)
@test isa(__rand!(rng, g, subX), SubArray)

# sampling
@test isa(__rand(rng, g), Vector{Float64})
X = __rand(rng, g, n_tsamples)
emp_mu = vec(mean(X, dims=2))
Z = X .- emp_mu
emp_cov = (Z * Z') * inv(n_tsamples)

mean_atols = 8 .* sqrt.(vs ./ n_tsamples)
cov_atols = 10 .* sqrt.(vs .* vs') ./ sqrt.(n_tsamples)
for i = 1:d
@test isapprox(emp_mu[i], μ[i], atol=mean_atols[i])
end
for i = 1:d, j = 1:d
@test isapprox(emp_cov[i,j], Σ[i,j], atol=cov_atols[i,j])
end

X = rand(MersenneTwister(14), g, n_tsamples)
Y = rand(MersenneTwister(14), g, n_tsamples)
@test X == Y
emp_mu = vec(mean(X, dims=2))
Z = X .- emp_mu
emp_cov = (Z * Z') * inv(n_tsamples)
for i = 1:d
@test isapprox(emp_mu[i] , μ[i] , atol=mean_atols[i])
end
for i = 1:d, j = 1:d
@test isapprox(emp_cov[i,j], Σ[i,j], atol=cov_atols[i,j])
end


# evaluation of sqmahal & logpdf
U = X .- μ
sqm = vec(sum(U .*\ U), dims=1))
for i = 1:min(100, n_tsamples)
@test sqmahal(g, X[:,i]) sqm[i]
end
@test sqmahal(g, X) sqm

lp = -0.5 .* sqm .- 0.5 * (d * log(2.0 * pi) + ldcov)
for i = 1:min(100, n_tsamples)
@test logpdf(g, X[:,i]) lp[i]
end
@test logpdf(g, X) lp

# log likelihood
@test loglikelihood(g, X) sum(i -> Distributions._logpdf(g, X[:,i]), 1:n_tsamples)
@test loglikelihood(g, X[:, 1]) logpdf(g, X[:, 1])
@test loglikelihood(g, [X[:, i] for i in axes(X, 2)]) loglikelihood(g, X)
end

end # module
12 changes: 8 additions & 4 deletions src/Distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import PDMats: dim, PDMat, invquad
using SpecialFunctions
using Base.MathConstants: eulergamma

import AliasTables

export
# re-export Statistics
mean, median, quantile, std, var, cov, cor,
Expand Down Expand Up @@ -122,6 +124,7 @@ export
Logistic,
LogNormal,
LogUniform,
MvLogitNormal,
LogitNormal,
MatrixBeta,
MatrixFDist,
Expand Down Expand Up @@ -315,15 +318,16 @@ include("mixtures/unigmm.jl")
# Interface for StatsAPI
include("statsapi.jl")

# Testing utilities for other packages which implement distributions.
include("test_utils.jl")

# Extensions: Implementation of DensityInterface and ChainRulesCore API
if !isdefined(Base, :get_extension)
include("../ext/DistributionsChainRulesCoreExt/DistributionsChainRulesCoreExt.jl")
include("../ext/DistributionsDensityInterfaceExt.jl")
include("../ext/DistributionsTestExt.jl")
end

# Testing utilities for other packages which implement distributions.
include("test_utils.jl")

include("deprecates.jl")

"""
Expand Down Expand Up @@ -363,7 +367,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
1 change: 1 addition & 0 deletions src/censored.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ _in_open_interval(x::Real, l::Real, ::Nothing) = x > l
_clamp(x, l, u) = clamp(x, l, u)
_clamp(x, ::Nothing, u) = min(x, u)
_clamp(x, l, ::Nothing) = max(x, l)
_clamp(x, ::Nothing, u::Nothing) = x

_to_truncated(d::Censored) = truncated(d.uncensored, d.lower, d.upper)

Expand Down
2 changes: 1 addition & 1 deletion src/cholesky/lkjcholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function _lkj_cholesky_onion_tri!(
# equivalent steps in algorithm in reference are marked.
@assert size(A) == (d, d)
A[1, 1] = 1
d > 1 || return R
d > 1 || return A
β = η + (d - 2)//2
# 1. Initialization
w0 = 2 * rand(rng, Beta(β, β)) - 1
Expand Down
Loading

0 comments on commit 424fd87

Please sign in to comment.