2
2
co_identity(x)
3
3
Identity function. Already defined in Julia as `identity`, specialized for scalars in the `comparison` layer.
4
4
"""
5
- co_identity (x; param = nothing , dom_size = 0 , nvars = 0 ) = identity (x)
5
+ co_identity (x; params ... ) = identity (x)
6
6
7
7
"""
8
- co_abs_diff_val_param (x; param )
9
- Return the absolute difference between `x` and `param `.
8
+ co_abs_diff_var_val (x; val )
9
+ Return the absolute difference between `x` and `val `.
10
10
"""
11
- co_abs_diff_val_param (x; param, dom_size = 0 , nvars = 0 ) = abs (x - param )
11
+ co_abs_diff_var_val (x; val, params ... ) = abs (x - val )
12
12
13
13
"""
14
- co_val_minus_param (x; param )
15
- Return the difference `x - param ` if positive, `0.0` otherwise.
14
+ co_var_minus_val (x; val )
15
+ Return the difference `x - val ` if positive, `0.0` otherwise.
16
16
"""
17
- co_val_minus_param (x; param, dom_size = 0 , nvars = 0 ) = max (0.0 , x - param )
17
+ co_var_minus_val (x; val, params ... ) = max (0.0 , x - val )
18
18
19
19
"""
20
- co_param_minus_val (x; param )
21
- Return the difference `param - x` if positive, `0.0` otherwise.
20
+ co_val_minus_var (x; val )
21
+ Return the difference `val - x` if positive, `0.0` otherwise.
22
22
"""
23
- co_param_minus_val (x; param, dom_size = 0 , nvars = 0 ) = max (0.0 , param - x)
23
+ co_val_minus_var (x; val, params ... ) = max (0.0 , val - x)
24
24
25
25
"""
26
- co_euclidean_param (x; param , dom_size)
27
- Compute an euclidean norm with domain size `dom_size`, weighted by `param `, of a scalar.
26
+ co_euclidean_val (x; val , dom_size)
27
+ Compute an euclidean norm with domain size `dom_size`, weighted by `val `, of a scalar.
28
28
"""
29
- function co_euclidean_param (x; param , dom_size, nvars = 0 )
30
- return x == param ? 0.0 : (1.0 + abs (x - param ) / dom_size)
29
+ function co_euclidean_val (x; val , dom_size, params ... )
30
+ return x == val ? 0.0 : (1.0 + abs (x - val ) / dom_size)
31
31
end
32
32
33
33
"""
34
34
co_euclidean(x; dom_size)
35
35
Compute an euclidean norm with domain size `dom_size` of a scalar.
36
36
"""
37
- function co_euclidean (x; param = nothing , dom_size, nvars = 0 )
38
- return co_euclidean_param (x; param = 0.0 , dom_size = dom_size)
37
+ function co_euclidean (x; dom_size, params ... )
38
+ return co_euclidean_val (x; val = 0.0 , dom_size)
39
39
end
40
40
41
41
"""
42
- co_abs_diff_val_vars (x; nvars)
42
+ co_abs_diff_var_vars (x; nvars)
43
43
Return the absolute difference between `x` and the number of variables `nvars`.
44
44
"""
45
- co_abs_diff_val_vars (x; param = nothing , dom_size = 0 , nvars ) = abs (x - nvars)
45
+ co_abs_diff_var_vars (x; nvars, params ... ) = abs (x - nvars)
46
46
47
47
"""
48
- co_val_minus_vars (x; nvars)
48
+ co_var_minus_vars (x; nvars)
49
49
Return the difference `x - nvars` if positive, `0.0` otherwise, where `nvars` denotes the numbers of variables.
50
50
"""
51
- co_val_minus_vars (x; param = nothing , dom_size = 0 , nvars) =
52
- co_val_minus_param (x; param = nvars)
51
+ co_var_minus_vars (x; nvars, params... ) = co_var_minus_val (x; val = nvars)
53
52
54
53
"""
55
- co_vars_minus_val (x; nvars)
54
+ co_vars_minus_var (x; nvars)
56
55
Return the difference `nvars - x` if positive, `0.0` otherwise, where `nvars` denotes the numbers of variables.
57
56
"""
58
- co_vars_minus_val (x; param = nothing , dom_size = 0 , nvars) =
59
- co_param_minus_val (x; param = nvars)
57
+ co_vars_minus_var (x; nvars, params... ) = co_val_minus_var (x; val = nvars)
60
58
61
59
62
60
# Parametric layers
@@ -66,18 +64,18 @@ function make_comparisons(::Val{:none})
66
64
return LittleDict {Symbol,Function} (
67
65
:identity => co_identity,
68
66
:euclidean => co_euclidean,
69
- :abs_diff_val_vars => co_abs_diff_val_vars ,
70
- :val_minus_vars => co_val_minus_vars ,
71
- :vars_minus_val => co_vars_minus_val ,
67
+ :abs_diff_var_vars => co_abs_diff_var_vars ,
68
+ :var_minus_vars => co_var_minus_vars ,
69
+ :vars_minus_var => co_vars_minus_var ,
72
70
)
73
71
end
74
72
75
73
function make_comparisons (:: Val{:val} )
76
74
return LittleDict {Symbol,Function} (
77
- :abs_diff_val_param => co_abs_diff_val_param ,
78
- :val_minus_param => co_val_minus_param ,
79
- :param_minus_val => co_param_minus_val ,
80
- :euclidean_param => co_euclidean_param ,
75
+ :abs_diff_var_val => co_abs_diff_var_val ,
76
+ :var_minus_val => co_var_minus_val ,
77
+ :val_minus_var => co_val_minus_var ,
78
+ :euclidean_val => co_euclidean_val ,
81
79
)
82
80
end
83
81
@@ -113,21 +111,21 @@ end
113
111
end
114
112
115
113
funcs_param = [
116
- CN. co_abs_diff_val_param => [2 , 5 ],
117
- CN. co_val_minus_param => [2 , 0 ],
118
- CN. co_param_minus_val => [0 , 5 ],
114
+ CN. co_abs_diff_var_val => [2 , 5 ],
115
+ CN. co_var_minus_val => [2 , 0 ],
116
+ CN. co_val_minus_var => [0 , 5 ],
119
117
]
120
118
121
119
for (f, results) in funcs_param
122
120
for (key, vals) in enumerate (data)
123
- @test f (vals. first; param = vals. second[1 ]) == results[key]
121
+ @test f (vals. first; val = vals. second[1 ]) == results[key]
124
122
end
125
123
end
126
124
127
125
funcs_vars = [
128
- CN. co_abs_diff_val_vars => [2 , 0 ],
129
- CN. co_val_minus_vars => [0 , 0 ],
130
- CN. co_vars_minus_val => [2 , 0 ],
126
+ CN. co_abs_diff_var_vars => [2 , 0 ],
127
+ CN. co_var_minus_vars => [0 , 0 ],
128
+ CN. co_vars_minus_var => [2 , 0 ],
131
129
]
132
130
133
131
for (f, results) in funcs_vars
@@ -136,11 +134,11 @@ end
136
134
end
137
135
end
138
136
139
- funcs_param_dom = [CN. co_euclidean_param => [1.4 , 2.0 ]]
137
+ funcs_val_dom = [CN. co_euclidean_val => [1.4 , 2.0 ]]
140
138
141
- for (f, results) in funcs_param_dom
139
+ for (f, results) in funcs_val_dom
142
140
for (key, vals) in enumerate (data)
143
- @test f (vals. first, param = vals. second[1 ], dom_size = vals. second[2 ]) ≈
141
+ @test f (vals. first, val = vals. second[1 ], dom_size = vals. second[2 ]) ≈
144
142
results[key]
145
143
end
146
144
end
0 commit comments