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,3,3,3,3,3,3,3,3,3,3,34,31,4,4,4,9,4,34,4,4,3,3,5,9,1,49,49,9,9,0,0,0,0,0,7,0,9,9,9,9,9,0,0,1,1,6,5,6,3,5,0,3,4,4,2,4,1,0,1,0,0,41,7,0,3,3,3,5,5,0,4,5,2,42,6,0,1,0,2,1,2,24,0,0,0,0,0,0,3,0
kemerer,0,0,0,0,0,0,39,39,28,28,9,0,35,9,0,1,0,0,0,0,3,3,23,1,0,0,0,0,0,0,0,15,15,33,0,33,1,0,5,0,0,34,22,1,1,2,15,2,0,0,0,25,25,26,1,13,68,1,1,0,0,10,0,1,0,0,0,0,0,2,2,5,2,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0
cocomo81o,9,9,9,9,9,9,7,7,7,7,32,7,36,29,35,17,35,11,7,7,64,64,57,13,22,9,9,16,31,20,20,9,9,68,125,68,6,9,50,6,6,54,7,20,20,7,45,7,7,6,6,18,7,55,34,7,9,6,43,41,41,9,13,31,7,10,54,55,6,9,16,21,35,30,5,23,10,30,54,51,22,6,7,7,7,7,7,7,6,3
cocomo81s,38,38,38,38,38,38,38,38,13,13,277,436,69,60,6,47,6,25,9,8,14,14,37,47,7,154,153,10,10,5,5,38,38,37,4,35,20,7,38,28,27,33,67,38,38,242,38,242,11,214,4,37,8,9,194,7,7,3,143,38,38,133,65,14,17,5,3,8,120,7,4,9,9,2,2,8,17,5,8,63,3,12,8,7,8,7,8,8,4,43
desharnaisL1,43,43,43,43,43,43,84,84,43,43,77,70,128,31,70,91,70,46,71,71,7,7,71,91,70,7,7,88,115,10,10,7,7,72,32,72,91,91,108,76,76,93,30,105,105,37,7,37,7,28,7,37,55,30,7,86,140,7,6,10,10,7,7,7,7,30,7,7,8,28,85,41,62,7,7,28,7,7,8,7,9,5,5,5,5,5,5,5,8,6
desharnaisL3,25,25,25,25,25,25,25,25,25,25,56,82,88,88,41,33,41,63,45,45,25,25,54,33,46,39,39,36,36,25,25,25,25,221,39,221,29,28,90,27,23,45,39,25,25,54,175,54,48,44,404,72,132,40,49,160,48,404,74,25,25,35,37,32,53,60,40,16,28,76,60,56,69,13,16,30,2,15,25,2,28,5,25,25,25,25,25,25,1,44
albrecht,60,60,60,60,60,60,82,82,88,88,79,122,77,66,50,67,50,65,55,55,84,84,86,67,53,101,101,58,48,64,64,71,71,70,36,70,38,38,111,35,35,51,35,35,35,168,83,168,57,49,36,71,146,38,65,169,9,48,1,2,2,9,51,91,6,2,2,107,34,88,51,87,0,6,0,5,63,0,0,0,2,3,0,0,0,0,0,0,0,0
cocomo81e,121,121,148,148,148,148,259,259,16,16,96,169,155,116,70,59,70,26,34,32,82,82,168,59,12,81,79,4,5,14,14,50,50,98,3,91,48,38,95,37,37,273,49,3,3,107,91,107,34,119,12,87,22,17,141,107,41,8,193,20,20,47,7,9,16,30,15,7,82,12,14,20,8,17,1,18,4,11,1,7,10,12,22,22,21,19,19,21,15,15
nasa93_{center5},167,167,167,167,167,167,149,149,186,186,156,196,257,49,110,47,110,147,113,113,151,151,48,47,109,44,44,47,48,2,2,66,66,69,89,69,47,47,48,47,47,18,71,81,81,7,64,7,66,18,89,69,7,9,53,7,9,24,14,29,29,107,10,1,99,13,14,0,12,2,11,5,12,3,12,10,9,3,4,4,2,1,6,6,6,6,6,6,2,11
desharnaisL2,147,147,147,147,147,147,55,55,55,55,54,42,95,73,82,139,82,61,88,88,84,84,55,139,193,54,54,177,177,80,80,58,58,55,96,55,139,129,75,106,106,42,43,61,61,74,56,74,55,45,98,50,97,109,2,97,191,99,45,2,2,0,79,104,98,66,60,89,22,80,81,109,39,25,51,28,49,24,7,45,43,0,2,2,2,2,3,3,1,2
desharnais,125,125,124,124,124,124,248,248,281,281,113,49,208,208,92,99,92,216,93,93,21,21,49,99,130,32,32,99,99,210,210,76,76,87,91,87,143,143,43,111,111,53,85,80,80,50,43,50,53,76,92,58,97,61,16,97,101,82,15,20,20,31,75,39,58,81,57,76,9,45,26,8,63,31,8,31,39,32,47,37,31,43,19,19,19,19,19,19,9,4
maxwell,220,220,220,220,220,220,220,220,220,220,154,163,155,134,135,159,135,122,158,153,220,220,7,159,177,126,126,161,162,8,8,220,220,63,119,63,159,159,63,153,153,7,66,220,220,150,52,150,175,68,62,52,150,86,46,150,173,62,9,220,220,46,141,136,100,120,34,95,68,3,3,3,2,6,41,3,143,16,5,13,18,7,6,6,6,6,6,6,3,0
nasa93_{center1},156,156,156,156,123,123,161,161,268,268,109,228,280,325,42,46,42,174,47,45,105,105,285,40,99,181,181,76,76,228,228,49,49,203,51,203,50,63,150,45,44,312,218,49,49,30,225,29,164,154,21,170,30,28,84,30,291,38,46,228,228,181,29,36,30,37,88,20,215,27,25,26,32,37,45,34,28,45,63,23,69,83,28,29,29,28,29,29,79,95
sdr,123,123,123,123,123,123,205,205,149,149,157,105,376,28,408,259,408,25,384,384,150,150,107,302,220,18,18,349,385,120,120,28,28,65,80,65,274,142,49,36,35,39,13,18,18,97,78,96,18,27,38,34,94,36,68,94,201,26,17,68,68,11,48,93,27,35,34,60,23,39,12,12,29,81,5,17,11,33,40,4,37,9,22,22,22,18,18,20,14,10
finnish,498,498,498,498,498,498,498,498,69,69,521,113,168,101,132,86,132,112,121,121,70,70,119,86,67,110,110,124,132,472,472,477,477,76,77,76,86,76,46,86,86,72,75,113,113,12,69,12,63,133,90,101,12,88,122,12,14,75,109,199,199,73,107,100,75,86,83,94,74,83,37,64,71,111,45,89,68,105,106,115,86,13,12,12,12,11,12,12,16,0
miyazaki94,340,340,340,340,323,323,376,376,135,135,420,153,263,138,221,205,221,99,218,218,174,174,286,208,74,176,176,94,94,156,156,173,173,244,167,243,190,94,406,186,186,219,115,181,181,91,119,90,147,87,170,102,158,151,116,138,213,125,147,55,55,98,193,106,7,31,10,108,35,96,108,104,28,18,9,30,5,18,12,13,14,16,25,23,24,25,23,25,27,77
nasa93_center_2,418,418,418,418,418,418,378,378,293,293,423,494,116,460,162,220,162,329,165,165,286,286,76,103,415,359,359,181,181,145,145,80,80,79,196,76,294,181,95,260,260,65,73,32,32,35,50,35,81,37,289,66,35,126,96,35,113,279,91,149,149,237,34,69,71,40,46,42,19,27,26,33,17,25,25,10,47,17,32,35,26,16,24,24,24,24,24,24,17,17
cocomo81,343,343,342,342,343,343,407,407,384,384,358,415,307,308,185,242,183,327,277,271,280,280,259,90,212,232,231,169,219,381,381,254,254,261,71,254,29,251,243,29,26,304,303,203,203,189,276,187,34,246,28,256,189,32,248,189,199,29,209,238,238,252,98,35,20,24,18,30,291,30,51,29,20,22,22,59,17,26,13,15,12,21,27,27,27,26,27,27,27,11
nasa93,441,441,441,441,441,441,469,469,490,490,562,490,475,182,109,159,109,409,118,118,406,406,211,164,449,244,244,153,155,466,466,142,142,164,97,159,93,92,205,92,92,233,191,61,61,58,176,58,69,26,169,161,58,32,223,58,79,262,125,141,141,206,22,22,49,29,27,11,35,12,24,26,12,59,12,8,86,13,36,56,35,39,31,31,31,31,31,32,14,28
china,554,554,554,554,552,552,544,544,544,544,347,315,329,431,465,463,465,432,465,465,628,628,341,463,505,311,311,473,474,406,406,220,220,313,434,313,440,541,315,443,443,292,300,103,103,273,121,273,219,141,439,168,303,264,278,280,442,440,271,301,301,292,103,217,110,59,54,103,124,55,89,36,88,86,100,52,220,83,80,58,86,76,25,23,23,23,23,23,72,20
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*7*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*7*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-all.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-all.eps

gnuplot<<EOF
set size 0.5,0.5
set terminal postscript eps color enhanced "Helvetica" 12
set output "cols-win-all.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-all.eps

