normalize() { cat - |	gawk 'BEGIN{FS=OFS=","} NR>1{for(i=2;i<=NF;i++) $i = int(100*$i/(89*7)); print $0}'; }
data() { cat <<EOF 
dataset,norm-CARTOn,norm-CARTOff,none-CARTOn,none-CARTOff,log-CARTOn,log-CARTOff,SWReg-CARTOn,SWReg-CARTOff,SFS-CARTOn,SFS-CARTOff,SWReg-1NN,log-1NN,SWReg-ABE0,SFS-ABE0,PCA-PLSR,SWReg-PCR,none-PLSR,SFS-1NN,PCA-PCR,none-PCR,PCA-CARTOn,PCA-CARTOff,freq5bin-ABE0,SWReg-PLSR,SFS-SLReg,norm-1NN,none-1NN,SFS-PCR,SFS-PLSR,freq5bin-CARTOn,freq5bin-CARTOff,width5bin-CARTOn,width5bin-CARTOff,norm-ABE0,PCA-SWReg,none-ABE0,SWReg-SWReg,SFS-SWReg,log-ABE0,norm-SWReg,none-SWReg,freq3bin-ABE0,PCA-ABE0,width3bin-CARTOn,width3bin-CARTOff,PCA-NNet,width3bin-ABE0,none-NNet,width5bin-SWReg,width5bin-1NN,none-SLReg,width5bin-ABE0,SFS-NNet,norm-PLSR,freq5bin-1NN,SWReg-NNet,SWReg-SLReg,norm-SLReg,freq3bin-1NN,freq3bin-CARTOn,freq3bin-CARTOff,PCA-1NN,width3bin-SWReg,width5bin-PLSR,log-SWReg,log-PCR,log-PLSR,width3bin-PLSR,width3bin-1NN,width5bin-PCR,norm-PCR,width3bin-PCR,freq5bin-PCR,freq5bin-SWReg,width3bin-SLReg,freq3bin-PCR,width5bin-SLReg,freq3bin-PLSR,freq5bin-PLSR,log-SLReg,freq3bin-SWReg,freq5bin-SLReg,width5bin-NNet,norm-NNet,width3bin-NNet,log-NNet,freq3bin-NNet,freq5bin-NNet,freq3bin-SLReg,PCA-SLReg
telecom1,0,0,0,0,0,0,0,0,0,0,8,8,0,0,0,0,0,8,0,0,0,0,0,0,0,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,15,15,12,16,14,11,10,10,10,10,9,9,15,15,16,10,10,16,16,10,10,11,11,11,11,12,7,12,7,7,16,7,7,9,8,8,8,26,14,26,10,10,7,13,21,7,10,23,0,10,0,0,0,0,8,15,0,0,0,16,7,16,10,15,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0
cocomo81e,25,25,26,26,26,26,40,40,2,2,8,11,33,25,6,7,6,6,2,0,11,11,24,7,2,8,6,3,3,2,2,6,6,8,2,1,7,10,1,6,6,48,4,1,1,22,4,22,4,22,12,1,15,10,22,22,1,4,31,4,4,7,3,3,1,12,6,7,7,7,7,13,2,3,0,10,4,3,0,7,2,9,15,15,14,12,12,14,12,12
nasa93_{center5},29,29,29,29,29,29,28,28,31,31,31,39,40,11,15,11,15,31,16,16,26,26,11,11,17,10,10,10,11,0,0,10,10,13,12,13,11,11,10,11,11,1,15,12,12,0,13,0,12,1,11,13,0,0,12,0,0,2,1,9,9,23,0,0,12,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10
desharnaisL2,20,20,20,20,20,20,8,8,8,8,8,7,14,11,10,19,10,10,11,11,12,12,8,19,27,8,8,24,24,12,12,8,8,8,15,8,19,17,8,14,14,6,7,9,9,10,8,10,8,7,14,8,12,14,0,12,24,15,8,0,0,0,10,13,10,8,8,12,6,10,10,13,6,6,7,6,8,6,1,6,7,0,0,0,0,0,0,0,0,0
desharnais,18,18,18,18,18,18,36,36,41,41,15,9,35,36,13,14,13,39,13,13,1,1,7,14,28,7,7,14,14,32,32,10,10,13,13,13,20,20,7,15,15,9,13,10,10,10,7,10,11,14,13,10,14,13,1,14,18,13,1,1,1,7,9,7,9,13,9,10,1,9,7,1,11,7,1,7,7,7,7,7,7,7,0,0,0,0,0,0,1,0
maxwell,32,32,32,32,32,32,32,32,32,32,22,25,24,24,19,23,19,22,22,17,32,32,2,23,26,22,22,23,23,2,2,32,32,19,19,19,23,23,19,22,22,2,19,32,32,20,16,20,23,16,5,16,20,15,14,20,26,5,2,32,32,14,20,20,14,15,3,13,16,0,0,0,0,2,2,0,20,2,1,2,2,0,0,0,0,0,0,0,0,0
nasa93_{center1},37,37,37,37,30,30,38,38,45,45,23,44,54,55,3,3,3,39,5,3,20,20,61,3,16,44,44,9,9,40,40,8,8,53,7,53,4,9,40,4,3,62,53,8,8,6,53,5,39,41,13,45,6,3,22,6,50,25,9,40,40,47,2,2,2,2,7,3,48,3,3,2,4,4,5,6,9,1,2,3,0,3,3,3,3,3,3,3,1,9
sdr,15,15,15,15,15,15,29,29,19,19,29,2,65,0,65,51,65,0,63,63,22,22,15,57,27,0,0,59,63,13,13,1,1,11,15,11,50,22,5,3,2,3,1,1,1,5,12,4,1,1,6,2,4,3,7,4,33,3,1,13,13,0,4,14,1,2,1,8,1,3,1,0,3,4,0,2,2,2,2,0,4,3,11,11,11,7,7,9,6,9
finnish,73,73,73,73,73,73,73,73,10,10,75,15,23,15,18,10,18,15,16,16,10,10,17,10,11,16,16,17,18,70,70,69,69,11,11,11,10,11,1,10,10,4,10,17,17,1,10,1,10,18,11,15,1,11,18,1,1,10,17,32,32,11,17,14,10,10,10,11,11,10,2,9,11,15,1,11,9,15,15,16,10,0,1,1,1,0,1,1,1,0
miyazaki94,53,53,53,53,49,49,62,62,19,19,66,27,42,25,30,25,30,22,28,28,27,27,42,25,10,30,30,14,14,25,25,27,27,37,29,36,28,14,59,28,28,38,25,27,27,22,16,21,22,14,18,13,22,25,25,31,30,25,27,12,12,18,27,22,0,8,1,21,2,20,20,19,8,3,1,5,0,3,2,0,1,0,1,1,1,1,1,1,3,9
nasa93_center_2,62,62,62,62,62,62,54,54,39,39,69,73,14,69,23,32,23,54,28,28,34,34,12,15,57,62,62,16,16,21,21,13,13,3,42,0,57,16,12,54,54,14,11,0,0,4,1,4,1,8,57,2,4,21,19,4,8,55,19,23,23,54,1,11,8,2,4,8,4,7,4,10,1,1,2,4,8,4,1,1,7,3,6,6,6,6,6,6,9,13
cocomo81,54,54,53,53,54,54,61,61,58,58,67,71,57,58,34,34,32,59,50,44,68,68,36,7,31,51,50,27,35,61,61,38,38,32,19,25,5,33,8,4,1,36,60,37,37,35,37,33,1,37,6,30,35,1,26,35,27,17,34,40,40,58,18,17,3,0,0,11,60,4,28,3,2,0,2,43,3,0,0,0,0,2,2,2,2,1,2,2,2,1
nasa93,69,69,69,69,69,69,69,69,72,72,89,77,72,36,13,24,13,71,13,13,62,62,43,23,67,48,48,23,23,72,72,19,19,26,10,21,12,12,42,12,12,44,30,0,0,11,36,11,8,1,24,32,11,0,44,11,12,32,21,23,23,48,0,0,1,5,0,1,1,2,5,9,3,5,2,1,11,2,5,10,4,0,5,5,5,5,5,5,3,5
china,85,85,85,85,85,85,84,84,84,84,47,43,47,60,62,63,62,60,62,62,84,84,48,63,69,43,43,62,62,58,58,29,29,43,60,43,60,78,43,60,60,41,42,12,12,60,21,60,28,28,60,24,69,43,40,62,60,60,40,42,42,39,12,28,10,8,8,12,17,0,11,4,11,11,11,3,28,8,3,0,10,11,6,4,4,4,4,4,11,0
EOF
}

get() {
	data | normalize |  
	gawk -F, '{OFS="\t"; for(i=2;i<=NF;i++) 
			if ($i < Max && $i >= Min) print NR,i }' Max=$2 Min=$1
}
cols() { data | gawk -F, 'NR> 1{OFS="\t"; sum=0; for(i=2;i<=NF;i++) sum += $i; print $1,sum*100/(89*1*90)}'; }
rows() { data | gawk -F, 'NR> 1{OFS="\t";  for(i=2;i<=NF;i++) sum[i] += $i} END{
                            for(i=2;i<=NF;i++) print sum[i]*100/(89*1*20) }'; }
names() { data | gawk -F, 'NR==1 {SUBSEP=" ";
					  for(i=2;i<=9;i++) mark(8,$i) 
					  for(i=10;i<=30;i++) mark(30,$i) 
					  for(i=31;i<=50;i++) mark(50,$i) 
					  for(i=51;i<=70;i++) mark(70,$i) 
					  for(i=71;i<=NF;i++) mark(90,$i) 
					  }
					  END {
					  	report("learners",ls,lsall)
					  	report("preps",ps,psall)
				  }
function report(header,all,m) {
	print header
	OFS="   "
	for(key in keys)
		for(one in all) {
			n =  ( (key,one) in m) ? m[key,one] : 0
			print one,key,n
		}
}
function mark(key,str,  l,p,tmp) {
	split(str,tmp,/-/)
	l = tmp[2]
	p = tmp[1]
	ls[l]
	ps[p]
	keys[key]
	psall[key,p]++
	lsall[key,l]++
}'
}
names | tee   names.out

cols | cat -n >  cols.dat
rows | cat -n >  rows.dat
get 0 12.5 >  5.dat
get 12.5 25 >  25.dat
get 25 50 >  50.dat
get 50 100 >  100.dat

gnuplot<<EOF
set size 0.5,0.5
set terminal postscript eps color enhanced "Helvetica" 12
set output "rows-win-pred25.eps
set nokey
set xrange [0:95]
set xlabel "algorithms, sorted as per Figure 5"
set ylabel "percentage of wins"
plot "rows.dat" with lines
EOF
epstopdf rows-win-pred25.eps

gnuplot<<EOF
set size 0.5,0.5
set terminal postscript eps color enhanced "Helvetica" 12
set output "cols-win-pred25.eps
set xtics rotate by -60 ("telecom" 1,"kemerer" 2,"cocomo81o" 3, "desharnaisL1" 4, "cocomo81s" 5, "desharnaisL3" 6, "albrecht" 7, "cocomo81e" 8, "nasa93_{center5}" 9, "desharnaaisL2" 10, "desharnais" 11, "maxwell" 12, "sdr" 13, "nasa93_{center1}" 14, "miyazaki94" 15, "nasa93_{center2}" 16, "finnish" 17, "cocomo81" 18, "nasa93" 19, "china" 20)
set nokey
set arrow 1 from 11,0 to 11,15 nohead ls 0
set arrow 2 from 0,15 to 11,15 nohead ls 0
## set title "total number of losses"
set ylabel "percentage of wins"
set xrange [0:21]
plot "cols.dat" using 1:3 with lines
EOF
epstopdf cols-win-pred25.eps
