Skip to content

Commit

Permalink
Merge 36b9a26 into 089025c
Browse files Browse the repository at this point in the history
  • Loading branch information
theogf committed Oct 27, 2020
2 parents 089025c + 36b9a26 commit c7f0a47
Show file tree
Hide file tree
Showing 32 changed files with 203 additions and 294 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -4,20 +4,20 @@ os:
- linux
- osx
julia:
- 1.2
- 1.4
- 1.3
- 1
- nightly
notifications:
email: false
after_success:
# push coverage results to Coveralls
- if [[ $TRAVIS_JULIA_VERSION = 1.4 ]] && [[ $TRAVIS_OS_NAME = linux ]]; then
- if [[ $TRAVIS_JULIA_VERSION = 1 ]] && [[ $TRAVIS_OS_NAME = linux ]]; then
julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())';
fi
jobs:
include:
- stage: "Documentation"
julia: 1.4
julia: 1
os: linux
script:
- export DOCUMENTER_DEBUG=true
Expand Down
10 changes: 5 additions & 5 deletions Project.toml
Expand Up @@ -9,6 +9,7 @@ Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DeterminantalPointProcesses = "4d968f93-c0cd-4b7f-b189-b034d1a24a0e"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Expand All @@ -25,7 +26,6 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
Expand All @@ -51,7 +51,7 @@ RecipesBase = "1.0, 1.1"
Reexport = "0.2"
SimpleTraits = "0.9"
SpecialFunctions = "0.9, 0.10"
StatsBase = "0.32.0, 0.33"
StatsFuns = "0.8.0, 0.9"
Zygote = "0.4, 0.5"
julia = "1.2"
StatsBase = "0.32, 0.33"
StatsFuns = "0.8, 0.9"
Zygote = "0.5"
julia = "1.3"
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -2,7 +2,7 @@

[![Docs Latest](https://img.shields.io/badge/docs-dev-blue.svg)](https://theogf.github.io/AugmentedGaussianProcesses.jl/dev)
[![Docs Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://theogf.github.io/AugmentedGaussianProcesses.jl/stable)
[![Build Status](https://travis-ci.org/theogf/AugmentedGaussianProcesses.jl.svg?branch=master)](https://travis-ci.org/theogf/AugmentedGaussianProcesses.jl)
[![Build Status](https://travis-ci.com/theogf/AugmentedGaussianProcesses.jl.svg?branch=master)](https://travis-ci.com/theogf/AugmentedGaussianProcesses.jl)
[![Coverage Status](https://coveralls.io/repos/github/theogf/AugmentedGaussianProcesses.jl/badge.svg?branch=master)](https://coveralls.io/github/theogf/AugmentedGaussianProcesses.jl?branch=master)
[![DOI](https://zenodo.org/badge/118922202.svg)](https://zenodo.org/badge/latestdoi/118922202)

Expand Down Expand Up @@ -59,7 +59,7 @@ AugmentedGaussianProcesses.jl is a Julia package in development for **Data Augme

## Install the package

The package requires at least [Julia 1.1](https://julialang.org/)
The package requires at least [Julia 1.3](https://julialang.org/)
Run `julia`, press `]` and type `add AugmentedGaussianProcesses`, it will install the package and all its dependencies.

## Use the package
Expand Down
8 changes: 4 additions & 4 deletions src/data/datacontainer.jl
Expand Up @@ -14,20 +14,20 @@ struct DataContainer{
TY<:AbstractVector,
} <: AbstractDataContainer
X::TX # Feature vectors
y::TY # Output (-1,1 for classification, real for regression, matrix for multiclass)
y::TY # Output (-1,1 for classification, real for regression, vector{vector} for multiclass)
nSamples::Int # Number of samples
nDim::Int # Number of features per sample
end

function wrap_data(X::TX, y::TY) where {TX, TY<:AbstractVector{<:Real}}
size(y, 1) == size(X, 1) || error("There is not the same number of samples in X ($(length(TX))) and y ($(size(y, 1)))")
length(y) == length(X) || error("There is not the same number of samples in X ($(length(X))) and y ($(length(y)))")
Tx = eltype(first(X))
Ty = eltype(first(y))
return DataContainer{Tx, TX, Ty, TY}(X, y, length(X), length(first(X)))
end

function wrap_data(X::TX, y::TY) where {TX, TY<:AbstractVector}
size(first(y), 1) == size(X, 1) || error("There is not the same number of samples in X ($(length(TX))) and y ($(size(y, 1)))")
all(length.(y) .== length(X)) || error("There is not the same number of samples in X ($(length(X))) and y ($(length.(y))))")
Tx = eltype(first(X))
Ty = eltype(first(y))
return DataContainer{Tx, TX, Ty, TY}(X, y, length(X), length(first(X)))
Expand All @@ -46,7 +46,7 @@ struct MODataContainer{
end

function wrap_modata(X::TX, y::TY) where {TX, TY<:AbstractVector}
all(size.(y, 1) .== size(X, 1)) || error("There is not the same number of samples in X ($(length(TX))) and y ($(size(y, 1)))")
all(length.(y) .== length(X)) || error("There is not the same number of samples in X ($(length(X))) and y ($(length.(y))))")
Tx = eltype(first(X))
return MODataContainer{Tx, TX, TY}(X, y, length(X), length(first(X)), length(y))
end
Expand Down
2 changes: 2 additions & 0 deletions src/data/utils.jl
Expand Up @@ -2,6 +2,8 @@ view_x(d::AbstractDataContainer, indices) = view(d.X, indices)
view_y(l::Likelihood, y::AbstractVector, i::AbstractVector) = view(y, i)
view_y(l::Likelihood, d::AbstractDataContainer, i::AbstractVector) = view_y(l, output(d), i)
view_y(l::Likelihood, d::MODataContainer, i::AbstractVector) = view_y.(l, output(d), Ref(i))
view_y(l::AbstractVector{<:Likelihood}, d::MODataContainer, i::AbstractVector) = view_y.(l, output(d), Ref(i))


# Verify that the data is self-consistent and consistent with the likelihood ##
function check_data!(
Expand Down
178 changes: 0 additions & 178 deletions src/examples/gpregression.md/GP Regression.md

This file was deleted.

26 changes: 16 additions & 10 deletions src/functions/KLdivergences.jl
@@ -1,5 +1,7 @@
"""Compute the KL Divergence between the GP Prior and the variational distribution"""
GaussianKL(model::AbstractGP) = sum(broadcast(GaussianKL, model.f, Zviews(model)))
"""
KL Divergence between the GP Prior and the variational distribution
"""
GaussianKL(model::AbstractGP) = mapreduce(GaussianKL, +, model.f, Zviews(model))

GaussianKL(gp::AbstractLatent, X::AbstractVector) = GaussianKL(mean(gp), pr_mean(gp, X), cov(gp), pr_cov(gp))

Expand All @@ -13,15 +15,17 @@ function GaussianKL(
0.5 * (logdet(K) - logdet(Σ) + tr(K \ Σ) + invquad(K, μ - μ₀) - length(μ))
end

extraKL(model::AbstractGP{T}) where {T} = zero(T)
extraKL(::AbstractGP{T}) where {T} = zero(T)

"""Return the extra KL term containing the divergence with the GP at time t and t+1"""
"""
Extra KL term containing the divergence with the GP at time t and t+1
"""
function extraKL(model::OnlineSVGP{T}) where {T}
KLₐ = zero(T)
for gp in model.f
κₐμ = gp.κₐ * mean(gp)
KLₐ += gp.prev𝓛ₐ
KLₐ += -0.5 * sum(opt_trace.([gp.invDₐ], [gp.K̃ₐ, gp.κₐ * cov(gp) * transpose(gp.κₐ)]))
KLₐ += -0.5 * sum(opt_trace.(Ref(gp.invDₐ), [gp.K̃ₐ, gp.κₐ * cov(gp) * transpose(gp.κₐ)]))
KLₐ += dot(gp.prevη₁, κₐμ) - 0.5 * dot(κₐμ, gp.invDₐ * κₐμ)
end
return KLₐ
Expand Down Expand Up @@ -57,7 +61,9 @@ function PoissonKL(
end


"""KL(q(ω)||p(ω)), where q(ω) = PG(b,c) and p(ω) = PG(b,0). θ = 𝑬[ω]"""
"""
KL(q(ω)||p(ω)), where q(ω) = PG(b,c) and p(ω) = PG(b,0). θ = 𝑬[ω]
"""
function PolyaGammaKL(b, c, θ)
dot(b, logcosh.(0.5 * c)) - 0.5 * dot(abs2.(c), θ)
end
Expand All @@ -67,11 +73,11 @@ end
Entropy of GIG variables with parameters a,b and p and omitting the derivative d/dpK_p cf <https://en.wikipedia.org/wiki/Generalized_inverse_Gaussian_distribution#Entropy>
"""
function GIGEntropy(a, b, p)
sqrtab = sqrt.(a .* b)
sqrt_ab = sqrt.(a .* b)
return sum(0.5 * log.(a ./ b)) +
sum(log.(2 * besselk.(p, sqrtab))) +
sum(log.(2 * besselk.(p, sqrt_ab))) +
sum(
0.5 * sqrtab ./ besselk.(p, sqrtab) .*
(besselk.(p + 1, sqrtab) + besselk.(p - 1, sqrtab)),
0.5 * sqrt_ab ./ besselk.(p, sqrt_ab) .*
(besselk.(p + 1, sqrt_ab) + besselk.(p - 1, sqrt_ab)),
)
end

0 comments on commit c7f0a47

Please sign in to comment.