|
1 | 1 | @testset "trainable" begin
|
2 |
| - using Flux: params |
3 | 2 | ν = 2.0; c = 3.0; d = 2.0; γ = 2.0; α = 2.5; h = 0.5; r = rand(3)
|
4 | 3 |
|
| 4 | + function test_params(kernel, reference) |
| 5 | + params_kernel = params(kernel) |
| 6 | + params_reference = params(reference) |
| 7 | + |
| 8 | + @test length(params_kernel) == length(params_reference) |
| 9 | + @test all(p == q for (p, q) in zip(params_kernel, params_reference)) |
| 10 | + end |
| 11 | + |
5 | 12 | kc = ConstantKernel(c=c)
|
6 |
| - @test all(params(kc) .== params([c])) |
| 13 | + test_params(kc, ([c],)) |
7 | 14 |
|
8 | 15 | kfbm = FBMKernel(h = h)
|
9 |
| - @test all(params(kfbm) .== params([h])) |
| 16 | + test_params(kfbm, ([h],)) |
10 | 17 |
|
11 | 18 | kge = GammaExponentialKernel(γ=γ)
|
12 |
| - @test all(params(kge) .== params([γ])) |
| 19 | + test_params(kge, ([γ],)) |
13 | 20 |
|
14 | 21 | kgr = GammaRationalQuadraticKernel(γ=γ, α=α)
|
15 |
| - @test all(params(kgr) .== params([α], [γ])) |
| 22 | + test_params(kgr, ([α], [γ])) |
16 | 23 |
|
17 | 24 | kl = LinearKernel(c=c)
|
18 |
| - @test all(params(kl) .== params([c])) |
| 25 | + test_params(kl, ([c],)) |
19 | 26 |
|
20 | 27 | km = MaternKernel(ν=ν)
|
21 |
| - @test all(params(km) .== params([ν])) |
| 28 | + test_params(km, ([ν],)) |
22 | 29 |
|
23 | 30 | kp = PolynomialKernel(c=c, d=d)
|
24 |
| - @test all(params(kp) .== params([d], [c])) |
| 31 | + test_params(kp, ([d], [c])) |
25 | 32 |
|
26 | 33 | kpe = PeriodicKernel(r = r)
|
27 |
| - @test all(params(kpe) .== params(r)) |
| 34 | + test_params(kpe, (r,)) |
28 | 35 |
|
29 | 36 | kr = RationalQuadraticKernel(α=α)
|
30 |
| - @test all(params(kr) .== params([α])) |
| 37 | + test_params(kr, ([α],)) |
31 | 38 |
|
32 | 39 | k = km + kc
|
33 |
| - @test all(params(k) .== params([k.weights], km, kc)) |
| 40 | + test_params(k, (k.weights, km, kc)) |
34 | 41 |
|
35 | 42 | k = km * kc
|
36 |
| - @test all(params(k) .== params(km, kc)) |
| 43 | + test_params(k, (km, kc)) |
37 | 44 |
|
38 | 45 | s = 2.0
|
39 | 46 | k = transform(km, s)
|
40 |
| - @test all(params(k) .== params([s], km)) |
| 47 | + test_params(k, ([s], km)) |
41 | 48 |
|
42 | 49 | v = [2.0]
|
43 | 50 | k = transform(kc, v)
|
44 |
| - @test all(params(k) .== params(v, kc)) |
| 51 | + test_params(k, (v, kc)) |
45 | 52 |
|
46 | 53 | P = rand(3, 2)
|
47 | 54 | k = transform(km, LinearTransform(P))
|
48 |
| - @test all(params(k) .== params(P, km)) |
| 55 | + test_params(k, (P, km)) |
49 | 56 |
|
50 | 57 | k = transform(km, LinearTransform(P) ∘ ScaleTransform(s))
|
51 |
| - @test all(params(k) .== params([s], P, km)) |
| 58 | + test_params(k, ([s], P, km)) |
52 | 59 |
|
53 | 60 | c = Chain(Dense(3, 2))
|
54 | 61 | k = transform(km, FunctionTransform(c))
|
55 |
| - @test all(params(k) .== params(c, km)) |
| 62 | + test_params(k, (c, km)) |
56 | 63 | end
|
0 commit comments