Skip to content
Prev 206535 / 398503 Next

optimization problem

Interesting! 

Now, if I change the "cost matrix", D,  in the LSAP formulation slightly such that it is quadratic, it finds the best solution to your example:


pMatrix.min <- function(A, B) {
# 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 "clue" package
# Returns P%*%A and the permutation vector `pvec' such that
# A[pvec, ] is the permutation of A closest to B
	n <- nrow(A)
	D <- matrix(NA, n, n)
	for (i in 1:n) {
	for (j in 1:n) {
#	D[j, i] <- sqrt(sum((B[j, ] - A[i, ])^2))
	D[j, i] <- (sum((B[j, ] - A[i, ])^2))  # this is better
	} }
vec <- c(solve_LSAP(D))
list(A=A[vec,], pvec=vec)
}

 > X<-pMatrix.min(A,B)
[1] 6 1 3 2 4 5
[1] 10.50172
This should be fine.  Any counter-examples to this?!

Best,
Ravi.
____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: Erwin Kalvelagen <erwin.kalvelagen at gmail.com>
Date: Saturday, January 16, 2010 5:26 pm
Subject: Re: [R] optimization problem
To: Ravi Varadhan <rvaradhan at jhmi.edu>
Cc: r-help at stat.math.ethz.ch