BEGIN { FS="," SUBSEP = "." Col1 = ( Col1 ? Col1 : 5 ) #1st Column sorting Col2 = ( Col2 ? Col2 : 1 ) #2nd Column sorting } { m = split($1,tmp,".") goal = tmp[4]" "tmp[1] # goal = tmp[1] type = tmp[2] id = "" for (i=3; i<=m; i++) { id = (id ? id"."tmp[i] : tmp[i]) } Appeared[goal,type,id]++ if (type ~ "ASIS") A2B[goal,"ASIS",id] = goal SUBSEP "TOBE" SUBSEP id # if (type ~ "TOBE") # Tobe2Asis[goal,"TOBE",id] = goal,"ASIS",id #Store the median reductions for each run if (type ~ "ASIS") { split("",Was,"") for (i=2; i<=NF; i++) Was[++Was["size"]]=$i } else { split("",Is,"") for (i=2; i<=NF; i++) Is[++Is["size"]]=$i Reductions[goal,id,++Reductions[goal,id,"size"]] = 100 * (findMedian(Was) - findMedian(Is)) / findMedian(Was) if ($2 == "") Reductions[goal,id,++Reductions[goal,id,"size"]] = 0 ++Olds[goal,id,"size"] ++News[goal,id,"size"] for (i=1; i<=Was["size"]; i++) { if (Olds[goal,id,Olds[goal,id,"size"]]) Olds[goal,id,Olds[goal,id,"size"]] = Olds[goal,id,Olds[goal,id,"size"]]","Was[i] else Olds[goal,id,Olds[goal,id,"size"]] = Was[i] } for (i=1; i<=Is["size"]; i++) { if (News[goal,id,News[goal,id,"size"]]) News[goal,id,News[goal,id,"size"]] = News[goal,id,News[goal,id,"size"]]","Is[i] else News[goal,id,Reductions[goal,id,"size"]] = Is[i] } # print "Reduction: "id"::"goal"::"Reductions[goal,id,Reductions[goal,id,"size"]] } #--------------------------------------- for (i=2; i<=NF; i++) { Data[goal,type,id,++Data[goal,type,id,"size"]] = $i } } function printMedians() { for (key in Appeared) { multi2single(key,Data,single) print key": "findMedian(single) } } function printAvgAndStd( ) { com="sort -k 2 -n -r" print "Average Reductions:" for (key in A2B) { multi2single(key,Data,asis) multi2single(A2B[key],Data,tobe) sub(".ASIS","",key) printf"%40s %4.2f \% (%g -> %g)\n",key, 100 * (findAvg(asis) - findAvg(tobe)) / findAvg(asis), findAvg(asis), findAvg(tobe) | com } close(com) print "" print "Standard Deviation Reductions:" for (key in A2B) { multi2single(key,Data,asis) multi2single(A2B[key],Data,tobe) sub(".ASIS","",key) printf "%40s: %4.2f\% (%g -> %g)\n",key, 100 * (findStdev(asis) - findStdev(tobe)) / findStdev(asis), findStdev(asis), findStdev(tobe) | com } close(com) print "" } function printTexHeader() { system("cat tex/header.tex") } function printMedianResults( asis,tobe,key,q25,q50,q75,m,sortedAsis,sortedTobe,reduc) { com="sort -b -k "Col1".1b,"Col1".2b -k "Col2".1,"Col2".2 -k 7nr" # com = "sort -b -k 3.1,3.2 -k 5" printTexHeader() print "{\\scriptsize" # print "\\begin{tabular}{ l | c | c | r@{}c@{}l r@{}c@{}l r@{}c@{}l |@{} c }" # print " & Median & Spread & \\multicolumn{9}{c}{Average Reductions (Before \\arrow After)}\\\\" # print "Treatment& Reduction & Reduction & & 25\\% & & & 50\\% & & & 75\\% & & Reduced Quartiles \\\\\\hline" print "\\begin{tabular}{|c| r | r | @{}c@{} | @{}c@{} | @{}c |}\\hline" print " & & & Median & Spread & Reduction Quartiles \\\\" print " Rank & Goal & Treatment & Reduc & Reduc & 50\\% \\\\\\hline" #---sort keys for ranking #store inside keyOrder based on median reduction, grouped by goal for (key in A2B) { #get all goals split(key,tmp,".") goals[tmp[1]] = 1 } m = asorti(goals) for (goal in goals) { split("",goalMedians,"") for (treatment in A2B) { split(treatment,tmp,".") if (tmp[1] ~ goals[goal]) { treatmentCopy = treatment sub(".ASIS","",treatmentCopy) multi2single(treatmentCopy,Reductions,reduc) median2 = findMedian(reduc) + (0.0001 * rand()) goalMedians[treatment] = median2 medianToTreatment[median2] = treatment } } m = asort(goalMedians) for (i=m; i>0; i--) { tOrder[++tOrder[0]] = medianToTreatment[goalMedians[i]] # print "ORDER: "tOrder[tOrder[0]] } } rank = 0 goal = "" oldGoal = "" #print stats for each ranking for (i=1; i<=tOrder[0]; i++) { key = tOrder[i] multi2single(key,Data,asis) multi2single(A2B[key],Data,tobe) sub(".ASIS","",key) multi2single(key,Reductions,reduc) multi2single(key,Olds,old) multi2single(key,News,new) split(key,tmp,".") goal = tmp[1] #Different than last treatment?? if (rank == 0 || goal != oldGoal) { rank = 1 split("",previous,"") for (r in reduc) { previous[r] = reduc[r] } } else { if (mwu(1,reduc,previous,"up",criticalValue(90))) rank++ split("",previous,"") for (r in reduc) { previous[r] = reduc[r] } } oldGoal = goal # for (kkey in reduc) # print kkey"::"reduc[kkey] treatment = key sub("[.]"," \\& ",treatment) # if (rank == 1) printf "\\rowcolor[rgb]{0.9,0.9,0.9}" printf "%d & %30s & %4.0f\\% & %4.0f\\% & ",rank,treatment,findMedian(reduc),findSpread(reduc)# | com q25 = clamp0to100(find25(reduc)) q50 = clamp0to100(findMedian(reduc)) q75 = clamp0to100(find75(reduc)) printf "\\boxplot{"q25"}{"q50-q25"}{"q50"}{"q75-q50"}{"q75"}"# | com # if (key ~ "score") # printf "%2.1f & \\arrow & %3.1f &",100 * findAvg(asis),100 * findAvg(tobe)# | com # else # printf "%2.1f & \\arrow & %2.1f &",findAvg(asis),findAvg(tobe)# | com # if (key ~ "score") # printf "%2.1f & \\arrow & %3.1f",100 * findStdev(asis),100 * findStdev(tobe)# | com # else # printf "%2.1f & \\arrow & %2.1f",findStdev(asis),findStdev(tobe)# | com xx = split(treatment,tmmmp,".") print tmmmp[1]","tmmmp[xx]","findMedian(asis)","findSpread(asis)","findMedian(tobe)","findSpread(tobe)","(findMedian(asis) - findMedian(tobe)) / findMedian(asis) * 100","(findSpread(asis) - findSpread(tobe)) / findSpread(asis) * 100")" > "woutt.csv" split(tOrder[i+1],tmp,".") nextGoal = tmp[1] if (nextGoal ~ goal) printf "\\\\ \n"# | com else printf "\\\\\\hline \n" } # close(com) print "" print "\\end{tabular}}" print "\\end{document}" } function clamp0to100(r) { r = (r < 0 ? 0 : r) r = (r > 100 ? 100 : r) return r } function quart25(asis, tobe, r) { r = 100 * (find25(asis) - find25(tobe)) / find25(asis) r = (r < 0 ? 0 : r) r = (r > 100 ? 100 : r) return r } function quartMedian(asis, tobe, r) { r = 100 * (findMedian(asis) - findMedian(tobe)) / findMedian(asis) r = (r < 0 ? 0 : r) r = (r > 100 ? 100 : r) return r } function quart75(asis, tobe, r) { r = 100 * (find75(asis) - find75(tobe)) / find75(asis) r = (r < 0 ? 0 : r) r = (r > 100 ? 100 : r) return r } #function printMedianReductions( asis,tobe,key) { # com="sort -k 2 -n -r" # print "Median Reductions:" # for (key in A2B) { # multi2single(key,Data,asis) # multi2single(A2B[key],Data,tobe) # sub(".ASIS","",key) # printf "%40s: %4.2f\% (%g -> %g)\n",key, medianReduc(asis,tobe), findMedian(asis), findMedian(tobe) | com # } # close(com) # print "" # print "Spread Reductions:" # for (key in A2B) { # multi2single(key,Data,asis) # multi2single(A2B[key],Data,tobe) # sub(".ASIS","",key) # printf "%40s: %4.2f\% (%g -> %g)\n",key, spreadReduc(asis,tobe), findSpread(asis), findSpread(tobe) | com # } # close(com) # print "" #} function multi2single(key,inarr,outarr, i) { split("",outarr,"") for (i=1; i<=inarr[key,"size"]; i++) outarr[i]=inarr[key,i] asort(outarr) } function printAll() { for (key in Appeared) { printf key": " for (i=1; i<=Data[key,"size"]; i++) { printf Data[key,i]"," } print "" } } END { # printMedians() # printMedianReductions() # printAvgAndStd() printMedianResults() }