From cbdb48ca080b09bf958b86aec1f29409b24efd37 Mon Sep 17 00:00:00 2001 From: Stephen Rawls Date: Wed, 21 Jan 2015 16:02:08 -0800 Subject: [PATCH] Adding a new table to the OpenBR report show FAR values at various fixed TAR values --- openbr/core/eval.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- openbr/core/plot.cpp | 14 ++++++++++++++ 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/openbr/core/eval.cpp b/openbr/core/eval.cpp index 1a7159a..5876538 100755 --- a/openbr/core/eval.cpp +++ b/openbr/core/eval.cpp @@ -53,7 +53,7 @@ struct OperatingPoint : score(_score), FAR(_FAR), TAR(_TAR) {} }; -static OperatingPoint getOperatingPoint(const QList &operatingPoints, float FAR) +static OperatingPoint getOperatingPointGivenFAR(const QList &operatingPoints, float FAR) { int index = 0; while (operatingPoints[index].FAR < FAR) { @@ -75,6 +75,32 @@ static OperatingPoint getOperatingPoint(const QList &operatingPo return OperatingPoint(mScore * FAR + bScore,FAR, mTAR * FAR + bTAR); } +static OperatingPoint getOperatingPointGivenTAR(const QList &operatingPoints, float TAR) +{ + int index = 0; + while (operatingPoints[index].TAR < TAR) { + index++; + if (index == operatingPoints.size()) + return OperatingPoint(operatingPoints.last().score, operatingPoints.last().FAR, TAR); + } + + + const float FAR1 = (index == 0 ? 0 : operatingPoints[index-1].FAR); + const float TAR1 = (index == 0 ? 0 : operatingPoints[index-1].TAR); + const float score1 = (index == 0 ? operatingPoints[index].score : operatingPoints[index-1].score); + const float FAR2 = operatingPoints[index].FAR; + const float TAR2 = operatingPoints[index].TAR; + const float score2 = operatingPoints[index].score; + const float mTAR = (TAR2 - TAR1) / (FAR2 - FAR1); + const float bTAR = TAR1 - mTAR*FAR1; + const float mScore = (score2 - score1) / (FAR2 - FAR1); + const float bScore = score1 - mScore*FAR1; + + const float FAR = (TAR - bTAR) / mTAR; + return OperatingPoint(mScore * FAR + bScore,FAR, TAR); +} + + static float getCMC(const QVector &firstGenuineReturns, int rank) { int realizedReturns = 0, possibleReturns = 0; @@ -231,6 +257,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QSt if ((falsePositives > previousFalsePositives) && (truePositives > previousTruePositives)) { operatingPoints.append(OperatingPoint(thresh, float(falsePositives)/impostorCount, float(truePositives)/genuineCount)); + if (EERIndex == 0) { if (floor(float(falsePositives)/impostorCount*100+0.5)/100 == floor((1-float(truePositives)/genuineCount)*100+0.5)/100) EERIndex = index-1; } @@ -277,7 +304,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QSt // Write Detection Error Tradeoff (DET), PRE, REC float FAR=0.000001; for (int i=0; i 0) qDebug("Template Size: %i bytes", (int)maxSize); - qDebug("TAR @ FAR = 0.01: %.3f",getOperatingPoint(operatingPoints, 0.01).TAR); - qDebug("TAR @ FAR = 0.001: %.3f",getOperatingPoint(operatingPoints, 0.001).TAR); - qDebug("TAR @ FAR = 0.0001: %.3f",getOperatingPoint(operatingPoints, 0.0001).TAR); - qDebug("TAR @ FAR = 0.00001: %.3f",getOperatingPoint(operatingPoints, 0.00001).TAR); + qDebug("TAR @ FAR = 0.01: %.3f",getOperatingPointGivenFAR(operatingPoints, 0.01).TAR); + qDebug("TAR @ FAR = 0.001: %.3f",getOperatingPointGivenFAR(operatingPoints, 0.001).TAR); + qDebug("TAR @ FAR = 0.0001: %.3f",getOperatingPointGivenFAR(operatingPoints, 0.0001).TAR); + qDebug("TAR @ FAR = 0.00001: %.3f",getOperatingPointGivenFAR(operatingPoints, 0.00001).TAR); qDebug("\nRetrieval Rate @ Rank = %d: %.3f", Report_Retrieval, getCMC(firstGenuineReturns, Report_Retrieval)); @@ -571,8 +606,8 @@ float InplaceEval(const QString &simmat, const QString &target, const QString &q float result; // Write FAR/TAR Bar Chart (BC) - lines.append(qPrintable(QString("BC,0.001,%1").arg(QString::number(getOperatingPoint(operatingPoints, 0.001).TAR, 'f', 3)))); - lines.append(qPrintable(QString("BC,0.01,%1").arg(QString::number(result = getOperatingPoint(operatingPoints, 0.01).TAR, 'f', 3)))); + lines.append(qPrintable(QString("BC,0.001,%1").arg(QString::number(getOperatingPointGivenFAR(operatingPoints, 0.001).TAR, 'f', 3)))); + lines.append(qPrintable(QString("BC,0.01,%1").arg(QString::number(result = getOperatingPointGivenFAR(operatingPoints, 0.01).TAR, 'f', 3)))); qDebug("TAR @ FAR = 0.01: %.3f", result); QtUtils::writeFile(csv, lines); diff --git a/openbr/core/plot.cpp b/openbr/core/plot.cpp index e4eb91f..aead994 100644 --- a/openbr/core/plot.cpp +++ b/openbr/core/plot.cpp @@ -161,6 +161,7 @@ struct RPlot "FRR <- data[grep(\"FRR\",data$Plot),-c(1)]\n" "SD <- data[grep(\"SD\",data$Plot),-c(1)]\n" "FT <- data[grep(\"FT\",data$Plot),-c(1)]\n" + "FatT <- data[grep(\"FatT\",data$Plot),-c(1)]\n" "CT <- data[grep(\"CT\",data$Plot),-c(1)]\n" "BC <- data[grep(\"BC\",data$Plot),-c(1)]\n" "TS <- data[grep(\"TS\",data$Plot),-c(1)]\n" @@ -178,6 +179,7 @@ struct RPlot "ERR$Y <- as.numeric(as.character(ERR$Y))\n" "SD$Y <- as.factor(unique(as.character(SD$Y)))\n" "FT$Y <- as.numeric(as.character(FT$Y))\n" + "FatT$Y <- as.numeric(as.character(FatT$Y))\n" "CT$Y <- as.numeric(as.character(CT$Y))\n" "BC$Y <- as.numeric(as.character(BC$Y))\n" "TS$Y <- as.character(TS$Y)\n" @@ -205,6 +207,16 @@ struct RPlot "rownames(mat) <- c(\"FAR = 1e-06\", \"FAR = 1e-05\", \"FAR = 1e-04\", \"FAR = 1e-03\", \"FAR = 1e-02\", \"FAR = 1e-01\")\n" "FTtable <- as.table(mat)\n" "\n" + "# Code to format TAR@FAR table\n" + "algs <- unique(FT$%2)\n" + "algs <- algs[!duplicated(algs)]\n" + "mat <- matrix(FatT$Y,nrow=6,ncol=length(algs),byrow=FALSE)\n" + "colnames(mat) <- algs \n" + "rownames(mat) <- c(\"TAR = 0.95\", \"TAR = 0.85\", \"TAR = 0.75\", \"TAR = 0.65\", \"TAR = 0.50\", \"TAR = 0.40\")\n" + "F_at_Ttable <- as.table(mat)\n" + "\n" + + "\n" "# Code to format CMC Table\n" "mat <- matrix(%4,nrow=6,ncol=length(algs),byrow=FALSE)\n" "colnames(mat) <- algs \n" @@ -249,6 +261,8 @@ struct RPlot "plot.new()\n" "print(textplot(FTtable))\n" "print(title(\"Table of True Accept Rates at various False Accept Rates\"))\n" + "print(textplot(F_at_Ttable))\n" + "print(title(\"Table of False Accept Rates at various True Accept Rates\"))\n" "print(textplot(CMCtable))\n" "print(title(\"Table of retrieval rate at various ranks\"))\n" "if (nrow(TS) != 0) {\n\t" -- libgit2 0.21.4