Skip to content

Commit

Permalink
Merge branch 'master' into type_generic_normal
Browse files Browse the repository at this point in the history
  • Loading branch information
gdalle committed Jan 13, 2024
2 parents 4b27b30 + c1705a3 commit 27ea06f
Show file tree
Hide file tree
Showing 72 changed files with 1,124 additions and 519 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ jobs:
- 'nightly'
os:
- ubuntu-latest
- macos-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down Expand Up @@ -62,7 +64,7 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: '1'
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
4 changes: 2 additions & 2 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: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
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
18 changes: 18 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
Expand All @@ -12,4 +28,6 @@ jobs:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
ssh: ${{ secrets.DOCUMENTER_KEY }}
# ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }}
41 changes: 30 additions & 11 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Distributions"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
authors = ["JuliaStats"]
version = "0.25.95"
version = "0.25.107"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -12,31 +12,53 @@ PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
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]
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"

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

[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 @@ -46,13 +68,10 @@ FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["StableRNGs", "Calculus", "ChainRulesCore", "ChainRulesTestUtils", "DensityInterface", "Distributed", "FiniteDifferences", "ForwardDiff", "JSON", "StaticArrays", "Test", "OffsetArrays"]

[weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
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 = "0.26, 0.27"
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
2 changes: 1 addition & 1 deletion perf/mixtures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ large_probs .= large_probs ./ sum(large_probs)

gmm_large = MixtureModel(large_normals, large_probs)

@info "Large Gausian mixture"
@info "Large Gaussian mixture"

Random.seed!(42)
for x in rand(5)
Expand Down
8 changes: 5 additions & 3 deletions src/Distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export
Logistic,
LogNormal,
LogUniform,
MvLogitNormal,
LogitNormal,
MatrixBeta,
MatrixFDist,
Expand Down Expand Up @@ -315,15 +316,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
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 27ea06f

Please sign in to comment.