5
5
#
6
6
# ###########################################################################################
7
7
# Assorted functions from StatsBase, plus some of my own
8
-
9
8
# ###############
10
9
# Means
11
10
function vmean (f:: F , A; dims= :) where {F}
12
11
c = 1 / _denom (A, dims)
13
- vmapreducethen (f , + , x -> c * x, A, dims= dims)
12
+ vmapreducethen (x -> float ( f (x)) , + , x -> c * x, A, dims= dims)
14
13
end
15
14
vmean (A; dims= :) = vmean (identity, A, dims= dims)
16
15
17
16
function vtmean (f:: F , A; dims= :) where {F}
18
17
c = 1 / _denom (A, dims)
19
- vtmapreducethen (f , + , x -> c * x, A, dims= dims)
18
+ vtmapreducethen (x -> float ( f (x)) , + , x -> c * x, A, dims= dims)
20
19
end
21
20
vtmean (A; dims= :) = vtmean (identity, A, dims= dims)
22
21
@@ -97,13 +96,12 @@ _vmaxentropy(p, dims::NTuple{M, Int}) where {M} =
97
96
_vmaxentropy (p, :: Colon ) = log (length (p))
98
97
vmaxentropy (p; dims= :) = _vmaxentropy (p, dims)
99
98
vshannonentropy (p; dims= :) = vmapreducethen (_xlogx, + , - , p, dims= dims)
100
- vcollisionentropy (p; dims= :) = vmapreducethen (abs2, + , x -> - log (x), p, dims= dims)
99
+ vcollisionentropy (p; dims= :) = vmapreducethen (abs2 ∘ float , + , x -> - log (x), p, dims= dims)
101
100
vminentropy (p; dims= :) = vmapreducethen (identity, max, x -> - log (x), p, dims= dims)
102
101
103
- _vrenyientropy (p, α:: T , dims) where {T<: Integer } =
104
- (c = one (T) / (one (T) - α); vmapreducethen (x -> x^ α, + , x -> c * log (x), p, dims= dims))
105
102
_vrenyientropy (p, α:: T , dims) where {T<: AbstractFloat } =
106
103
(c = one (T) / (one (T) - α); vmapreducethen (x -> exp (α * log (x)), + , x -> c * log (x), p, dims= dims))
104
+ _vrenyientropy (p, α:: T , dims) where {T<: Integer } = _vrenyientryop (p, float (α), dims)
107
105
_vrenyientropy (p, α:: Rational{T} , dims) where {T} = _vrenyientropy (p, float (α), dims)
108
106
function vrenyientropy (p, α:: Real ; dims= :)
109
107
α < 0 && throw (ArgumentError (" Order of Rényi entropy not legal, $(α) < 0." ))
@@ -139,13 +137,12 @@ _vtmaxentropy(p, dims::NTuple{M, Int}) where {M} =
139
137
_vtmaxentropy (p, :: Colon ) = log (length (p))
140
138
vtmaxentropy (p; dims= :) = _vtmaxentropy (p, dims)
141
139
vtshannonentropy (p; dims= :) = vtmapreducethen (_xlogx, + , - , p, dims= dims)
142
- vtcollisionentropy (p; dims= :) = vtmapreducethen (abs2, + , x -> - log (x), p, dims= dims)
140
+ vtcollisionentropy (p; dims= :) = vtmapreducethen (abs2 ∘ float , + , x -> - log (x), p, dims= dims)
143
141
vtminentropy (p; dims= :) = vtmapreducethen (identity, max, x -> - log (x), p, dims= dims)
144
142
145
- _vtrenyientropy (p, α:: T , dims) where {T<: Integer } =
146
- (c = one (T) / (one (T) - α); vtmapreducethen (x -> x^ α, + , x -> c * log (x), p, dims= dims))
147
143
_vtrenyientropy (p, α:: T , dims) where {T<: AbstractFloat } =
148
144
(c = one (T) / (one (T) - α); vtmapreducethen (x -> exp (α * log (x)), + , x -> c * log (x), p, dims= dims))
145
+ _vtrenyientropy (p, α:: T , dims) where {T<: Integer } = _vrenyientryop (p, float (α), dims)
149
146
_vtrenyientropy (p, α:: Rational{T} , dims) where {T} = _vtrenyientropy (p, float (α), dims)
150
147
function vtrenyientropy (p, α:: Real ; dims= :)
151
148
α < 0 && throw (ArgumentError (" Order of Rényi entropy not legal, $(α) < 0." ))
@@ -274,7 +271,7 @@ See also: [`vmaxad`](@ref)
274
271
"""
275
272
function vmeanad (x, y; dims= :)
276
273
c = 1 / _denom (x, dims)
277
- vmapreducethen ((xᵢ, yᵢ) -> abs (xᵢ - yᵢ ) , + , z -> c * z, x, y, dims= dims)
274
+ vmapreducethen ((xᵢ, yᵢ) -> abs (float (xᵢ) - float (yᵢ) ) , + , z -> c * z, x, y, dims= dims)
278
275
end
279
276
280
277
"""
@@ -287,7 +284,7 @@ See also: [`vtmaxad`](@ref)
287
284
"""
288
285
function vtmeanad (x, y; dims= :)
289
286
c = 1 / _denom (x, dims)
290
- vtmapreducethen ((xᵢ, yᵢ) -> abs (xᵢ - yᵢ ) , + , z -> c * z, x, y, dims= dims)
287
+ vtmapreducethen ((xᵢ, yᵢ) -> abs (float (xᵢ) - float (yᵢ) ) , + , z -> c * z, x, y, dims= dims)
291
288
end
292
289
293
290
"""
@@ -320,7 +317,7 @@ See also: [`vrmse`](@ref)
320
317
"""
321
318
function vmse (x, y; dims= :)
322
319
c = 1 / _denom (x, dims)
323
- vmapreducethen ((xᵢ, yᵢ) -> abs2 (xᵢ - yᵢ ) , + , z -> c * z, x, y, dims= dims)
320
+ vmapreducethen ((xᵢ, yᵢ) -> abs2 (float (xᵢ) - float (yᵢ) ) , + , z -> c * z, x, y, dims= dims)
324
321
end
325
322
326
323
"""
@@ -333,7 +330,7 @@ See also: [`vtrmse`](@ref)
333
330
"""
334
331
function vtmse (x, y; dims= :)
335
332
c = 1 / _denom (x, dims)
336
- vtmapreducethen ((xᵢ, yᵢ) -> abs2 (xᵢ - yᵢ ) , + , z -> c * z, x, y, dims= dims)
333
+ vtmapreducethen ((xᵢ, yᵢ) -> abs2 (float (xᵢ) - float (yᵢ) ) , + , z -> c * z, x, y, dims= dims)
337
334
end
338
335
339
336
"""
@@ -348,7 +345,7 @@ See also: [`vmse`](@ref)
348
345
"""
349
346
function vrmse (x, y; dims= :)
350
347
c = 1 / _denom (x, dims)
351
- vmapreducethen ((xᵢ, yᵢ) -> abs2 (xᵢ - yᵢ ) , + , z -> √ (c * z), x, y, dims= dims)
348
+ vmapreducethen ((xᵢ, yᵢ) -> abs2 (float (xᵢ) - float (yᵢ) ) , + , z -> √ (c * z), x, y, dims= dims)
352
349
end
353
350
354
351
"""
@@ -363,7 +360,7 @@ See also: [`vtmse`](@ref)
363
360
"""
364
361
function vtrmse (x, y; dims= :)
365
362
c = 1 / _denom (x, dims)
366
- vtmapreducethen ((xᵢ, yᵢ) -> abs2 (xᵢ - yᵢ ) , + , z -> √ (c * z), x, y, dims= dims)
363
+ vtmapreducethen ((xᵢ, yᵢ) -> abs2 (float (xᵢ) - float (yᵢ) ) , + , z -> √ (c * z), x, y, dims= dims)
367
364
end
368
365
369
366
# Match names with StatsBase
0 commit comments