I need to solve a problem that involves comparing two matrices with the same number of columns. One of them is managed until a better match is obtained. The way I evaluate the differences between the two matrices is rather confusing, and I still have to complete it. I am currently very interested in finding a search / optimization algorithm that works only with positive integers. I created a simple example with a simple function to maximize. Say I have a dataset D.
D <- data.frame(rbind(c(1,1,1),
c(1,1,0),c(1,1,0),c(1,1,0),c(1,0,0),
c(0,0,0),c(1,0,0),c(1,0,0),c(1,1,0),
c(1,0,0),c(1,1,1),c(1,1,0),c(1,0,0),
c(1,0,0),c(1,0,1)))
I want to find which permutation Dx gives me the lowest absolute difference.
Dx<-data.frame(rbind(c(1,1,0),c(1,0,0),c(0,0,0),c(1,1,0)))
So I could go through all possible permutations using the function below
library(combinat)
SPACE <- t(as.data.frame(list(permn(1:3))))
f <- function(x){
if(anyDuplicated(x)>0){return(0)}
Dist<-NA
for (i in 1:nrow(D)){
Dist[i]<-sum(abs(Dx[,x]-t(D[i,])))}
return(sum(Dist))}
apply(SPACE,1,f)
. 2 , :
A B , . , 1 14 R .
- . A. , SPACE (.. ), , .
library(NMOF)
gridSearch(f, rep(list(seq(1,ncol(D))),ncol(D)))
, , B, . , , , 15 ?
, (.. ), R, (, , ) (, 1-2 ), ? , , . optim() method="SANN", . , , , , . ( , ), , , D2, - ?
D<-cbind(D,D,D,D,D)
ncol(D)
Dx<-cbind(Dx,Dx,Dx,Dx,Dx)
f(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))
f(c(13,2,4,3,5,6,7,8,9,10,11,12,1,14,15))
EDIT:
, , ( ) , . , , , , , ... ' m, , (, ) f , D2, .