max.col(m)
m
| a numeric matrix. |
m
,
find the index of a maximal element for each row.
In the case of ties (more than one maximum in a row), uses reservoir sampling to break ties at random.
nc
, of length k =nrow(m)
,
where nc[i] == j
if m[i,j] == max(m[i,])
.
mm <- cbind(1,1:8,3) max.col(mm) apply(mm,1,function(x) order(x)[3])#-- the same [sometimes!] #- See that ties are broken randomly: r <- integer(3) for(i in 1:100) { m <- max.col(mm)[3]; r[m] <- r[m] + 1} r[2:3] # about 50:50 test.cl <- function(true, pred){ ## Compute (Mis)classification table for "Softmax" true <- max.col(true) cres <- max.col(pred) table(true, cres) }