-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmoinput.jl
More file actions
115 lines (96 loc) · 3.88 KB
/
moinput.jl
File metadata and controls
115 lines (96 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@testset "moinput" begin
x = [rand(5) for _ in 1:4]
type_1 = AbstractVector{Tuple{Vector{Float64},Int}}
type_2 = AbstractVector{Tuple{AbstractVector{Vector{Float64}},Int}}
@testset "isotopicbyoutputs" begin
ibo = KernelFunctions.MOInputIsotopicByOutputs(x, 3)
ibo2 = KernelFunctions.MOInputIsotopicByOutputs(x, 2)
@test_throws DimensionMismatch vcat(ibo, ibo2)
@test ibo == MOInput(x, 3)
@test isa(ibo, type_1) == true
@test isa(ibo, type_2) == false
@test length(ibo) == 12
@test size(ibo) == (12,)
@test size(ibo, 1) == 12
@test size(ibo, 2) == 1
@test lastindex(ibo) == 12
@test firstindex(ibo) == 1
@test_throws BoundsError ibo[0]
@test vcat(ibo, ibo) == MOInput(vcat(x, x), 3)
@test ibo[2] == (x[2], 1)
@test ibo[5] == (x[1], 2)
@test ibo[7] == (x[3], 2)
@test all([(x_, i) for i in 1:3 for x_ in x] .== ibo)
end
@testset "isotopicbyfeatures" begin
ibf = KernelFunctions.MOInputIsotopicByFeatures(x, 3)
@test isa(ibf, type_1) == true
@test isa(ibf, type_2) == false
@test length(ibf) == 12
@test size(ibf) == (12,)
@test size(ibf, 1) == 12
@test size(ibf, 2) == 1
@test lastindex(ibf) == 12
@test firstindex(ibf) == 1
@test_throws BoundsError ibf[0]
@test vcat(ibf, ibf) == KernelFunctions.MOInputIsotopicByFeatures(vcat(x, x), 3)
@test ibf[2] == (x[1], 2)
@test ibf[5] == (x[2], 2)
@test ibf[7] == (x[3], 1)
@test all([(x_, i) for x_ in x for i in 1:3] .== ibf)
end
@testset "heterotopic" begin
out_inds = [1, 2, 3, 2]
mo_input = KernelFunctions.MOInputsHeterotopic(x, out_inds)
@test isa(mo_input, type_1) == true
@test isa(mo_input, type_2) == false
@test length(mo_input) == 4
@test size(mo_input) == (4,)
@test size(mo_input, 1) == 4
@test size(mo_input, 2) == 1
@test lastindex(mo_input) == 4
@test firstindex(mo_input) == 1
@test_throws BoundsError mo_input[0]
@test vcat(mo_input, mo_input) == KernelFunctions.MOInputsHeterotopic(vcat(x, x), vcat(out_inds, out_inds))
@test mo_input[2] == (x[2], 2)
@test mo_input[3] == (x[3], 3)
@test mo_input[4] == (x[4], 2)
@test all([(x_, i) for (x_, i) in zip(x, out_inds)] .== mo_input)
end
@testset "prepare_isotopic_multi_output_data" begin
@testset "ColVecs" begin
N = 5
P = 3
x = randn(N)
y = ColVecs(randn(P, N))
x_canon, y_canon = prepare_isotopic_multi_output_data(x, y)
@test x_canon isa KernelFunctions.MOInputIsotopicByFeatures
@test length(x_canon) == N * P
@test y_canon isa AbstractVector{<:Real}
@test length(y_canon) == length(x_canon)
end
@testset "RowVecs" begin
N = 5
P = 3
x = randn(N)
y = RowVecs(randn(N, P))
x_canon, y_canon = prepare_isotopic_multi_output_data(x, y)
@test x_canon isa KernelFunctions.MOInputIsotopicByOutputs
@test length(x_canon) == N * P
@test y_canon isa AbstractVector{<:Real}
@test length(y_canon) == length(x_canon)
end
end
@testset "prepare_heterotopic_multi_output_data" begin
x = randn(3)
y = randn(3)
output_indices = [3, 1, 2]
x_canon, y_canon = prepare_heterotopic_multi_output_data(x, y, output_indices)
@test x_canon isa AbstractVector{<:Tuple{<:Real,Int}}
@test y isa AbstractVector{<:Real}
@test_throws ArgumentError prepare_heterotopic_multi_output_data(x, y, [3, 1])
@test_throws(
ArgumentError, prepare_heterotopic_multi_output_data(x, [1.0], output_indices),
)
end
end