min_fnorm: Minimize Frobenius norm for between two matrices

Description Usage Arguments Details Value Author(s) Examples

View source: R/utils.R

Description

Finds a permutation of a matrix such that its Frobenius norm with another matrix is minimized.

Usage

1
min_fnorm(A, B = diag(nrow(A)))

Arguments

A

data matrix we want to permute

B

matrix whose distance with the permuted A we want to minimize. By default, B <- diag(nrow(A)), so the permutation maximizes the trace of A.

Details

Finds the permutation P of A such that ||PA - B|| is minimum in Frobenius norm. Uses the linear-sum assignment problem (LSAP) solver in the package clue. The default B is the identity matrix of same dimension, so that the permutation of A maximizes its trace. This procedure is useful for constructing a confusion matrix when we don't know the true class labels of a predicted class and want to compare to a reference class.

Value

Permuted matrix such that it is the permutation of A closest to B

Author(s)

Ravi Varadhan: https://stat.ethz.ch/pipermail/r-help/2010-April/236664.html

Examples

1
2
3
set.seed(1)
A <- matrix(sample(1:25, size = 25, rep = FALSE), 5, 5)
min_fnorm(A)

diceR documentation built on June 11, 2018, 5:04 p.m.