Commit e3b09a68d6e1d90b040d5417c1f0de2de4543c43
1 parent
83dd836b
exposed DKE equations
Showing
2 changed files
with
31 additions
and
19 deletions
sdk/core/common.h
| @@ -200,6 +200,33 @@ QList<T> CumSum(const QList<T> &vals) | @@ -200,6 +200,33 @@ QList<T> CumSum(const QList<T> &vals) | ||
| 200 | 200 | ||
| 201 | 201 | ||
| 202 | /**** | 202 | /**** |
| 203 | +KernelDensityBandwidth | ||
| 204 | + Calculate DKE bandwidth parameter 'h' | ||
| 205 | +****/ | ||
| 206 | +template <typename T> | ||
| 207 | +double KernelDensityBandwidth(const QList<T> &vals) | ||
| 208 | +{ | ||
| 209 | + double mean, stddev; | ||
| 210 | + MeanStdDev(vals, &mean, &stddev); | ||
| 211 | + return pow(4 * pow(stddev, 5.0) / (3 * vals.size()), 0.2); | ||
| 212 | +} | ||
| 213 | + | ||
| 214 | + | ||
| 215 | +/**** | ||
| 216 | +KernelDensityEstimation | ||
| 217 | + Compute kernel density at value x with bandwidth h. | ||
| 218 | +****/ | ||
| 219 | +template <typename T> | ||
| 220 | +double KernelDensityEstimation(const QList<T> &vals, double x, double h) | ||
| 221 | +{ | ||
| 222 | + double y = 0; | ||
| 223 | + foreach (T val, vals) | ||
| 224 | + y += exp(-pow((val-x)/h,2)/2)/sqrt(2*3.1415926353898); | ||
| 225 | + return y / (vals.size() * h); | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | + | ||
| 229 | +/**** | ||
| 203 | RandSample | 230 | RandSample |
| 204 | Returns a vector of n integers sampled in the range <min, max]. | 231 | Returns a vector of n integers sampled in the range <min, max]. |
| 205 | If unique then there will be no repeated integers. | 232 | If unique then there will be no repeated integers. |
sdk/core/plot.cpp
| @@ -109,21 +109,6 @@ static float getTAR(const QList<OperatingPoint> &operatingPoints, float FAR) | @@ -109,21 +109,6 @@ static float getTAR(const QList<OperatingPoint> &operatingPoints, float FAR) | ||
| 109 | return m * FAR + b; | 109 | return m * FAR + b; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | -static float kernelDensityBandwidth(const QList<double> &vals) | ||
| 113 | -{ | ||
| 114 | - double mean, stddev; | ||
| 115 | - Common::MeanStdDev(vals, &mean, &stddev); | ||
| 116 | - return pow(4 * pow(stddev, 5.0) / (3 * vals.size()), 0.2); | ||
| 117 | -} | ||
| 118 | - | ||
| 119 | -static float kernelDensityEstimation(const QList<double> &vals, double x, double h) | ||
| 120 | -{ | ||
| 121 | - double y = 0; | ||
| 122 | - foreach (double val, vals) | ||
| 123 | - y += exp(-pow((val-x)/h,2)/2)/sqrt(2*CV_PI); | ||
| 124 | - return y / (vals.size() * h); | ||
| 125 | -} | ||
| 126 | - | ||
| 127 | float Evaluate(const QString &simmat, const QString &mask, const QString &csv) | 112 | float Evaluate(const QString &simmat, const QString &mask, const QString &csv) |
| 128 | { | 113 | { |
| 129 | qDebug("Evaluating %s with %s", qPrintable(simmat), qPrintable(mask)); | 114 | qDebug("Evaluating %s with %s", qPrintable(simmat), qPrintable(mask)); |
| @@ -237,13 +222,13 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv) | @@ -237,13 +222,13 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv) | ||
| 237 | sampledImpostorScores.append(impostorScore); | 222 | sampledImpostorScores.append(impostorScore); |
| 238 | } | 223 | } |
| 239 | 224 | ||
| 240 | - const double hGenuine = kernelDensityBandwidth(sampledGenuineScores); | 225 | + const double hGenuine = Common::KernelDensityBandwidth(sampledGenuineScores); |
| 241 | foreach (double f, sampledGenuineScores) | 226 | foreach (double f, sampledGenuineScores) |
| 242 | - lines.append(QString("KDEGenuine,%1,%2").arg(QString::number(f), QString::number(kernelDensityEstimation(sampledGenuineScores, f, hGenuine)))); | 227 | + lines.append(QString("KDEGenuine,%1,%2").arg(QString::number(f), QString::number(Common::KernelDensityEstimation(sampledGenuineScores, f, hGenuine)))); |
| 243 | 228 | ||
| 244 | - const double hImpostor = kernelDensityBandwidth(sampledImpostorScores); | 229 | + const double hImpostor = Common::KernelDensityBandwidth(sampledImpostorScores); |
| 245 | foreach (double f, sampledImpostorScores) | 230 | foreach (double f, sampledImpostorScores) |
| 246 | - lines.append(QString("KDEImpostor,%1,%2").arg(QString::number(f), QString::number(kernelDensityEstimation(sampledImpostorScores, f, hImpostor)))); | 231 | + lines.append(QString("KDEImpostor,%1,%2").arg(QString::number(f), QString::number(Common::KernelDensityEstimation(sampledImpostorScores, f, hImpostor)))); |
| 247 | 232 | ||
| 248 | // Write Cumulative Match Characteristic (CMC) curve | 233 | // Write Cumulative Match Characteristic (CMC) curve |
| 249 | const int Max_Retrieval = 25; | 234 | const int Max_Retrieval = 25; |