library(MASS)

ntw.lrn <- read.table("../lrn/ntw_lrn.dat",header=T,sep=",")
ntw.val <- read.table("../val/ntw_val.dat",header=T,sep=",")
ntw.tst <- read.table("../tst/ntw_tst.dat",header=T,sep=",")

ntw <- rbind(ntw.lrn,ntw.val,ntw.tst)

#plot(y=ntw.lrn$connection.type,x=ntw.lrn$duration)

tmp <- names(ntw)

feature.count <- length(tmp)-1
feature.names <- tmp[1:feature.count]

best.cer <- 1

for (i in 1:feature.count) { 
  for (j in 2:feature.count) { 
    if ( is.numeric(ntw.lrn[,i]) && is.numeric(ntw.lrn[,j]) ) {
      if ( (var(ntw.lrn[,i]) > 0) && (var(ntw.lrn[,j]) > 0) ) {
        y <- ntw.lrn$connection.type
        xi <- ntw.lrn[,i]
        xj <- ntw.lrn[,j]
        fit <- lda(cbind(xi,xj),y)
        y <- ntw.val$connection.type
        xi <- ntw.val[,i]
        xj <- ntw.val[,j]
        yhat <- predict(fit,cbind(xi,xj))
        n <- length(y)
        ehat <- (y != yhat$class)
        cer <- sum(ehat)/n
	if (cer < best.cer) {
	  best.cer <- cer
	  best.outcome <- paste(cer,feature.names[i],feature.names[j])
        }
        print(paste(cer,feature.names[i],feature.names[j]))
      }
    }
  }
}

print(" ")
print(" ")
print(best.outcome)

