Skip to content

Commit 6818fe4

Browse files
authored
Stop doing sparse stuff in this package (#213)
* Bump minor version * Fix comment * Allow [email protected] * Remove elbo from core of package * Remove elbo-related tests * Update NEWS.md * Only bump patch * Update implementation for SparseGP object * Remove [email protected] from compat
1 parent 577fce7 commit 6818fe4

File tree

10 files changed

+24
-168
lines changed

10 files changed

+24
-168
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ between versions, and discuss new features.
66
If you find a breaking change this is not reported here, please either raise an issue or
77
make a PR to ammend this document.
88

9+
## 0.7.14
10+
11+
AbstractGPs now takes care of everything sparsity-related.
12+
Consequently, Stheno no longer tests anything ELBO-related, and the functionality you get
13+
will depend entirely upon which version of AbstractGPs you're using.
14+
915
## 0.7.0
1016

1117
### Breaking changes

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Stheno"
22
uuid = "8188c328-b5d6-583d-959b-9690869a5511"
3-
version = "0.7.13"
3+
version = "0.7.14"
44

55
[deps]
66
AbstractGPs = "99985d1d-32ba-4be9-9821-2ec096f28918"
@@ -17,7 +17,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
1717
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"
1818

1919
[compat]
20-
AbstractGPs = "0.3.9"
20+
AbstractGPs = "0.4"
2121
BlockArrays = "0.15, 0.16"
2222
ChainRulesCore = "1"
2323
FillArrays = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12"

src/Stheno.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ module Stheno
6565
include("deprecate.jl")
6666

6767
export wrap, BlockData, GPC, GPPPInput, @gppp
68-
export elbo, dtc
6968
export , select, stretch, periodic, shift
7069
export cov_diag, mean_and_cov_diag
7170
end # module

src/composite/cross.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ end
6161

6262

6363
#
64-
# Util for multi-process versions of `rand`, `logpdf`, and `elbo`.
64+
# Build a single FiniteGP from a collection of FiniteGPs.
6565
#
6666

6767
function finites_to_block(fs::AV{<:FiniteGP})

src/gaussian_process_probabilistic_programme.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,15 @@ f = @gppp let
177177
f3 = f1 + f2
178178
end
179179
180-
x = GPPPInput(:f3, randn(5))
180+
x_local = randn(5)
181181
182-
y = rand(f(x, 0.1))
182+
x = BlockData(GPPPInput(:f1, x_local), GPPPInput(:f2, x_local), GPPPInput(:f3, x_local))
183183
184-
logpdf(f(x, 0.1), y) ≈ elbo(f(x, 0.1), y, f(x, 1e-9))
184+
y = rand(f(x, 1e-12))
185+
186+
f1, f2, f3 = split(x, y)
187+
188+
isapprox(f1 + f2, f3; rtol=1e-4)
185189
186190
# output
187191

src/sparse_finite_gp.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ rand(f::SparseFiniteGP, N::Int) = rand(Random.GLOBAL_RNG, f, N)
5555
rand(rng::AbstractRNG, f::SparseFiniteGP) = vec(rand(rng, f, 1))
5656
rand(f::SparseFiniteGP) = vec(rand(f, 1))
5757

58-
elbo(f::SparseFiniteGP, y::AV{<:Real}) = elbo(f.fobs, y, f.finducing)
58+
elbo(f::SparseFiniteGP, y::AV{<:Real}) = elbo(VFE(f.finducing), f.fobs, y)
5959

60-
logpdf(f::SparseFiniteGP, y::AV{<:Real}) = elbo(f.fobs, y, f.finducing)
60+
logpdf(f::SparseFiniteGP, y::AV{<:Real}) = elbo(VFE(f.finducing), f.fobs, y)
6161

6262
function logpdf(f::SparseFiniteGP, Y::AbstractMatrix{<:Real})
6363
return map(y -> logpdf(f, y), eachcol(Y))
6464
end
6565

6666
function posterior(f::SparseFiniteGP, y::AbstractVector{<:Real})
67-
return approx_posterior(AbstractGPs.VFE(), f.fobs, y, f.finducing)
67+
return posterior(AbstractGPs.VFE(f.finducing), f.fobs, y)
6868
end

test/abstract_gp.jl

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -73,85 +73,6 @@ end
7373
atol=1e-9, rtol=1e-9,
7474
)
7575
end
76-
@testset "logpdf / elbo / dtc" begin
77-
rng, N, S, σ, gpc = MersenneTwister(123456), 10, 11, 1e-1, GPC()
78-
x = collect(range(-3.0, stop=3.0, length=N))
79-
f = wrap(GP(1, SEKernel()), gpc)
80-
fx, y = FiniteGP(f, x, 0), FiniteGP(f, x, σ^2)
81-
= rand(rng, y)
82-
83-
# Check that logpdf returns the correct type and roughly agrees with Distributions.
84-
@test logpdf(y, ŷ) isa Real
85-
@test logpdf(y, ŷ) logpdf(MvNormal(Vector(mean(y)), cov(y)), ŷ)
86-
87-
# Check that multi-sample logpdf returns the correct type and is consistent with
88-
# single-sample logpdf
89-
= rand(rng, y, S)
90-
@test logpdf(y, Ŷ) isa Vector{Float64}
91-
@test logpdf(y, Ŷ) [logpdf(y, Ŷ[:, n]) for n in 1:S]
92-
93-
# Check gradient of logpdf at mean is zero for `f`.
94-
adjoint_test(ŷ->logpdf(fx, ŷ), 1, ones(size(ŷ)))
95-
lp, back = Zygote.pullback(ŷ->logpdf(fx, ŷ), ones(size(ŷ)))
96-
@test back(randn(rng))[1] == zeros(size(ŷ))
97-
98-
# Check that gradient of logpdf at mean is zero for `y`.
99-
adjoint_test(ŷ->logpdf(y, ŷ), 1, ones(size(ŷ)))
100-
lp, back = Zygote.pullback(ŷ->logpdf(y, ŷ), ones(size(ŷ)))
101-
@test back(randn(rng))[1] == zeros(size(ŷ))
102-
103-
# Check that gradient w.r.t. inputs is approximately correct for `f`.
104-
x, l̄ = randn(rng, N), randn(rng)
105-
adjoint_test(
106-
x->logpdf(FiniteGP(f, x, 1e-3), ones(size(x))),
107-
l̄, collect(x);
108-
atol=1e-8, rtol=1e-8,
109-
)
110-
adjoint_test(
111-
x->sum(logpdf(FiniteGP(f, x, 1e-3), ones(size(Ŷ)))),
112-
l̄, collect(x);
113-
atol=1e-8, rtol=1e-8,
114-
)
115-
116-
# Check that the gradient w.r.t. the noise is approximately correct for `f`.
117-
σ_ = randn(rng)
118-
adjoint_test((σ_, ŷ)->logpdf(FiniteGP(f, x, exp(σ_)), ŷ), l̄, σ_, ŷ)
119-
adjoint_test((σ_, Ŷ)->sum(logpdf(FiniteGP(f, x, exp(σ_)), Ŷ)), l̄, σ_, Ŷ)
120-
121-
# Check that the gradient w.r.t. a scaling of the GP works.
122-
adjoint_test(
123-
α->logpdf(FiniteGP* f, x, 1e-1), ŷ), l̄, randn(rng);
124-
atol=1e-8, rtol=1e-8,
125-
)
126-
adjoint_test(
127-
α->sum(logpdf(FiniteGP* f, x, 1e-1), Ŷ)), l̄, randn(rng);
128-
atol=1e-8, rtol=1e-8,
129-
)
130-
131-
# Ensure that the elbo is close to the logpdf when appropriate.
132-
@test elbo(y, ŷ, fx) isa Real
133-
@test elbo(y, ŷ, fx) logpdf(y, ŷ)
134-
@test elbo(y, ŷ, y) < logpdf(y, ŷ)
135-
@test elbo(y, ŷ, FiniteGP(f, x, 2 * σ^2)) < elbo(y, ŷ, y)
136-
137-
# Check adjoint w.r.t. elbo is correct.
138-
adjoint_test(
139-
(x, ŷ, σ)->elbo(FiniteGP(f, x, σ^2), ŷ, FiniteGP(f, x, 0)),
140-
randn(rng), x, ŷ, σ;
141-
atol=1e-6, rtol=1e-6,
142-
)
143-
144-
# Ensure that the dtc is close to the logpdf when appropriate.
145-
@test dtc(y, ŷ, fx) isa Real
146-
@test dtc(y, ŷ, fx) logpdf(y, ŷ)
147-
148-
# Check adjoint w.r.t. dtc is correct.
149-
adjoint_test(
150-
(x, ŷ, σ)->dtc(FiniteGP(f, x, σ^2), ŷ, FiniteGP(f, x, 0)),
151-
randn(rng), x, ŷ, σ;
152-
atol=1e-6, rtol=1e-6,
153-
)
154-
end
15576
@testset "Type Stability - $T" for T in [Float64, Float32]
15677
rng = MersenneTwister(123456)
15778
x = randn(rng, T, 123)
@@ -164,6 +85,5 @@ end
16485
y = rand(rng, fx)
16586
@test y isa Vector{T}
16687
@test logpdf(fx, y) isa T
167-
@test elbo(fx, y, u) isa T
16888
end
16989
end

test/composite/addition.jl

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -89,56 +89,3 @@
8989
)
9090
end
9191
end
92-
93-
# # θ = Dict(:l1=>0.5, :l2=>2.3);
94-
# x, z = collect(range(-5.0, 5.0; length=512)), collect(range(-5.0, 5.0; length=128));
95-
# y = rand(GP(sin, SqExponentialKernel(), GPC())(x, 0.1));
96-
97-
# foo_logpdf = (x, y) -> begin
98-
# gpc = GPC()
99-
# f = GP(sin, SqExponentialKernel(), gpc)
100-
# return logpdf(f(x, 0.1), y)
101-
# end
102-
103-
# foo_elbo = (x, y, z) -> begin
104-
# f = GP(0, SqExponentialKernel(), GPC())
105-
# return elbo(f(x, 0.1), y, f(z, 0.001))
106-
# end
107-
108-
# @benchmark foo_logpdf($x, $y)
109-
# @benchmark Zygote.pullback(foo_logpdf, $x, $y)
110-
111-
# let
112-
# z, back = Zygote.pullback(foo_logpdf, x, y)
113-
# @benchmark $back($(randn()))
114-
# end
115-
116-
# let
117-
# foo = function(x, y)
118-
# fx = GP(0, SqExponentialKernel(), GPC())(x, 0.1)
119-
# C = cholesky(Symmetric(cov(fx)))
120-
# return logdet(C) + Xt_invA_X(C, y)
121-
# end
122-
# display(@benchmark Zygote.pullback($foo, $x, $y))
123-
# z_pw, back_pw = Zygote.pullback(foo, x, y)
124-
# @benchmark $back_pw(randn())
125-
# end
126-
127-
128-
# @benchmark foo_elbo($x, $y, $z)
129-
# @benchmark Zygote.pullback(foo_elbo, $x, $y, $z)
130-
131-
# let
132-
# L, back = Zygote.pullback(foo_elbo, x, y, z)
133-
# @benchmark $back($L)
134-
# end
135-
136-
137-
# θ->begin
138-
# gpc = GPC()
139-
# f1 = GP(sin, SqExponentialKernel(l=θ[:l1]), gpc)
140-
# f2 = GP(cos, SqExponentialKernel(l=θ[:l2]), gpc)
141-
# f3 = f1 + f2
142-
# return f3, f3
143-
# end,
144-
# 13, 11,

test/composite/test_util.jl

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Some basic consistency checks for the function `f(θ)::Tuple{GP, GP}`. Mainly just checks
55
that Zygote works properly for `f`, and correctly derives the gradients w.r.t. `θ` for
6-
`rand`, `logpdf`, `elbo` when considering the f.d.d.s `f(x, Σ)` and observations `y`, where
6+
`rand`, `logpdf`, when considering the f.d.d.s `f(x, Σ)` and observations `y`, where
77
`Σ = _to_psd(A)`. The first output of `f` will be the GP sampled from and whose `logpdf`
88
will be computed, while the second will be used as the process for the pseudo-points, whose
99
inputs are `z`.
@@ -46,7 +46,7 @@ function check_consistency(rng::AbstractRNG, θ, f, x::AV, y::AV, A, z::AV, B)
4646

4747

4848
# #
49-
# # rand / logpdf / elbo tests
49+
# # rand / logpdf tests
5050
# #
5151

5252
# # Check that the gradient w.r.t. the samples is correct (single-sample).
@@ -69,19 +69,8 @@ function check_consistency(rng::AbstractRNG, θ, f, x::AV, y::AV, A, z::AV, B)
6969
# rtol=1e-4, atol=1e-4,
7070
# )
7171

72-
# # Check adjoint for elbo.
73-
# adjoint_test(
74-
# (ϴ, x, A, y, z, B)->begin
75-
# fx, uz = h(θ, x, A, z, B)
76-
# return elbo(fx, y, uz)
77-
# end,
78-
# randn(rng), θ, x, A, y, z, B;
79-
# rtol=1e-4, atol=1e-4,
80-
# )
81-
82-
8372
# #
84-
# # multi-process rand / logpdf / elbo tests - this stuff won't work for anything if
73+
# # multi-process rand / logpdf tests - this stuff won't work for anything if
8574
# # cross-related functionality doesn't work properly
8675
# #
8776

@@ -120,15 +109,6 @@ function check_consistency(rng::AbstractRNG, θ, f, x::AV, y::AV, A, z::AV, B)
120109
# randn(rng), θ, x, A, y;
121110
# rtol=1e-4, atol=1e-4,
122111
# )
123-
124-
# adjoint_test(
125-
# (ϴ, x, A, y, z, B)->begin
126-
# fx, uz = h(θ, x, A, z, B)
127-
# return elbo([fx, fx], [y, y], [uz, uz])
128-
# end,
129-
# randn(rng), θ, x, A, y, z, B;
130-
# rtol=1e-4, atol=1e-4,
131-
# )
132112
end
133113

134114
function standard_1D_dense_test(rng::AbstractRNG, θ, f, x::AV, z::AV)

test/sparse_finite_gp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
fxu = SparseFiniteGP(f(x, σ), f(xu, σu))
3131
y = rand(MersenneTwister(12345), fxu)
3232

33-
fpost1 = approx_posterior(VFE(), fxu.fobs, y, fxu.finducing)
33+
fpost1 = posterior(VFE(fxu.finducing), fxu.fobs, y)
3434
fpost2 = posterior(fxu, y)
3535

3636
@test marginals(fpost1(x)) == marginals(fpost2(x))
3737
@test elbo(fxu, y) == logpdf(fxu, y)
38-
@test logpdf(fxu, y) == elbo(fxu.fobs, y, fxu.finducing)
38+
@test logpdf(fxu, y) == elbo(VFE(fxu.finducing),fxu.fobs, y)
3939
yy = rand(fxu, 10)
4040
@test all(logpdf(fx, yy) .> logpdf(fxu, yy))
4141
end

0 commit comments

Comments
 (0)