rm(list=ls())
setwd("/yourpath/codes")


source("./knn_belief_fusion.r")
source("./knn_fusion.r")
source("./knn_fuzzy_fusion.r")
source("./bayes_classifier.r")

#plane data
plane <- read.table(file="plane.txt",sep=",")
nbD <- dim(plane)[1]
nbC <- dim(plane)[2]
indice <- sample(c(1:nbD)) # random selection of data
nbT <- round(nbD*2/3)
train <- data.matrix(plane[indice[1:nbT],1:nbC-1]) #take 2/3 of the data for training
trainLabel <- plane[indice[1:nbT],nbC]
nbB <- nbT+1
test <- data.matrix(plane[indice[nbB:nbD],1:nbC-1])
trueLabel <- plane[indice[nbB:nbD],nbC]

res1 <- knn_fusion(train,trainLabel,test,trueLabel,k=3)
res2 <- knn_fuzzy_fusion(train,trainLabel,test,trueLabel,k=3,kf=5)
res3 <- bayes_classifier(train,trainLabel,test,trueLabel)
res4 <- knn_belief_fusion(train,trainLabel,test,trueLabel,k=3)

res1$matr_conf
res2$matr_conf
res3$matr_conf
res4$matr_conf

#fusion
source("./mydiscounting.r")
alpha <- 0.5
mass_knn_s <- mydiscounting(res1$matr_sort_classif,alpha)
mass_knnf_s <- mydiscounting(res2$matr_sort_classif,alpha)
mass_BC_s <- mydiscounting(res3$matr_sort_classif,alpha)


source("./conversionBinaryOrder.r")
mass_knn <- conversionBinaryOrder(mass_knn_s)
mass_knnf <- conversionBinaryOrder(mass_knnf_s)
mass_BC <- conversionBinaryOrder(mass_BC_s)
mass_eknn <- conversionBinaryOrder(res4$matr_sort_classif)


library(ibelief)
nbTest=dim(test)[1]
criteria <- 1
foundLabel=c()
for (i in 1:nbTest){
  massIn <- cbind(mass_knn[,i],mass_knnf[,i],mass_BC[,i],mass_eknn[,i])
  massC <- DST(massIn,criteria)
  foundLabel <- c(foundLabel, decisionDST(massC,4))
  #foundLabel <- c(foundLabel, which.max(mtobetp(massC)))
}


restest=rbind(trueLabel ,foundLabel)

res<-paramperf(restest)
res[1]

