Skip to content

Commit 360d427

Browse files
authored
Multivariate dist (#8)
* up codecov * modified: src/continuous/Burr.jl * Rename Package * modified: src/ProbabilityDistributions.jl * modified: Project.toml * modified: Project.toml * rename again * add multivariate t, normal distributions and CDF * add tests * modified: Project.toml * modified: docs/src/bestiary/multivariate.md * modified: docs/src/bestiary/multivariate.md modified: test/continuous_test.jl
1 parent a1f3c38 commit 360d427

File tree

12 files changed

+1380
-55
lines changed

12 files changed

+1380
-55
lines changed

Project.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
name = "AdditionalDistributions"
22
uuid = "6655a985-646a-4595-ab89-59c8a6085518"
3+
version = "0.1.1"
34
authors = ["Santiago Jimenez Ramos <[email protected]>"]
45
description = "A collection of additional probability distributions not included in Distributions.jl, fully compatible with its API."
5-
version = "0.1.1"
66

77
[deps]
88
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
99
HypergeometricFunctions = "34004b35-14d8-5ef3-9330-4cdb6864b03a"
1010
LambertW = "984bce1d-4616-540c-a9ee-88d1112d94c9"
11+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1112
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
13+
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
1214
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
1315
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1416
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
@@ -19,9 +21,12 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1921
[compat]
2022
Aqua = "0.8"
2123
Distributions = "0.25"
24+
ForwardDiff = "0.10, 1"
2225
HypergeometricFunctions = "0.3"
2326
LambertW = "0.4"
27+
LinearAlgebra = "1"
2428
LogExpFunctions = "0.3"
29+
Primes = "0.5.7"
2530
QuadGK = "2"
2631
Random = "1"
2732
Roots = "1"
@@ -32,14 +37,15 @@ StatsBase = "0.33"
3237
Test = "1"
3338
TestItemRunner = "1.1.0"
3439
TestItems = "1.0.0"
35-
julia = "1.9"
40+
julia = "1.6, 1.9"
3641

3742
[extras]
3843
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
44+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
3945
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
4046
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4147
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
4248
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
4349

4450
[targets]
45-
test = ["Test", "StableRNGs", "Aqua", "TestItemRunner", "TestItems"]
51+
test = ["Test", "StableRNGs", "Aqua", "TestItemRunner", "TestItems", "ForwardDiff"]

README.md

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,93 @@
55
[![Build Status](https://github.com/Santymax98/AdditionalDistributions.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/Santymax98/AdditionalDistributions.jl/actions/workflows/CI.yml?query=branch%3Amain)
66
[![Coverage](https://codecov.io/gh/Santymax98/AdditionalDistributions.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/Santymax98/AdditionalDistributions.jl)
77

8-
The [*AdditionalDistributions*](https://github.com/Santymax98/AdditionalDistributions.jl) package is a comprehensive extension of [*Distributions.jl*](https://github.com/JuliaStats/Distributions.jl).
9-
It is designed to expand the functionality of the base package by incorporating both discrete and continuous probability distributions that are not included in `Distributions`, either due to their specialized nature or because they are less commonly used.
10-
*AdditionalDistributions* aims to provide a broader range of statistical tools for data analysis, simulation, and probabilistic modeling, catering to both academic and scientific needs where these additional distributions are essential.
11-
128
---
139

14-
## Motivation and Relationship with Distributions.jl
15-
16-
Although several additional distributions have been proposed for inclusion in `Distributions.jl` as early as [JuliaStats/Distributions.jl#124](https://github.com/JuliaStats/Distributions.jl/issues/124) (2013), many of them have not yet been integrated into the main package.
17-
The motivation behind *AdditionalDistributions.jl* is therefore to provide a **flexible yet rigorous, API-compatible environment** for developing and testing both classical and new distribution families — **without compromising statistical quality, numerical stability, or consistency** with the `Distributions.jl` interface.
10+
**AdditionalDistributions.jl** extends the [Distributions.jl](https://github.com/JuliaStats/Distributions.jl)
11+
ecosystem by providing additional discrete, continuous, and multivariate probability
12+
distributions that are not yet available in the base package.
1813

19-
This package also serves as a foundation for future **multivariate** and **computationally optimized distributions**, designed for efficient integration with [`Copulas.jl`](https://github.com/lrnv/Copulas.jl), where the author is an active co-developer.
20-
These implementations aim to offer faster, more stable probability evaluations for dependence modeling and simulation, while remaining interoperable with the broader JuliaStats ecosystem.
14+
It maintains full API compatibility (`pdf`, `cdf`, `rand`, etc.) and emphasizes
15+
**accuracy, efficiency, and completeness** — integrating advanced cumulative
16+
probability algorithms for multivariate Gaussian and Student’s *t* models.
2117

2218
---
2319

24-
## Purpose and Scope
20+
## 🔹 Key Features
2521

26-
The purpose of `AdditionalDistributions.jl` is to serve as a well-maintained repository for distributions that are too exotic or specialized to be included in the main `Distributions.jl` package.
27-
This includes distributions that are frequently required in specific fields of research but are not yet available in Julia, as well as new or experimental distributions that may not be widely used but have significant potential applications.
22+
- 📈 **Extensive library of distributions** — zero-inflated, generalized, and heavy-tailed families.
23+
-**High-performance QMC algorithms** for multivariate CDFs (`MvGaussian`, `MvTStudent`),
24+
significantly faster than [MvNormalCDF.jl](https://github.com/JuliaStats/MvNormalCDF.jl)
25+
with minimal loss in absolute precision (typically within `1e-5``1e-6`).
26+
- 🧮 **Full API compatibility** with `Distributions.jl`.
27+
- 🧩 **Research-oriented architecture**, extensible to new distributional forms.
28+
- 🧠 **Reproducibility-focused testing**, with benchmarks aligned with *mvtnorm* (R, Genz & Bretz 2002).
29+
30+
---
2831

29-
For instance, you can define the following distributions (among many others):
32+
## 🚀 Example
3033

3134
```julia
32-
julia> using Distributions, AdditionalDistributions
33-
julia> BetaNegBinomial(r, α, β) # Discrete univariate
34-
julia> Lomax(α, λ) # Continuous univariate
35-
julia> ZINB(r, θ, p) # Discrete univariate
36-
julia> Gompertz(η, b) # Continuous univariate
35+
using AdditionalDistributions
36+
37+
# Univariate and multivariate distributions
38+
d1 = Lomax=2.0, λ=3.0)
39+
d2 = ZINB(r=4, θ=0.7, p=0.2)
40+
41+
pdf(d1, 1.5), cdf(d2, 3)
42+
43+
# Accurate CDF for a multivariate t distribution
44+
Σ = [1.0 0.5; 0.5 1.0]
45+
d3 = MvTStudent=5, Σ)
46+
cdf(d3, [-1.0, -1.0], [1.0, 1.0])
3747
```
3848

39-
These distributions, along with others like the ARGUS or Zero-Inflated Poisson (ZIP), are essential in various fields of research but are not included in the base `Distributions.jl` package.
40-
`AdditionalDistributions.jl` provides these and more, ensuring that users have access to a broad spectrum of statistical tools.
49+
---
50+
51+
## 🧩 Performance Highlights
52+
53+
| Algorithm | Library | Mean Error | Relative Speed |
54+
| ------------------------ | ---------------------------- | ---------- | ------------------ |
55+
| QMC–Sobol (this package) | `AdditionalDistributions.jl` | `≈ 1e-5` | **1.5×–3× faster** |
56+
| Adaptive Genz–Bretz | `MvNormalCDF.jl` | `≈ 1e-6` | slower |
57+
| QRSVN (R `mvtnorm`) | Reference | `≈ 1e-6` ||
58+
59+
Our implementation sacrifices a marginal amount of absolute precision
60+
for a substantial speedup in moderate to high dimensions (3–25).
4161

4262
---
4363

44-
## Key Features
64+
## 🧭 Roadmap
4565

46-
* **Extensive Range of Distributions:** Includes a wide variety of distributions, some of which are not commonly found in standard statistical libraries.
47-
* **Seamless Integration:** Fully compatible with `Distributions.jl`, allowing joint use with other packages in the Julia ecosystem.
48-
* **Detailed Documentation:** Comprehensive references and examples for each implemented distribution.
49-
* **Community-Driven Development:** Contributions are welcome — from new distributions to documentation improvements.
66+
* [ ] Add `Generalized Hyperbolic` and `Skew-t` families.
67+
* [ ] Implement flexible parameter fitting (`fit_mle`, `fit_map`).
68+
* [ ] Integrate symbolic representations for documentation.
69+
* [ ] Parallelize with threads
70+
* [ ] Maybe GPU-parallelized QMC backend (planned).
5071

5172
---
5273

53-
## Maintaining Relevance and Utility
74+
## 🤝 Contributing
5475

55-
Given the importance of these additional distributions in various academic and scientific applications, we are committed to the ongoing maintenance and development of `AdditionalDistributions.jl`.
56-
Our goal is to ensure that the package remains a valuable resource for the Julia community.
57-
To support this, we are considering moving the package under the `JuliaStats` organization, which would provide additional support and visibility, ensuring its long-term sustainability.
76+
We welcome contributions!
77+
All code follows the design and testing conventions of
78+
[`Distributions.jl`](https://github.com/JuliaStats/Distributions.jl),
79+
ensuring consistency and interoperability.
5880

59-
With *AdditionalDistributions*, you can:
81+
### Guidelines
6082

61-
* **Sample from distributions:** Draw random samples from a variety of distributions.
62-
* **Calculate moments and other properties:** Obtain moments (mean, variance, skewness, kurtosis), entropy, and other statistical metrics.
63-
* **Evaluate probability density/mass functions:** Compute `pdf`, `logpdf`, and related functions.
64-
* **Utilize moment-generating, quantile, and characteristic functions:** Access `mgf`, `quantile`, and `cf` for in-depth statistical analysis.
83+
* Open an issue to discuss bugs or ideas.
84+
* Use `@testitem`-based testsets (same as `Distributions.jl`).
85+
* Follow `Documenter.jl` docstring style and type annotations.
6586

66-
---
87+
Pull requests improving:
88+
89+
* distribution coverage,
90+
* algorithmic efficiency,
91+
* or documentation clarity are particularly encouraged.
6792

68-
## Future Directions
93+
---
6994

70-
In future releases, we plan to implement **maximum-likelihood estimators**, expand **multivariate coverage**, and introduce **optimized numerical backends** to support efficient use within `Copulas.jl` and other packages in the JuliaStats and SciML ecosystems.
95+
**Author:** Santiago Jiménez
96+
**License:** MIT
97+
**Repository:** [Santymax98/AdditionalDistributions.jl](https://github.com/Santymax98/AdditionalDistributions.jl)

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ makedocs(;
2525
"Bestiary" => [
2626
"Discrete Distributions"=>"bestiary/discrete.md",
2727
"Continuous Distribution"=>"bestiary/continuous.md",
28+
"Multivariate Distributions"=>"bestiary/multivariate.md",
2829
],
2930
],
3031
)

docs/src/bestiary/multivariate.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Extra Multivariate Distributions
2+
3+
The following multivariate distributions extend the behavior of `Distributions.jl` to include **numerically stable cumulative
4+
probability computations** using custom Quasi–Monte Carlo (QMC) integration routines.
5+
6+
---
7+
8+
```@docs
9+
MvGaussian
10+
```
11+
12+
**Notes**
13+
14+
* Equivalent to `Distributions.MvNormal`, but implements its own `cdf(a, b)` method based on a high–precision QMC integrator.
15+
* Compatible with reference datasets from [MvNormalCDF.jl](https://github.com/JuliaStats/MvNormalCDF.jl), adjusted for local reproducibility.
16+
* Fully compatible with `mean`, `cov`, `pdf`, `logpdf`, and `rand`.
17+
18+
**Example**
19+
20+
```julia
21+
μ = [0.0, 0.0]
22+
Σ = [1.0 0.5; 0.5 1.0]
23+
d = MvGaussian(μ, Σ)
24+
cdf(d, [-1.0, -1.0], [1.0, 1.0])
25+
```
26+
27+
```@docs
28+
MvTStudent
29+
```
30+
31+
**Notes**
32+
33+
* Equivalent to `Distributions.MvTDist`, but with a custom `cdf(a, b)` based on the same QMC integrator.
34+
* For ν → ∞, numerical results converge to those of `MvGaussian`.
35+
* Benchmarked against `pmvt` from *mvtnorm* (R, Genz & Bretz, 2002).
36+
37+
**Example**
38+
39+
```julia
40+
ν = 10
41+
Σ = [1.0 0.4; 0.4 1.0]
42+
d = MvTStudent(ν, Σ)
43+
cdf(d, [-1.0, -1.0], [1.0, 1.0])
44+
```
45+
46+
---
47+
48+
### Implementation Notes
49+
50+
Both types serve as lightweight wrappers around their `Distributions.jl` counterparts:
51+
52+
```julia
53+
struct MvGaussian{D<:Distributions.MvNormal}
54+
dist::D
55+
end
56+
57+
struct MvTStudent{D<:Distributions.MvTDist}
58+
dist::D
59+
end
60+
```
61+
62+
All statistical methods (`mean`, `cov`, `pdf`, etc.) are delegated to their internal distribution objects, ensuring full compatibility while
63+
adding numerical integration support for the cumulative distribution function.
64+
65+
```@docs
66+
AdditionalDistributions.mvtcdf
67+
```

0 commit comments

Comments
 (0)