|
4 | 4 | v1 = rand(rng, 3)
|
5 | 5 | v2 = rand(rng, 3)
|
6 | 6 |
|
| 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 (α = $(α))" |
| 23 | + |
| 24 | + # Standardised tests. |
| 25 | + TestUtils.test_interface(k, Float64) |
| 26 | + test_ADs(x -> RationalKernel(; alpha=exp(x[1])), [α]) |
| 27 | + test_params(k, ([α],)) |
| 28 | + end |
| 29 | + |
7 | 30 | @testset "RationalQuadraticKernel" begin
|
8 |
| - α = 2.0 |
| 31 | + α = rand() |
9 | 32 | k = RationalQuadraticKernel(; α=α)
|
10 | 33 |
|
11 | 34 | @testset "RQ ≈ EQ for large α" begin
|
|
18 | 41 | end
|
19 | 42 |
|
20 | 43 | @test metric(RationalQuadraticKernel()) == SqEuclidean()
|
21 |
| - @test metric(RationalQuadraticKernel(; α=2.0)) == SqEuclidean() |
| 44 | + @test metric(RationalQuadraticKernel(; α=α)) == SqEuclidean() |
22 | 45 | @test repr(k) == "Rational Quadratic Kernel (α = $(α))"
|
23 | 46 |
|
24 | 47 | # Standardised tests.
|
25 | 48 | TestUtils.test_interface(k, Float64)
|
26 |
| - test_ADs(x -> RationalQuadraticKernel(; alpha=x[1]), [α]) |
| 49 | + test_ADs(x -> RationalQuadraticKernel(; alpha=exp(x[1])), [α]) |
27 | 50 | test_params(k, ([α],))
|
28 | 51 | end
|
29 | 52 |
|
30 |
| - @testset "GammaRationalQuadraticKernel" begin |
31 |
| - k = GammaRationalQuadraticKernel() |
| 53 | + @testset "GammaRationalKernel" begin |
| 54 | + k = GammaRationalKernel() |
32 | 55 |
|
33 |
| - @test repr(k) == "Gamma Rational Quadratic Kernel (α = 2.0, γ = 2.0)" |
| 56 | + @test repr(k) == "Gamma Rational Kernel (α = 2.0, γ = 2.0)" |
34 | 57 |
|
35 |
| - @testset "Default GammaRQ ≈ RQ with rescaled inputs" begin |
| 58 | + @testset "Default GammaRational ≈ RQ with rescaled inputs" begin |
36 | 59 | @test isapprox(
|
37 |
| - GammaRationalQuadraticKernel()(v1 ./ sqrt(2), v2 ./ sqrt(2)), |
| 60 | + GammaRationalKernel()(v1 ./ sqrt(2), v2 ./ sqrt(2)), |
38 | 61 | RationalQuadraticKernel()(v1, v2),
|
39 | 62 | )
|
40 |
| - a = 1.0 + rand() |
| 63 | + a = 1 + rand() |
41 | 64 | @test isapprox(
|
42 |
| - GammaRationalQuadraticKernel(; α=a)(v1 ./ sqrt(2), v2 ./ sqrt(2)), |
| 65 | + GammaRationalKernel(; α=a)(v1 ./ sqrt(2), v2 ./ sqrt(2)), |
43 | 66 | RationalQuadraticKernel(; α=a)(v1, v2),
|
44 | 67 | )
|
45 | 68 | end
|
46 | 69 |
|
47 |
| - @testset "GammaRQ ≈ EQ for large α with rescaled inputs" begin |
| 70 | + @testset "Default GammaRational ≈ EQ for large α with rescaled inputs" begin |
48 | 71 | v1 = randn(2)
|
49 | 72 | v2 = randn(2)
|
50 | 73 | @test isapprox(
|
51 |
| - GammaRationalQuadraticKernel(; α=1e9)(v1 ./ sqrt(2), v2 ./ sqrt(2)), |
| 74 | + GammaRationalKernel(; α=1e9)(v1 ./ sqrt(2), v2 ./ sqrt(2)), |
52 | 75 | SqExponentialKernel()(v1, v2);
|
53 | 76 | atol=1e-6,
|
54 | 77 | rtol=1e-6,
|
55 | 78 | )
|
56 | 79 | end
|
57 | 80 |
|
58 |
| - @testset "GammaRQ(γ=1) ≈ Exponential with rescaled inputs for large α" begin |
| 81 | + @testset "GammaRational(γ=1) ≈ Rational" begin |
| 82 | + @test isapprox(GammaRationalKernel(; γ=1.0)(v1, v2), RationalKernel()(v1, v2)) |
| 83 | + a = 1 + rand() |
| 84 | + @test isapprox( |
| 85 | + GammaRationalKernel(; γ=1.0, α=a)(v1, v2), RationalKernel(; α=a)(v1, v2) |
| 86 | + ) |
| 87 | + end |
| 88 | + |
| 89 | + @testset "GammaRational(γ=1) ≈ Exponential with rescaled inputs for large α" begin |
59 | 90 | v1 = randn(4)
|
60 | 91 | v2 = randn(4)
|
61 | 92 | @test isapprox(
|
62 |
| - GammaRationalQuadraticKernel(; α=1e9, γ=1.0)(v1, v2), |
| 93 | + GammaRationalKernel(; α=1e9, γ=1.0)(v1, v2), |
63 | 94 | ExponentialKernel()(v1, v2);
|
64 | 95 | atol=1e-6,
|
65 | 96 | rtol=1e-6,
|
66 | 97 | )
|
67 | 98 | end
|
68 | 99 |
|
69 |
| - @testset "GammaRQ ≈ GammaExponential for same γ and large α" begin |
| 100 | + @testset "GammaRational ≈ GammaExponential for same γ and large α" begin |
70 | 101 | v1 = randn(3)
|
71 | 102 | v2 = randn(3)
|
72 | 103 | γ = rand() + 0.5
|
73 | 104 | @test isapprox(
|
74 |
| - GammaRationalQuadraticKernel(; α=1e9, γ=γ)(v1, v2), |
| 105 | + GammaRationalKernel(; α=1e9, γ=γ)(v1, v2), |
75 | 106 | GammaExponentialKernel(; γ=γ)(v1, v2);
|
76 | 107 | atol=1e-6,
|
77 | 108 | rtol=1e-6,
|
78 | 109 | )
|
79 | 110 | end
|
80 | 111 |
|
81 |
| - @test metric(GammaRationalQuadraticKernel()) == Euclidean() |
82 |
| - @test metric(GammaRationalQuadraticKernel(; γ=2.0)) == Euclidean() |
83 |
| - @test metric(GammaRationalQuadraticKernel(; γ=2.0, α=3.0)) == Euclidean() |
| 112 | + @test metric(GammaRationalKernel()) == Euclidean() |
| 113 | + @test metric(GammaRationalKernel(; γ=2.0)) == Euclidean() |
| 114 | + @test metric(GammaRationalKernel(; γ=2.0, α=3.0)) == Euclidean() |
| 115 | + |
| 116 | + # Deprecations. |
| 117 | + a = rand() |
| 118 | + g = 2 * rand() |
| 119 | + @test GammaRationalQuadraticKernel()(v1, v2) == GammaRationalKernel()(v1, v2) |
| 120 | + @test GammaRationalQuadraticKernel(; γ=g)(v1, v2) == |
| 121 | + GammaRationalKernel(; γ=g)(v1, v2) |
| 122 | + @test GammaRationalQuadraticKernel(; γ=g, α=a)(v1, v2) == |
| 123 | + GammaRationalKernel(; γ=g, α=a)(v1, v2) |
84 | 124 |
|
85 | 125 | # Standardised tests.
|
86 | 126 | TestUtils.test_interface(k, Float64)
|
87 | 127 | a = 1.0 + rand()
|
88 |
| - test_ADs(x -> GammaRationalQuadraticKernel(; α=x[1], γ=x[2]), [a, 1 + 0.5 * rand()]) |
89 |
| - test_params(GammaRationalQuadraticKernel(; α=a, γ=x), ([a], [x])) |
| 128 | + test_ADs(x -> GammaRationalKernel(; α=x[1], γ=x[2]), [a, 1 + 0.5 * rand()]) |
| 129 | + test_params(GammaRationalKernel(; α=a, γ=x), ([a], [x])) |
90 | 130 | end
|
91 | 131 | end
|
0 commit comments