diff --git a/sdk/core/common.h b/sdk/core/common.h index c522cea..8c2f8c8 100644 --- a/sdk/core/common.h +++ b/sdk/core/common.h @@ -200,6 +200,33 @@ QList CumSum(const QList &vals) /**** +KernelDensityBandwidth + Calculate DKE bandwidth parameter 'h' +****/ +template +double KernelDensityBandwidth(const QList &vals) +{ + double mean, stddev; + MeanStdDev(vals, &mean, &stddev); + return pow(4 * pow(stddev, 5.0) / (3 * vals.size()), 0.2); +} + + +/**** +KernelDensityEstimation + Compute kernel density at value x with bandwidth h. +****/ +template +double KernelDensityEstimation(const QList &vals, double x, double h) +{ + double y = 0; + foreach (T val, vals) + y += exp(-pow((val-x)/h,2)/2)/sqrt(2*3.1415926353898); + return y / (vals.size() * h); +} + + +/**** RandSample Returns a vector of n integers sampled in the range &operatingPoints, float FAR) return m * FAR + b; } -static float kernelDensityBandwidth(const QList &vals) -{ - double mean, stddev; - Common::MeanStdDev(vals, &mean, &stddev); - return pow(4 * pow(stddev, 5.0) / (3 * vals.size()), 0.2); -} - -static float kernelDensityEstimation(const QList &vals, double x, double h) -{ - double y = 0; - foreach (double val, vals) - y += exp(-pow((val-x)/h,2)/2)/sqrt(2*CV_PI); - return y / (vals.size() * h); -} - float Evaluate(const QString &simmat, const QString &mask, const QString &csv) { qDebug("Evaluating %s with %s", qPrintable(simmat), qPrintable(mask)); @@ -237,13 +222,13 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv) sampledImpostorScores.append(impostorScore); } - const double hGenuine = kernelDensityBandwidth(sampledGenuineScores); + const double hGenuine = Common::KernelDensityBandwidth(sampledGenuineScores); foreach (double f, sampledGenuineScores) - lines.append(QString("KDEGenuine,%1,%2").arg(QString::number(f), QString::number(kernelDensityEstimation(sampledGenuineScores, f, hGenuine)))); + lines.append(QString("KDEGenuine,%1,%2").arg(QString::number(f), QString::number(Common::KernelDensityEstimation(sampledGenuineScores, f, hGenuine)))); - const double hImpostor = kernelDensityBandwidth(sampledImpostorScores); + const double hImpostor = Common::KernelDensityBandwidth(sampledImpostorScores); foreach (double f, sampledImpostorScores) - lines.append(QString("KDEImpostor,%1,%2").arg(QString::number(f), QString::number(kernelDensityEstimation(sampledImpostorScores, f, hImpostor)))); + lines.append(QString("KDEImpostor,%1,%2").arg(QString::number(f), QString::number(Common::KernelDensityEstimation(sampledImpostorScores, f, hImpostor)))); // Write Cumulative Match Characteristic (CMC) curve const int Max_Retrieval = 25;