@@ -16,13 +16,13 @@ _klterm(x::T, y::T) where {T} = _xlogy(x, x) - _xlogy(x, y)
16
16
17
17
# ###############
18
18
# Means
19
- function vmean (f, A; dims= :)
19
+ function vmean (f:: F , A; dims= :) where {F}
20
20
c = 1 / _denom (A, dims)
21
21
vmapreducethen (f, + , x -> c * x, A, dims= dims)
22
22
end
23
23
vmean (A; dims= :) = vmean (identity, A, dims= dims)
24
24
25
- function vtmean (f, A; dims= :)
25
+ function vtmean (f:: F , A; dims= :) where {F}
26
26
c = 1 / _denom (A, dims)
27
27
vtmapreducethen (f, + , x -> c * x, A, dims= dims)
28
28
end
@@ -54,25 +54,29 @@ function vtharmmean(A; dims=:)
54
54
vtmapreducethen (inv, + , x -> inv (c * x), A, dims= dims)
55
55
end
56
56
57
- # Mean on the log scaley
58
- function vmean_log (f, A; dims= :)
57
+ # Mean on the log scale
58
+ function vmean_log (f:: F , A; dims= :) where {F}
59
59
c = log (_denom (A, dims))
60
60
vmapreducethen (f, + , x -> log (x) - c, A, dims= dims)
61
61
end
62
+ function vtmean_log (f:: F , A; dims= :) where {F}
63
+ c = log (_denom (A, dims))
64
+ vtmapreducethen (f, + , x -> log (x) - c, A, dims= dims)
65
+ end
62
66
63
67
# ###############
64
68
# logsumexp (the naive and unsafe version)
65
69
# Naturally, faster than the overflow/underflow-safe logsumexp, but if one can tolerate it...
66
70
vlse (A; dims= :) = vmapreducethen (exp, + , log, A, dims= dims)
67
71
vtlse (A; dims= :) = vtmapreducethen (exp, + , log, A, dims= dims)
68
- vlse (f, A; dims= :) = vmapreducethen (x -> exp (f (x)), + , log, A, dims= dims)
69
- vtlse (f, A; dims= :) = vtmapreducethen (x -> exp (f (x)), + , log, A, dims= dims)
72
+ vlse (f:: F , A; dims= :) where {F} = vmapreducethen (x -> exp (f (x)), + , log, A, dims= dims)
73
+ vtlse (f:: F , A; dims= :) where {F} = vtmapreducethen (x -> exp (f (x)), + , log, A, dims= dims)
70
74
71
75
function vlse_mean (A; dims= :)
72
76
c = log (_denom (A, dims))
73
77
vmapreducethen (exp, + , x -> log (x) - c, A, dims= dims)
74
78
end
75
- function vlse_mean (f, A; dims= :)
79
+ function vlse_mean (f:: F , A; dims= :) where {F}
76
80
c = log (_denom (A, dims))
77
81
vmapreducethen (x -> exp (f (x)), + , x -> log (x) - c, A, dims= dims)
78
82
end
@@ -81,7 +85,7 @@ function vtlse_mean(A; dims=:)
81
85
c = log (_denom (A, dims))
82
86
vtmapreducethen (exp, + , x -> log (x) - c, A, dims= dims)
83
87
end
84
- function vtlse_mean (f, A; dims= :)
88
+ function vtlse_mean (f:: F , A; dims= :) where {F}
85
89
c = log (_denom (A, dims))
86
90
vtmapreducethen (x -> exp (f (x)), + , x -> log (x) - c, A, dims= dims)
87
91
end
@@ -196,9 +200,6 @@ function vrenyadivergence(p, q, α::Real; dims=:)
196
200
end
197
201
end
198
202
199
-
200
-
201
-
202
203
# ###############
203
204
# Deviations
204
205
0 commit comments