min_fnorm: Minimize Frobenius norm for between two matrices

View source: R/utils.R

min_fnormR Documentation

Minimize Frobenius norm for between two matrices

Description

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

Usage

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


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

diceR documentation built on Sept. 29, 2023, 1:06 a.m.