rename argmax as onecold
This commit is contained in:
parent
33c901c191
commit
6c97846551
|
@ -56,11 +56,14 @@ onehotbatch(ls, labels, unk...) =
|
|||
|
||||
import Base:argmax
|
||||
|
||||
argmax(y::AbstractVector, labels) =
|
||||
onecold(y::AbstractVector, labels = 1:length(y)) =
|
||||
labels[something(findfirst(isequal(maximum(y)), y), 0)]
|
||||
|
||||
argmax(y::AbstractMatrix, labels) =
|
||||
dropdims(mapslices(y -> argmax(y, labels), y, dims=1), dims=1)
|
||||
onecold(y::AbstractMatrix, labels...) =
|
||||
dropdims(mapslices(y -> onecold(y, labels...), y, dims=1), dims=1)
|
||||
|
||||
@deprecate argmax(y::AbstractVector, labels::AbstractVector) onecold(y, labels)
|
||||
@deprecate argmax(y::AbstractMatrix, labels::AbstractVector) onecold(y, labels)
|
||||
|
||||
# Ambiguity hack
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
using Flux:argmax
|
||||
using Flux:onecold
|
||||
using Test
|
||||
|
||||
@testset "argmax" begin
|
||||
a = [1, 2, 5, 3.]
|
||||
A = [1 20 5; 2 7 6; 3 9 10; 2 1 14]
|
||||
labels = ['A', 'B', 'C', 'D']
|
||||
|
||||
@test argmax(a) == 3
|
||||
@test argmax(A) == CartesianIndex(1, 2)
|
||||
@test argmax(a, labels) == 'C'
|
||||
@test argmax(A, labels) == ['C', 'A', 'D']
|
||||
|
||||
@test onecold(a) == 3
|
||||
@test onecold(A) == [3, 1, 4]
|
||||
@test onecold(a, labels) == 'C'
|
||||
@test onecold(A, labels) == ['C', 'A', 'D']
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue