#!/usr/bin/gawk -f BEGIN { FS = OFS = ","; IGNORECASE = 1; Criteria = "AR"; } NF==10 { Results[0,0]= 0; key = $3 "|" $4 "|" $5 "|" $6 "|" $9; Prediction = $(NF-1); Actual = $(NF); if (Actual == 0) Actual = 10^(-20); if (Prediction == 0) Prediction = 10^(-20); if (Actual == "inf") Actual = 10^(20); if (Prediction == "inf") Prediction = 10^(20); Performance = ""; if (Criteria == "AR") { AR = (Actual - Prediction); AR = (AR < 0 ? -1*AR : AR); Performance = AR; } else if (Criteria == "MRE") { MRE = (Actual - Prediction) / Actual; MRE = (MRE < 0 ? -1*MRE : MRE); } else if (Criteria == "MER") { MER = (Actual - Prediction) / Prediction; MER = (MER < 0 ? -1*MER : MER); Performance = MER; } else if (Criteria == "BRE") { if (Prediction - Actual >= 0) BRE = (Prediction - Actual) / Actual; else BRE = (Prediction - Actual) / Prediction; Performance = BRE; } else if (Criteria == "IBRE") { if (Prediction - Actual < 0) IBRE = (Prediction - Actual) / Actual; else IBRE = (Prediction - Actual) / Prediction; Performance = IBRE; } PerformanceArray[key,++PerformanceArray[key,0]] = Performance; N[key]++; } END { print "Key,Median("Criteria")%,33%,66%,100%,spread(33%<->66%),spread(66%<->100%)"; for(key in N) { findResults(key); split(key,parsedKey,FS); print key,Results[key,1],Results[key,2],Results[key,3],Results[key,4],Results[key,3]-Results[key,2],Results[key,4]-Results[key,3]; } } function findResults(key) { for (counter=1; counter<=PerformanceArray[key,0]; counter++) tempArray[counter]=PerformanceArray[key,counter]; asort(tempArray); #This calculates the median if (PerformanceArray[key,0]%2 == 0) Results[key,1] = (tempArray[PerformanceArray[key,0]/2]+tempArray[(PerformanceArray[key,0]+2)/2])/2 * 100; else Results[key,1] = tempArray[(PerformanceArray[key,0]+1)/2] * 100; #This finds the 33 percentile Results[key,2] = tempArray[int(PerformanceArray[key,0]/3)] * 100; #This finds the 66 percentile Results[key,3] = tempArray[int(2*PerformanceArray[key,0]/3)] * 100; #This finds the 100 percentile Results[key,4] = tempArray[PerformanceArray[key,0]] * 100; }