MCPcopy Create free account
hub / github.com/biometrics/openbr / EvalRegression

Function EvalRegression

openbr/core/eval.cpp:1250–1303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1248}
1249
1250void EvalRegression(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty, QString truthProperty)
1251{
1252 qDebug("Evaluating regression of %s against %s", qPrintable(predictedGallery), qPrintable(truthGallery));
1253
1254 if (predictedProperty.isEmpty())
1255 predictedProperty = "Regressor";
1256 // If predictedProperty is specified, but truthProperty isn't, copy the value over
1257 // rather than using the default for truthProperty
1258 else if (truthProperty.isEmpty())
1259 truthProperty = predictedProperty;
1260
1261 if (truthProperty.isEmpty())
1262 predictedProperty = "Regressand";
1263
1264 const TemplateList predicted(TemplateList::fromGallery(predictedGallery));
1265 const TemplateList truth(TemplateList::fromGallery(truthGallery));
1266 if (predicted.size() != truth.size()) qFatal("Input size mismatch.");
1267
1268 float rmsError = 0;
1269 float maeError = 0;
1270 QStringList truthValues, predictedValues;
1271 for (int i=0; i<predicted.size(); i++) {
1272 if (predicted[i].file.name != truth[i].file.name)
1273 qFatal("Input order mismatch.");
1274
1275 if (predicted[i].file.contains(predictedProperty) && truth[i].file.contains(truthProperty)) {
1276 float difference = predicted[i].file.get<float>(predictedProperty) - truth[i].file.get<float>(truthProperty);
1277
1278 rmsError += pow(difference, 2.f);
1279 maeError += fabsf(difference);
1280 truthValues.append(QString::number(truth[i].file.get<float>(truthProperty)));
1281 predictedValues.append(QString::number(predicted[i].file.get<float>(predictedProperty)));
1282 }
1283 }
1284
1285 QStringList rSource;
1286 rSource << "# Load libraries" << "library(ggplot2)" << "" << "# Set Data"
1287 << "Actual <- c(" + truthValues.join(",") + ")"
1288 << "Predicted <- c(" + predictedValues.join(",") + ")"
1289 << "data <- data.frame(Actual, Predicted)"
1290 << "" << "# Construct Plot" << "pdf(\"EvalRegression.pdf\")"
1291 << "print(qplot(Actual, Predicted, data=data, geom=\"jitter\", alpha=I(2/3)) + geom_abline(intercept=0, slope=1, color=\"forestgreen\", size=I(1)) + geom_smooth(size=I(1), color=\"mediumblue\") + theme_bw())"
1292 << "print(qplot(Actual, Predicted-Actual, data=data, geom=\"jitter\", alpha=I(2/3)) + geom_abline(intercept=0, slope=0, color=\"forestgreen\", size=I(1)) + geom_smooth(size=I(1), color=\"mediumblue\") + theme_bw())"
1293 << "dev.off()";
1294
1295
1296 QString rFile = "EvalRegression.R";
1297 QtUtils::writeFile(rFile, rSource);
1298 bool success = QtUtils::runRScript(rFile);
1299 if (success) QtUtils::showFile("EvalRegression.pdf");
1300
1301 qDebug("RMS Error = %f", sqrt(rmsError/predicted.size()));
1302 qDebug("MAE = %f", maeError/predicted.size());
1303}
1304
1305void readKNN(size_t &probeCount, size_t &k, QVector<Candidate> &neighbors, const QString &fileName)
1306{

Callers 1

br_eval_regressionFunction · 0.85

Calls 9

writeFileFunction · 0.85
runRScriptFunction · 0.85
showFileFunction · 0.85
isEmptyMethod · 0.80
powFunction · 0.50
sqrtFunction · 0.50
sizeMethod · 0.45
containsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected