#!/usr/bin/gawk -f #/* vim: set filteype=awk : */ -*- awk -*- BEGIN { Decimals = 3 Got = 1 Want = 2; Prefix = ""; True = "true"; ## define symbol 1 A=B=C=D=0 ; FS=OFS="," GoalPd = 1; GoalPf = 0; } function yes(s) {return s ~ True } function no(s) {return ( yes(s) ? 0 : 1 ) } { sub(/#.*/,"") } /^[ \t]*$/ { next } NF==2 { N++; Predicted=$Got; Actual=$Want; if (Predicted == Actual) Good++; if (no( Actual) && no( Predicted)) A++; if (yes(Actual) && no( Predicted)) B++; if (no( Actual) && yes(Predicted)) C++; if (yes(Actual) && yes(Predicted)) D++; print N,$0,A,B,C,D } END { OFMT = "%." Decimals "f"; Balance=Precision=Accuracy=Pf=NotPf=Pd=0; if (C+D > 0 ) Precision = D/(C+D); if ((A+B+C+D) > 0) Accuracy = (A+D)/(A+B+C+D); if (A+C > 0 ) Pf = C/(A+C) if (B+D > 0 ) Pd = D/(B+D); if (B+C+D > 0) { # special case- everything misses Balance = 1 - sqrt((GoalPd - Pd)^2 + (GoalPf - Pf)^2)/sqrt(2)} if(Prefix) printf Txt=Prefix OFS; print A,B,C,D, sprintf(OFMT,100*Accuracy), sprintf(OFMT,100*Pd), sprintf(OFMT,100*Pf), sprintf(OFMT,100*Precision), sprintf(OFMT,100*Balance); }