From c111addb6c882170f5c90f8788706076ecd9fcc6 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Sun, 10 Mar 2024 00:38:53 +0100 Subject: [PATCH 1/7] Replace `Product` (deprecated) by `product_distribution` --- docs/src/index.md | 2 +- src/likelihoods/bernoulli.jl | 2 +- src/likelihoods/categorical.jl | 2 +- src/likelihoods/exponential.jl | 2 +- src/likelihoods/gamma.jl | 2 +- src/likelihoods/negativebinomial.jl | 2 +- src/likelihoods/poisson.jl | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 0c9c4c26..ead0f259 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -36,7 +36,7 @@ if you need to transform an `AbstractMatrix`). fs = [2.0, 3.0, 4.5]; CategoricalLikelihood()(fs) isa Categorical Fs = [rand(3) for _ in 1:4]; -CategoricalLikelihood()(Fs) isa Product{<:Any,<:Categorical} +CategoricalLikelihood()(Fs) isa product_distribution{<:Any,<:Categorical} ``` ### Constrained parameters diff --git a/src/likelihoods/bernoulli.jl b/src/likelihoods/bernoulli.jl index d14878eb..e8bc08be 100644 --- a/src/likelihoods/bernoulli.jl +++ b/src/likelihoods/bernoulli.jl @@ -18,4 +18,4 @@ BernoulliLikelihood(l=logistic) = BernoulliLikelihood(link(l)) (l::BernoulliLikelihood)(f::Real) = Bernoulli(l.invlink(f)) -(l::BernoulliLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs)) +(l::BernoulliLikelihood)(fs::AbstractVector{<:Real}) = product_distribution(map(l, fs)) diff --git a/src/likelihoods/categorical.jl b/src/likelihoods/categorical.jl index 6caedbf5..235310c1 100644 --- a/src/likelihoods/categorical.jl +++ b/src/likelihoods/categorical.jl @@ -36,4 +36,4 @@ function (l::CategoricalLikelihood)(f::AbstractVector{<:Real}) return Categorical(l.invlink(f)) end -(l::CategoricalLikelihood)(fs::AbstractVector) = Product(map(l, fs)) +(l::CategoricalLikelihood)(fs::AbstractVector) = product_distribution(map(l, fs)) diff --git a/src/likelihoods/exponential.jl b/src/likelihoods/exponential.jl index 1b7dc603..9ab648e5 100644 --- a/src/likelihoods/exponential.jl +++ b/src/likelihoods/exponential.jl @@ -15,7 +15,7 @@ ExponentialLikelihood(l=exp) = ExponentialLikelihood(link(l)) (l::ExponentialLikelihood)(f::Real) = Exponential(l.invlink(f)) -(l::ExponentialLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs)) +(l::ExponentialLikelihood)(fs::AbstractVector{<:Real}) = product_distribution(map(l, fs)) function expected_loglikelihood( ::AnalyticExpectation, diff --git a/src/likelihoods/gamma.jl b/src/likelihoods/gamma.jl index dcd0202f..61bd4cb8 100644 --- a/src/likelihoods/gamma.jl +++ b/src/likelihoods/gamma.jl @@ -20,7 +20,7 @@ GammaLikelihood(α::Real=1.0, l=exp) = GammaLikelihood(α, link(l)) (l::GammaLikelihood)(f::Real) = Gamma(l.α, l.invlink(f)) -(l::GammaLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs)) +(l::GammaLikelihood)(fs::AbstractVector{<:Real}) = product_distribution(map(l, fs)) function expected_loglikelihood( ::AnalyticExpectation, diff --git a/src/likelihoods/negativebinomial.jl b/src/likelihoods/negativebinomial.jl index d8f78a25..318887f8 100644 --- a/src/likelihoods/negativebinomial.jl +++ b/src/likelihoods/negativebinomial.jl @@ -79,7 +79,7 @@ end @functor NegativeBinomialLikelihood -(l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs)) +(l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real}) = product_distribution(map(l, fs)) @doc raw""" NBParamSuccess(successes) diff --git a/src/likelihoods/poisson.jl b/src/likelihoods/poisson.jl index 9e31d6e2..300f120f 100644 --- a/src/likelihoods/poisson.jl +++ b/src/likelihoods/poisson.jl @@ -18,7 +18,7 @@ PoissonLikelihood(l=exp) = PoissonLikelihood(link(l)) (l::PoissonLikelihood)(f::Real) = Poisson(l.invlink(f)) -(l::PoissonLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs)) +(l::PoissonLikelihood)(fs::AbstractVector{<:Real}) = product_distribution(map(l, fs)) function expected_loglikelihood( ::AnalyticExpectation, From 82d46887154d59d6709d409afdb8fd40f35a6344 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Sun, 10 Mar 2024 00:45:27 +0100 Subject: [PATCH 2/7] Add Aqua tests --- README.md | 1 + test/Project.toml | 2 ++ test/runtests.jl | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d0e86a32..d97b9c9e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Codecov](https://codecov.io/gh/JuliaGaussianProcesses/GPLikelihoods.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaGaussianProcesses/GPLikelihoods.jl) [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) +[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) GPLikelihoods.jl provides a collection of likelihoods to be used as building blocks for defining non-Gaussian problems. It is intended to be mainly diff --git a/test/Project.toml b/test/Project.toml index 6e2c7758..feeb76eb 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" @@ -7,6 +8,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] +Aqua = "0.8" Distributions = "0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25" Functors = "0.1, 0.2, 0.3, 0.4" StatsFuns = "0.9, 1" diff --git a/test/runtests.jl b/test/runtests.jl index 1552a999..5b25cbaf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,11 +1,13 @@ using GPLikelihoods using GPLikelihoods: GaussHermiteExpectation, MonteCarloExpectation using GPLikelihoods.TestInterface: test_interface -using Test -using Random -using Functors + +using Aqua using Distributions +using Functors +using Random using StatsFuns +using Test using Zygote @testset "GPLikelihoods.jl" begin @@ -20,4 +22,8 @@ using Zygote include("likelihoods/negativebinomial.jl") end include("expectations.jl") + @testset "Code quality (Aqua.jl)" begin + Aqua.test_all(GPLikelihoods; ambiguities = false) + Aqua.test_ambiguities([GPLikelihoods, Base, Core]; recursive=false) + end end From 3b73b94a45d5c5ba7d7b14f27450a1bdfa2b215c Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Sun, 10 Mar 2024 00:45:37 +0100 Subject: [PATCH 3/7] Bump version --- Project.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 91847a90..cf58d2ca 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GPLikelihoods" uuid = "6031954c-0455-49d7-b3b9-3e1c99afaf40" authors = ["JuliaGaussianProcesses Team"] -version = "0.4.6" +version = "0.4.7" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" @@ -23,6 +23,9 @@ FastGaussQuadrature = "0.4, 0.5" Functors = "0.1, 0.2, 0.3, 0.4" InverseFunctions = "0.1.2" IrrationalConstants = "0.1, 0.2" +LinearAlgebra = "1" +Random = "1" SpecialFunctions = "1, 2" StatsFuns = "0.9.13, 1" +Test = "1" julia = "1.6" From 2bde5fa031db039e0459763aced9bb2ae20455d4 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace <51025924+simsurace@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:06:14 +0100 Subject: [PATCH 4/7] Update runtests.jl Co-authored-by: David Widmann --- test/runtests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 5b25cbaf..8bbc5cdd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,6 +24,7 @@ using Zygote include("expectations.jl") @testset "Code quality (Aqua.jl)" begin Aqua.test_all(GPLikelihoods; ambiguities = false) - Aqua.test_ambiguities([GPLikelihoods, Base, Core]; recursive=false) + # Ref https://github.com/JuliaTesting/Aqua.jl/issues/77 + Aqua.test_ambiguities(GPLikelihoods; recursive=false) end end From 53c4ddb86718a973260ec785ef264a2569cfe53d Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace <51025924+simsurace@users.noreply.github.com> Date: Sun, 10 Mar 2024 20:52:46 +0100 Subject: [PATCH 5/7] Apply format suggestions Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/likelihoods/negativebinomial.jl | 4 +++- test/runtests.jl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/likelihoods/negativebinomial.jl b/src/likelihoods/negativebinomial.jl index 318887f8..03c42d8f 100644 --- a/src/likelihoods/negativebinomial.jl +++ b/src/likelihoods/negativebinomial.jl @@ -79,7 +79,9 @@ end @functor NegativeBinomialLikelihood -(l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real}) = product_distribution(map(l, fs)) +function (l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real}) + return product_distribution(map(l, fs)) +end @doc raw""" NBParamSuccess(successes) diff --git a/test/runtests.jl b/test/runtests.jl index 8bbc5cdd..05528afd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,7 +23,7 @@ using Zygote end include("expectations.jl") @testset "Code quality (Aqua.jl)" begin - Aqua.test_all(GPLikelihoods; ambiguities = false) + Aqua.test_all(GPLikelihoods; ambiguities=false) # Ref https://github.com/JuliaTesting/Aqua.jl/issues/77 Aqua.test_ambiguities(GPLikelihoods; recursive=false) end From 39e56d7c6520f63afb869f58cf76dcb7098df4e4 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Sun, 10 Mar 2024 22:19:53 +0100 Subject: [PATCH 6/7] Fix typo --- docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/index.md b/docs/src/index.md index ead0f259..0c9c4c26 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -36,7 +36,7 @@ if you need to transform an `AbstractMatrix`). fs = [2.0, 3.0, 4.5]; CategoricalLikelihood()(fs) isa Categorical Fs = [rand(3) for _ in 1:4]; -CategoricalLikelihood()(Fs) isa product_distribution{<:Any,<:Categorical} +CategoricalLikelihood()(Fs) isa Product{<:Any,<:Categorical} ``` ### Constrained parameters From 7ec0d3629ff3ed8f206dfc24b484bb0a5c363891 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Sun, 10 Mar 2024 22:24:27 +0100 Subject: [PATCH 7/7] Remove type piracy --- src/expectations.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/expectations.jl b/src/expectations.jl index 85db8c3d..33545487 100644 --- a/src/expectations.jl +++ b/src/expectations.jl @@ -1,8 +1,10 @@ -using FastGaussQuadrature: gausshermite +using FastGaussQuadrature: FastGaussQuadrature using SpecialFunctions: loggamma using ChainRulesCore: ChainRulesCore using IrrationalConstants: sqrt2, invsqrtπ +gausshermite(n::Integer) = FastGaussQuadrature.gausshermite(n) + struct DefaultExpectationMethod end struct AnalyticExpectation end