Skip to content

Commit 956b581

Browse files
author
Will Tebbutt
committed
Test all rationalquadratickernel methods
1 parent f009284 commit 956b581

File tree

1 file changed

+117
-103
lines changed

1 file changed

+117
-103
lines changed

test/basekernels/rational.jl

Lines changed: 117 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44
v1 = rand(rng, 3)
55
v2 = rand(rng, 3)
66

7-
@testset "RationalKernel" begin
8-
α = rand()
9-
k = RationalKernel(; α=α)
10-
11-
@testset "RationalKernel ≈ Exponential for large α" begin
12-
@test isapprox(
13-
RationalKernel(; α=1e9)(v1, v2),
14-
ExponentialKernel()(v1, v2);
15-
atol=1e-6,
16-
rtol=1e-6,
17-
)
18-
end
19-
20-
@test metric(RationalKernel()) == Euclidean()
21-
@test metric(RationalKernel(; α=α)) == Euclidean()
22-
@test repr(k) == "Rational Kernel (α = $(α), metric = Euclidean(0.0))"
23-
24-
k2 = RationalKernel(; α=α, metric=WeightedEuclidean(ones(3)))
25-
@test metric(k2) isa WeightedEuclidean
26-
@test k2(v1, v2) k(v1, v2)
27-
28-
# Standardised tests.
29-
TestUtils.test_interface(k, Float64)
30-
test_ADs(x -> RationalKernel(; alpha=exp(x[1])), [α])
31-
test_params(k, ([α],))
32-
test_interface_ad_perf-> RationalKernel(; alpha=α), α, StableRNG(123456))
33-
end
7+
# @testset "RationalKernel" begin
8+
# α = rand()
9+
# k = RationalKernel(; α=α)
10+
11+
# @testset "RationalKernel ≈ Exponential for large α" begin
12+
# @test isapprox(
13+
# RationalKernel(; α=1e9)(v1, v2),
14+
# ExponentialKernel()(v1, v2);
15+
# atol=1e-6,
16+
# rtol=1e-6,
17+
# )
18+
# end
19+
20+
# @test metric(RationalKernel()) == Euclidean()
21+
# @test metric(RationalKernel(; α=α)) == Euclidean()
22+
# @test repr(k) == "Rational Kernel (α = $(α), metric = Euclidean(0.0))"
23+
24+
# k2 = RationalKernel(; α=α, metric=WeightedEuclidean(ones(3)))
25+
# @test metric(k2) isa WeightedEuclidean
26+
# @test k2(v1, v2) ≈ k(v1, v2)
27+
28+
# # Standardised tests.
29+
# TestUtils.test_interface(k, Float64)
30+
# test_ADs(x -> RationalKernel(; alpha=exp(x[1])), [α])
31+
# test_params(k, ([α],))
32+
# test_interface_ad_perf(α -> RationalKernel(; alpha=α), α, StableRNG(123456))
33+
# end
3434

3535
@testset "RationalQuadraticKernel" begin
3636
α = rand()
@@ -55,87 +55,101 @@
5555

5656
# Standardised tests.
5757
TestUtils.test_interface(k, Float64)
58-
test_ADs(x -> RationalQuadraticKernel(; alpha=exp(x[1])), [α])
58+
# test_ADs(x -> RationalQuadraticKernel(; alpha=exp(x[1])), [α])
5959
test_params(k, ([α],))
6060
test_interface_ad_perf(α, StableRNG(123456)) do α
6161
RationalQuadraticKernel(; alpha=α)
6262
end
63-
end
64-
65-
@testset "GammaRationalKernel" begin
66-
k = GammaRationalKernel()
67-
68-
@test repr(k) == "Gamma Rational Kernel (α = 2.0, γ = 1.0, metric = Euclidean(0.0))"
69-
70-
@testset "GammaRational (γ=2) ≈ RQ with rescaled inputs" begin
71-
@test isapprox(
72-
GammaRationalKernel(; γ=2)(v1 ./ sqrt(2), v2 ./ sqrt(2)),
73-
RationalQuadraticKernel()(v1, v2),
74-
)
75-
a = 1 + rand()
76-
@test isapprox(
77-
GammaRationalKernel(; α=a, γ=2)(v1 ./ sqrt(2), v2 ./ sqrt(2)),
78-
RationalQuadraticKernel(; α=a)(v1, v2),
79-
)
80-
end
81-
82-
@testset "GammaRational (γ=2) ≈ EQ for large α with rescaled inputs" begin
83-
v1 = randn(2)
84-
v2 = randn(2)
85-
@test isapprox(
86-
GammaRationalKernel(; α=1e9, γ=2)(v1 ./ sqrt(2), v2 ./ sqrt(2)),
87-
SqExponentialKernel()(v1, v2);
88-
atol=1e-6,
89-
rtol=1e-6,
90-
)
91-
end
92-
93-
@testset "Default GammaRational ≈ Rational" begin
94-
@test isapprox(GammaRationalKernel()(v1, v2), RationalKernel()(v1, v2))
95-
a = 1 + rand()
96-
@test isapprox(
97-
GammaRationalKernel(; α=a)(v1, v2), RationalKernel(; α=a)(v1, v2)
98-
)
99-
end
100-
101-
@testset "Default GammaRational ≈ Exponential for large α" begin
102-
v1 = randn(4)
103-
v2 = randn(4)
104-
@test isapprox(
105-
GammaRationalKernel(; α=1e9)(v1, v2),
106-
ExponentialKernel()(v1, v2);
107-
atol=1e-6,
108-
rtol=1e-6,
109-
)
110-
end
11163

112-
@testset "GammaRational ≈ GammaExponential for same γ and large α" begin
113-
v1 = randn(3)
114-
v2 = randn(3)
115-
γ = rand() + 0.5
116-
@test isapprox(
117-
GammaRationalKernel(; α=1e9, γ=γ)(v1, v2),
118-
GammaExponentialKernel(; γ=γ)(v1, v2);
119-
atol=1e-6,
120-
rtol=1e-6,
121-
)
122-
end
123-
124-
@test metric(GammaRationalKernel()) == Euclidean()
125-
@test metric(GammaRationalKernel(; γ=2.0)) == Euclidean()
126-
@test metric(GammaRationalKernel(; γ=2.0, α=3.0)) == Euclidean()
127-
128-
k2 = GammaRationalKernel(; metric=WeightedEuclidean(ones(3)))
129-
@test metric(k2) isa WeightedEuclidean
130-
@test k2(v1, v2) k(v1, v2)
131-
132-
# Standardised tests.
133-
TestUtils.test_interface(k, Float64)
134-
a = 1.0 + rand()
135-
test_ADs(x -> GammaRationalKernel(; α=x[1], γ=x[2]), [a, 1 + 0.5 * rand()])
136-
test_params(GammaRationalKernel(; α=a, γ=x), ([a], [x]))
137-
test_interface_ad_perf((2.0, 1.5), StableRNG(123456)) do θ
138-
GammaRationalKernel(; α=θ[1], γ=θ[2])
64+
# Check correctness and performance with non-Euclidean metrics.
65+
TestUtils.test_interface(
66+
RationalQuadraticKernel(; alpha=α, metric=WeightedEuclidean([1.0, 2.0])),
67+
ColVecs{Float64},
68+
)
69+
TestUtils.test_interface(
70+
RationalQuadraticKernel(; alpha=α, metric=WeightedEuclidean([1.0, 2.0])),
71+
RowVecs{Float64},
72+
)
73+
types = [ColVecs{Float64, Matrix{Float64}}, RowVecs{Float64, Matrix{Float64}}]
74+
test_interface_ad_perf(α, StableRNG(123456)) do α
75+
RationalQuadraticKernel(; alpha=α, metric=KernelFunctions.DotProduct())
13976
end
14077
end
78+
79+
# @testset "GammaRationalKernel" begin
80+
# k = GammaRationalKernel()
81+
82+
# @test repr(k) == "Gamma Rational Kernel (α = 2.0, γ = 1.0, metric = Euclidean(0.0))"
83+
84+
# @testset "GammaRational (γ=2) ≈ RQ with rescaled inputs" begin
85+
# @test isapprox(
86+
# GammaRationalKernel(; γ=2)(v1 ./ sqrt(2), v2 ./ sqrt(2)),
87+
# RationalQuadraticKernel()(v1, v2),
88+
# )
89+
# a = 1 + rand()
90+
# @test isapprox(
91+
# GammaRationalKernel(; α=a, γ=2)(v1 ./ sqrt(2), v2 ./ sqrt(2)),
92+
# RationalQuadraticKernel(; α=a)(v1, v2),
93+
# )
94+
# end
95+
96+
# @testset "GammaRational (γ=2) ≈ EQ for large α with rescaled inputs" begin
97+
# v1 = randn(2)
98+
# v2 = randn(2)
99+
# @test isapprox(
100+
# GammaRationalKernel(; α=1e9, γ=2)(v1 ./ sqrt(2), v2 ./ sqrt(2)),
101+
# SqExponentialKernel()(v1, v2);
102+
# atol=1e-6,
103+
# rtol=1e-6,
104+
# )
105+
# end
106+
107+
# @testset "Default GammaRational ≈ Rational" begin
108+
# @test isapprox(GammaRationalKernel()(v1, v2), RationalKernel()(v1, v2))
109+
# a = 1 + rand()
110+
# @test isapprox(
111+
# GammaRationalKernel(; α=a)(v1, v2), RationalKernel(; α=a)(v1, v2)
112+
# )
113+
# end
114+
115+
# @testset "Default GammaRational ≈ Exponential for large α" begin
116+
# v1 = randn(4)
117+
# v2 = randn(4)
118+
# @test isapprox(
119+
# GammaRationalKernel(; α=1e9)(v1, v2),
120+
# ExponentialKernel()(v1, v2);
121+
# atol=1e-6,
122+
# rtol=1e-6,
123+
# )
124+
# end
125+
126+
# @testset "GammaRational ≈ GammaExponential for same γ and large α" begin
127+
# v1 = randn(3)
128+
# v2 = randn(3)
129+
# γ = rand() + 0.5
130+
# @test isapprox(
131+
# GammaRationalKernel(; α=1e9, γ=γ)(v1, v2),
132+
# GammaExponentialKernel(; γ=γ)(v1, v2);
133+
# atol=1e-6,
134+
# rtol=1e-6,
135+
# )
136+
# end
137+
138+
# @test metric(GammaRationalKernel()) == Euclidean()
139+
# @test metric(GammaRationalKernel(; γ=2.0)) == Euclidean()
140+
# @test metric(GammaRationalKernel(; γ=2.0, α=3.0)) == Euclidean()
141+
142+
# k2 = GammaRationalKernel(; metric=WeightedEuclidean(ones(3)))
143+
# @test metric(k2) isa WeightedEuclidean
144+
# @test k2(v1, v2) ≈ k(v1, v2)
145+
146+
# # Standardised tests.
147+
# TestUtils.test_interface(k, Float64)
148+
# a = 1.0 + rand()
149+
# test_ADs(x -> GammaRationalKernel(; α=x[1], γ=x[2]), [a, 1 + 0.5 * rand()])
150+
# test_params(GammaRationalKernel(; α=a, γ=x), ([a], [x]))
151+
# test_interface_ad_perf((2.0, 1.5), StableRNG(123456)) do θ
152+
# GammaRationalKernel(; α=θ[1], γ=θ[2])
153+
# end
154+
# end
141155
end

0 commit comments

Comments
 (0)