Commit 4f43a6d38c5ce9f3a2bdc6859564176f7eae54a7
1 parent
ff98581b
updated CMC plot
Showing
1 changed file
with
18 additions
and
15 deletions
openbr/core/plot.cpp
| @@ -254,20 +254,22 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv) | @@ -254,20 +254,22 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv) | ||
| 254 | lines.append(QString("KDEImpostor,%1,%2").arg(QString::number(f), QString::number(Common::KernelDensityEstimation(sampledImpostorScores, f, hImpostor)))); | 254 | lines.append(QString("KDEImpostor,%1,%2").arg(QString::number(f), QString::number(Common::KernelDensityEstimation(sampledImpostorScores, f, hImpostor)))); |
| 255 | 255 | ||
| 256 | // Write Cumulative Match Characteristic (CMC) curve | 256 | // Write Cumulative Match Characteristic (CMC) curve |
| 257 | - const int Max_Retrieval = 25; | ||
| 258 | - float maxRankRate; | 257 | + const int Max_Retrieval = 100; |
| 258 | + const int Report_Retrieval = 5; | ||
| 259 | + float reportRetrievalRate = -1; | ||
| 259 | for (int i=1; i<=Max_Retrieval; i++) { | 260 | for (int i=1; i<=Max_Retrieval; i++) { |
| 260 | int realizedReturns = 0, possibleReturns = 0; | 261 | int realizedReturns = 0, possibleReturns = 0; |
| 261 | foreach (int firstGenuineReturn, firstGenuineReturns) { | 262 | foreach (int firstGenuineReturn, firstGenuineReturns) { |
| 262 | if (firstGenuineReturn > 0) possibleReturns++; | 263 | if (firstGenuineReturn > 0) possibleReturns++; |
| 263 | if (firstGenuineReturn <= i) realizedReturns++; | 264 | if (firstGenuineReturn <= i) realizedReturns++; |
| 264 | } | 265 | } |
| 265 | - lines.append(qPrintable(QString("CMC,%1,%2").arg(QString::number(i), QString::number(float(realizedReturns)/possibleReturns)))); | ||
| 266 | - if (i==(Max_Retrieval)) maxRankRate = float(realizedReturns)/possibleReturns; | 266 | + const float retrievalRate = float(realizedReturns)/possibleReturns; |
| 267 | + lines.append(qPrintable(QString("CMC,%1,%2").arg(QString::number(i), QString::number(retrievalRate)))); | ||
| 268 | + if (i == Report_Retrieval) reportRetrievalRate = retrievalRate; | ||
| 267 | } | 269 | } |
| 268 | 270 | ||
| 269 | if (!csv.isEmpty()) QtUtils::writeFile(csv, lines); | 271 | if (!csv.isEmpty()) QtUtils::writeFile(csv, lines); |
| 270 | - qDebug("TAR @ FAR = 0.01: %.3f\nRetrieval Rate at Rank 25: %.3f", result, maxRankRate); | 272 | + qDebug("TAR @ FAR = 0.01: %.3f\nRetrieval Rate @ Rank = %d: %.3f", result, Report_Retrieval, reportRetrievalRate); |
| 271 | return result; | 273 | return result; |
| 272 | } | 274 | } |
| 273 | 275 | ||
| @@ -471,7 +473,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | @@ -471,7 +473,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | ||
| 471 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + | 473 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + |
| 472 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + | 474 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + |
| 473 | QString(" + scale_x_log10(labels=percent) + scale_y_continuous(labels=percent) + annotation_logticks(sides=\"b\")") + | 475 | QString(" + scale_x_log10(labels=percent) + scale_y_continuous(labels=percent) + annotation_logticks(sides=\"b\")") + |
| 474 | - QString("\nggsave(\"%1\")\n").arg(p.subfile("ROC")))); | 476 | + QString("\nggsave(\"%1\")\n\n").arg(p.subfile("ROC")))); |
| 475 | 477 | ||
| 476 | p.file.write(qPrintable(QString("qplot(X, Y, data=DET%1").arg((p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") + | 478 | p.file.write(qPrintable(QString("qplot(X, Y, data=DET%1").arg((p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") + |
| 477 | (p.major.size > 1 ? QString(", colour=factor(%1)").arg(p.major.header) : QString()) + | 479 | (p.major.size > 1 ? QString(", colour=factor(%1)").arg(p.major.header) : QString()) + |
| @@ -480,7 +482,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | @@ -480,7 +482,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | ||
| 480 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + | 482 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + |
| 481 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + | 483 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + |
| 482 | QString(" + scale_x_log10(labels=percent) + scale_y_log10(labels=percent) + annotation_logticks()") + | 484 | QString(" + scale_x_log10(labels=percent) + scale_y_log10(labels=percent) + annotation_logticks()") + |
| 483 | - QString("\nggsave(\"%1\")\n").arg(p.subfile("DET")))); | 485 | + QString("\nggsave(\"%1\")\n\n").arg(p.subfile("DET")))); |
| 484 | 486 | ||
| 485 | p.file.write(qPrintable(QString("qplot(X, data=SD, geom=\"histogram\", fill=Y, position=\"identity\", alpha=I(1/2)") + | 487 | p.file.write(qPrintable(QString("qplot(X, data=SD, geom=\"histogram\", fill=Y, position=\"identity\", alpha=I(1/2)") + |
| 486 | QString(", xlab=\"Score%1\"").arg((p.flip ? p.major.size : p.minor.size) > 1 ? " / " + (p.flip ? p.major.header : p.minor.header) : QString()) + | 488 | QString(", xlab=\"Score%1\"").arg((p.flip ? p.major.size : p.minor.size) > 1 ? " / " + (p.flip ? p.major.header : p.minor.header) : QString()) + |
| @@ -488,16 +490,17 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | @@ -488,16 +490,17 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | ||
| 488 | QString(") + scale_fill_manual(\"Ground Truth\", values=c(\"blue\", \"red\")) + theme_minimal() + scale_x_continuous(minor_breaks=NULL) + scale_y_continuous(minor_breaks=NULL) + theme(axis.text.y=element_blank(), axis.ticks=element_blank(), axis.text.x=element_text(angle=-90, hjust=0))") + | 490 | QString(") + scale_fill_manual(\"Ground Truth\", values=c(\"blue\", \"red\")) + theme_minimal() + scale_x_continuous(minor_breaks=NULL) + scale_y_continuous(minor_breaks=NULL) + theme(axis.text.y=element_blank(), axis.ticks=element_blank(), axis.text.x=element_text(angle=-90, hjust=0))") + |
| 489 | (p.major.size > 1 ? (p.minor.size > 1 ? QString(" + facet_grid(%2 ~ %1, scales=\"free\")").arg((p.flip ? p.major.header : p.minor.header), (p.flip ? p.minor.header : p.major.header)) : QString(" + facet_wrap(~ %1, scales = \"free\")").arg(p.major.header)) : QString()) + | 491 | (p.major.size > 1 ? (p.minor.size > 1 ? QString(" + facet_grid(%2 ~ %1, scales=\"free\")").arg((p.flip ? p.major.header : p.minor.header), (p.flip ? p.minor.header : p.major.header)) : QString(" + facet_wrap(~ %1, scales = \"free\")").arg(p.major.header)) : QString()) + |
| 490 | QString(" + theme(aspect.ratio=1)") + | 492 | QString(" + theme(aspect.ratio=1)") + |
| 491 | - QString("\nggsave(\"%1\")\n").arg(p.subfile("SD")))); | 493 | + QString("\nggsave(\"%1\")\n\n").arg(p.subfile("SD")))); |
| 492 | 494 | ||
| 493 | - p.file.write(qPrintable(QString("qplot(X, Y, data=CMC%1, xlab=\"Rank\", ylab=\"Retrieval Rate\"").arg((p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") + | ||
| 494 | - (p.major.size > 1 ? QString(", colour=factor(%1)").arg(p.major.header) : QString()) + | ||
| 495 | - (p.minor.size > 1 ? QString(", linetype=factor(%1)").arg(p.minor.header) : QString()) + | ||
| 496 | - QString(") + theme_minimal() + scale_x_continuous(limits = c(1,25), breaks = c(1,5,10,25))") + | 495 | + p.file.write(qPrintable(QString("ggplot(CMC, aes(x=X, y=Y)) + xlab(\"Rank\") + ylab(\"Retrieval Rate\")") + |
| 496 | + ((p.major.smooth || p.minor.smooth) ? QString(" + stat_summary(geom=\"line\", fun.y=min, aes(linetype=\"Min/Max\")) + stat_summary(geom=\"line\", fun.y=max, aes(linetype=\"Min/Max\")) + stat_summary(geom=\"line\", fun.y=mean, aes(linetype=\"Mean\")) + scale_linetype_manual(\"Legend\", values=c(\"Mean\"=1, \"Min/Max\"=2))") | ||
| 497 | + : QString(" + geom_line(aes(%1))").arg((p.major.size > 1 ? QString("colour=factor(%1)").arg(p.major.header) : QString()) + | ||
| 498 | + (p.minor.size > 1 ? QString(", linetype=factor(%1)").arg(p.minor.header) : QString()))) + | ||
| 499 | + QString(" + theme_minimal() + scale_x_log10() + annotation_logticks(sides=\"b\")") + | ||
| 497 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + | 500 | (p.major.size > 1 ? getScale("colour", p.major.header, p.major.size) : QString()) + |
| 498 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + | 501 | (p.minor.size > 1 ? QString(" + scale_linetype_discrete(\"%1\")").arg(p.minor.header) : QString()) + |
| 499 | QString(" + scale_y_continuous(labels=percent)") + | 502 | QString(" + scale_y_continuous(labels=percent)") + |
| 500 | - QString("\nggsave(\"%1\")\n").arg(p.subfile("CMC")))); | 503 | + QString("\nggsave(\"%1\")\n\n").arg(p.subfile("CMC")))); |
| 501 | 504 | ||
| 502 | p.file.write(qPrintable(QString("qplot(factor(%1)%2, data=BC, %3").arg(p.major.smooth ? (p.minor.header.isEmpty() ? "Algorithm" : p.minor.header) : p.major.header, (p.major.smooth || p.minor.smooth) ? ", Y" : "", (p.major.smooth || p.minor.smooth) ? "geom=\"boxplot\"" : "geom=\"bar\", position=\"dodge\", weight=Y") + | 505 | p.file.write(qPrintable(QString("qplot(factor(%1)%2, data=BC, %3").arg(p.major.smooth ? (p.minor.header.isEmpty() ? "Algorithm" : p.minor.header) : p.major.header, (p.major.smooth || p.minor.smooth) ? ", Y" : "", (p.major.smooth || p.minor.smooth) ? "geom=\"boxplot\"" : "geom=\"bar\", position=\"dodge\", weight=Y") + |
| 503 | (p.major.size > 1 ? QString(", fill=factor(%1)").arg(p.major.header) : QString()) + | 506 | (p.major.size > 1 ? QString(", fill=factor(%1)").arg(p.major.header) : QString()) + |
| @@ -506,7 +509,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | @@ -506,7 +509,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | ||
| 506 | (p.major.size > 1 ? getScale("fill", p.major.header, p.major.size) : QString()) + | 509 | (p.major.size > 1 ? getScale("fill", p.major.header, p.major.size) : QString()) + |
| 507 | (p.minor.size > 1 ? QString(" + facet_grid(%2 ~ X)").arg(p.minor.header) : QString(" + facet_grid(. ~ X, labeller=far_labeller)")) + | 510 | (p.minor.size > 1 ? QString(" + facet_grid(%2 ~ X)").arg(p.minor.header) : QString(" + facet_grid(. ~ X, labeller=far_labeller)")) + |
| 508 | QString(" + scale_y_continuous(labels=percent) + theme(legend.position=\"none\", axis.text.x=element_text(angle=-90, hjust=0))%1").arg((p.major.smooth || p.minor.smooth) ? "" : " + geom_text(data=BC, aes(label=Y, y=0.05))") + | 511 | QString(" + scale_y_continuous(labels=percent) + theme(legend.position=\"none\", axis.text.x=element_text(angle=-90, hjust=0))%1").arg((p.major.smooth || p.minor.smooth) ? "" : " + geom_text(data=BC, aes(label=Y, y=0.05))") + |
| 509 | - QString("\nggsave(\"%1\")\n").arg(p.subfile("BC")))); | 512 | + QString("\nggsave(\"%1\")\n\n").arg(p.subfile("BC")))); |
| 510 | 513 | ||
| 511 | p.file.write(qPrintable(QString("qplot(X, Y, data=ERR%1, linetype=Error").arg((p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") + | 514 | p.file.write(qPrintable(QString("qplot(X, Y, data=ERR%1, linetype=Error").arg((p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") + |
| 512 | ((p.flip ? p.major.size : p.minor.size) > 1 ? QString(", colour=factor(%1)").arg(p.flip ? p.major.header : p.minor.header) : QString()) + | 515 | ((p.flip ? p.major.size : p.minor.size) > 1 ? QString(", colour=factor(%1)").arg(p.flip ? p.major.header : p.minor.header) : QString()) + |
| @@ -515,7 +518,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | @@ -515,7 +518,7 @@ bool Plot(const QStringList &files, const br::File &destination, bool show) | ||
| 515 | QString(" + scale_y_log10(labels=percent) + annotation_logticks(sides=\"l\")") + | 518 | QString(" + scale_y_log10(labels=percent) + annotation_logticks(sides=\"l\")") + |
| 516 | ((p.flip ? p.minor.size : p.major.size) > 1 ? QString(" + facet_wrap(~ %1, scales=\"free_x\")").arg(p.flip ? p.minor.header : p.major.header) : QString()) + | 519 | ((p.flip ? p.minor.size : p.major.size) > 1 ? QString(" + facet_wrap(~ %1, scales=\"free_x\")").arg(p.flip ? p.minor.header : p.major.header) : QString()) + |
| 517 | QString(" + theme(aspect.ratio=1)") + | 520 | QString(" + theme(aspect.ratio=1)") + |
| 518 | - QString("\nggsave(\"%1\")\n").arg(p.subfile("ERR")))); | 521 | + QString("\nggsave(\"%1\")\n\n").arg(p.subfile("ERR")))); |
| 519 | 522 | ||
| 520 | return p.finalize(show); | 523 | return p.finalize(show); |
| 521 | } | 524 | } |