Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Aqua tests and clean up #103

Merged
merged 7 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/expectations.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion src/likelihoods/categorical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion src/likelihoods/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/likelihoods/negativebinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ end

@functor NegativeBinomialLikelihood

(l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real}) = Product(map(l, fs))
function (l::NegativeBinomialLikelihood)(fs::AbstractVector{<:Real})
return product_distribution(map(l, fs))
end

@doc raw"""
NBParamSuccess(successes)
Expand Down
2 changes: 1 addition & 1 deletion src/likelihoods/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
13 changes: 10 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,4 +22,9 @@ using Zygote
include("likelihoods/negativebinomial.jl")
end
include("expectations.jl")
@testset "Code quality (Aqua.jl)" begin
Aqua.test_all(GPLikelihoods; ambiguities=false)
# Ref https://github.com/JuliaTesting/Aqua.jl/issues/77
Aqua.test_ambiguities(GPLikelihoods; recursive=false)
end
end
Loading