Skip to content

Commit

Permalink
Allow AbstractGPs in WrappedGP (#217)
Browse files Browse the repository at this point in the history
* Bump patch

* Allow AbstractGP in WrappedGP

* Test nested GPPP

* Check WrappedGP with fresh AbstractGP

* Remove redundant code

* Remove redudant code
  • Loading branch information
willtebbutt authored Dec 26, 2021
1 parent 576df0b commit c822896
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 540 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Stheno"
uuid = "8188c328-b5d6-583d-959b-9690869a5511"
version = "0.7.15"
version = "0.7.16"

[deps]
AbstractGPs = "99985d1d-32ba-4be9-9821-2ec096f28918"
Expand Down
1 change: 0 additions & 1 deletion src/Stheno.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module Stheno
include(joinpath("util", "zygote_rules.jl"))
include(joinpath("util", "covariance_matrices.jl"))
include(joinpath("util", "block_arrays", "dense.jl"))
include(joinpath("util", "block_arrays", "diagonal.jl"))
include(joinpath("util", "abstract_data_set.jl"))
include(joinpath("util", "proper_type_piracy.jl"))

Expand Down
4 changes: 2 additions & 2 deletions src/gp/gp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ struct WrappedGP{Tgp<:AbstractGP} <: SthenoAbstractGP
gp::Tgp
n::Int
gpc::GPC
function WrappedGP{Tgp}(gp::Tgp, gpc::GPC) where {Tgp<:GP}
function WrappedGP{Tgp}(gp::Tgp, gpc::GPC) where {Tgp<:AbstractGP}
wgp = new{Tgp}(gp, next_index(gpc), gpc)
gpc.n += 1
return wgp
end
end

wrap(gp::Tgp, gpc::GPC) where {Tgp<:GP} = WrappedGP{Tgp}(gp, gpc)
wrap(gp::Tgp, gpc::GPC) where {Tgp<:AbstractGP} = WrappedGP{Tgp}(gp, gpc)

mean(f::WrappedGP, x::AbstractVector) = mean(f.gp, x)

Expand Down
231 changes: 0 additions & 231 deletions src/util/block_arrays/diagonal.jl

This file was deleted.

19 changes: 17 additions & 2 deletions test/gaussian_process_probabilistic_programme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
GPPPInput(:f1, randn(4)),
),
]
rng = MersenneTwister(123456)
AbstractGPs.TestUtils.test_internal_abstractgps_interface(rng, f, x0, x1)
test_internal_abstractgps_interface(MersenneTwister(123456), f, x0, x1)
end

@timedtestset "gppp macro" begin
Expand All @@ -103,4 +102,20 @@
y = rand(f(x, s))
Zygote.gradient((x, y, f, s) -> logpdf(f(x, s), y), x, y, f, s)
end

# Check that we can use one GPPP inside another.
@timedtestset "nested gppp" begin

gpc_outer = GPC()
f1_outer = Stheno.wrap(f, gpc_outer)
f2_outer = 5 * f1_outer
f_outer = Stheno.GPPP((f1=f1_outer, f2=f2_outer), gpc_outer)

x0 = GPPPInput(:f1, randn(5))
x1 = GPPPInput(:f2, randn(4))
x0_outer = GPPPInput(:f1, x0)
x1_outer = GPPPInput(:f2, x1)
rng = MersenneTwister(123456)
test_internal_abstractgps_interface(rng, f_outer, x0_outer, x1_outer)
end
end
6 changes: 6 additions & 0 deletions test/gp/gp.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
struct ToyAbstractGP <: AbstractGP end

@timedtestset "gp" begin

# Ensure that basic functionality works as expected.
Expand Down Expand Up @@ -33,4 +35,8 @@

@test cov(f1, f1, x′, x) cov(f1, f1, x, x′)'
end

@timedtestset "wrapped AbstractGP" begin
wrap(ToyAbstractGP(), GPC())
end
end
5 changes: 1 addition & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ using Stheno:
GPC,
AV,
FiniteGP,
block_diagonal,
AbstractGP,
BlockData,
blocks,
Expand All @@ -36,10 +35,9 @@ using Stheno:
diag_At_B,
diag_Xt_invA_X,
diag_Xt_invA_Y,
block_diagonal,
BlockDiagonal,
blocksizes

using Stheno.AbstractGPs.TestUtils: test_internal_abstractgps_interface
using Stheno.AbstractGPs.Distributions: MvNormal
using FiniteDifferences: j′vp

Expand All @@ -60,7 +58,6 @@ include("test_util.jl")
@testset "block_arrays" begin
include(joinpath("util", "block_arrays", "test_util.jl"))
include(joinpath("util", "block_arrays", "dense.jl"))
include(joinpath("util", "block_arrays", "diagonal.jl"))
end
include(joinpath("util", "abstract_data_set.jl"))
end
Expand Down
Loading

12 comments on commit c822896

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/51248

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.16 -m "<description of version>" c822896a9a5633e61275ff152bda84fb41619ad7
git push origin v0.7.16

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/51248

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.16 -m "<description of version>" c822896a9a5633e61275ff152bda84fb41619ad7
git push origin v0.7.16

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/51248

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.16 -m "<description of version>" c822896a9a5633e61275ff152bda84fb41619ad7
git push origin v0.7.16

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/51248

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.16 -m "<description of version>" c822896a9a5633e61275ff152bda84fb41619ad7
git push origin v0.7.16

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/51248

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.16 -m "<description of version>" c822896a9a5633e61275ff152bda84fb41619ad7
git push origin v0.7.16

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/51248

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.16 -m "<description of version>" c822896a9a5633e61275ff152bda84fb41619ad7
git push origin v0.7.16

Please sign in to comment.