Commit e6c2e195ee1f64fa5293996717c91d25d4b58463

Authored by Charles Otto
1 parent 39d1c697

Rename collectValues to get, add a values method

These names mirroring File functionality.
Fixed SVMDistance
dropped unnecessary second relabel in LDATransform::train
openbr/core/bee.cpp
... ... @@ -262,8 +262,8 @@ cv::Mat BEE::makeMask(const br::FileList &targets, const br::FileList &queries,
262 262 {
263 263 // Would like to use indexProperty for this, but didn't make a version of that for Filelist yet
264 264 // -cao
265   - QList<QString> targetLabels = targets.collectValues<QString>("Subject", "-1");
266   - QList<QString> queryLabels = queries.collectValues<QString>("Subject", "-1");
  265 + QList<QString> targetLabels = targets.get<QString>("Subject", "-1");
  266 + QList<QString> queryLabels = queries.get<QString>("Subject", "-1");
267 267 QList<int> targetPartitions = targets.crossValidationPartitions();
268 268 QList<int> queryPartitions = queries.crossValidationPartitions();
269 269  
... ...
openbr/core/cluster.cpp
... ... @@ -280,7 +280,7 @@ void br::EvalClustering(const QString &amp;csv, const QString &amp;input)
280 280  
281 281 // We assume clustering algorithms store assigned cluster labels as integers (since the clusters are
282 282 // not named).
283   - QList<int> labels = TemplateList::fromGallery(input).files().collectValues<int>("Subject");
  283 + QList<int> labels = TemplateList::fromGallery(input).files().get<int>("Subject");
284 284  
285 285 QHash<int, int> labelToIndex;
286 286 int nClusters = 0;
... ...
openbr/openbr_plugin.cpp
... ... @@ -437,7 +437,7 @@ TemplateList TemplateList::fromGallery(const br::File &amp;gallery)
437 437 // stores the index values in "Label" of the output template list -cao
438 438 TemplateList TemplateList::relabel(const TemplateList &tl, const QString & propName)
439 439 {
440   - const QList<QString> originalLabels = tl.collectValues<QString>(propName);
  440 + const QList<QString> originalLabels = tl.get<QString>(propName);
441 441 QHash<QString,int> labelTable;
442 442 foreach (const QString & label, originalLabels)
443 443 if (!labelTable.contains(label))
... ... @@ -465,7 +465,7 @@ QList&lt;int&gt; TemplateList::indexProperty(const QString &amp; propName, QHash&lt;QString,
465 465 valueMap.clear();
466 466 reverseLookup.clear();
467 467  
468   - const QList<QVariant> originalLabels = collectValues<QVariant>(propName);
  468 + const QList<QVariant> originalLabels = values(propName);
469 469 foreach (const QVariant & label, originalLabels) {
470 470 QString labelString = label.toString();
471 471 if (!valueMap.contains(labelString)) {
... ... @@ -484,7 +484,7 @@ QList&lt;int&gt; TemplateList::indexProperty(const QString &amp; propName, QHash&lt;QString,
484 484 // uses -1 for missing values
485 485 QList<int> TemplateList::applyIndex(const QString & propName, const QHash<QString, int> & valueMap) const
486 486 {
487   - const QList<QString> originalLabels = collectValues<QString>(propName);
  487 + const QList<QString> originalLabels = get<QString>(propName);
488 488  
489 489 QList<int> result;
490 490 for (int i=0; i<originalLabels.size(); i++) {
... ...
openbr/openbr_plugin.h
... ... @@ -297,9 +297,9 @@ struct BR_EXPORT FileList : public QList&lt;File&gt;
297 297 QStringList flat() const; /*!< \brief Returns br::File::flat() for each file in the list. */
298 298 QStringList names() const; /*!< \brief Returns #br::File::name for each file in the list. */
299 299 void sort(const QString& key); /*!< \brief Sort the list based on metadata. */
300   - /*!< \brief Returns br::File::label() for each file in the list. */
  300 + /*!< \brief Returns values associated with the input propName for each file in the list. */
301 301 template<typename T>
302   - QList<T> collectValues(const QString & propName) const
  302 + QList<T> get(const QString & propName) const
303 303 {
304 304 QList<T> values; values.reserve(size());
305 305 foreach (const File &f, *this)
... ... @@ -307,7 +307,7 @@ struct BR_EXPORT FileList : public QList&lt;File&gt;
307 307 return values;
308 308 }
309 309 template<typename T>
310   - QList<T> collectValues(const QString & propName, T defaultValue) const
  310 + QList<T> get(const QString & propName, T defaultValue) const
311 311 {
312 312 QList<T> values; values.reserve(size());
313 313 foreach (const File &f, *this)
... ... @@ -480,12 +480,18 @@ struct TemplateList : public QList&lt;Template&gt;
480 480 * \brief Returns br::Template::label() for each template in the list.
481 481 */
482 482 template<typename T>
483   - QList<T> collectValues(const QString & propName) const
  483 + QList<T> get(const QString & propName) const
484 484 {
485 485 QList<T> values; values.reserve(size());
486 486 foreach (const Template &t, *this) values.append(t.file.get<T>(propName));
487 487 return values;
488 488 }
  489 + QList<QVariant> values(const QString & propName) const
  490 + {
  491 + QList<QVariant> values; values.reserve(size());
  492 + foreach (const Template &t, *this) values.append(t.file.value(propName));
  493 + return values;
  494 + }
489 495  
490 496 /*!
491 497 * \brief Returns the number of occurences for each label in the list.
... ...
openbr/plugins/eigen3.cpp
... ... @@ -343,14 +343,12 @@ class LDATransform : public Transform
343 343  
344 344 TemplateList ldaTrainingSet;
345 345 static_cast<Transform*>(&pca)->project(trainingSet, ldaTrainingSet);
346   - // Reindex label, is this still necessary? -cao
347   - ldaTrainingSet = TemplateList::relabel(ldaTrainingSet, "Label");
348 346  
349 347 int dimsIn = ldaTrainingSet.first().m().rows * ldaTrainingSet.first().m().cols;
350 348  
351 349 // OpenBR ensures that class values range from 0 to numClasses-1.
352 350 // Label exists because we created it earlier with relabel
353   - QList<int> classes = trainingSet.collectValues<int>("Label");
  351 + QList<int> classes = trainingSet.get<int>("Label");
354 352 QMap<int, int> classCounts = trainingSet.countValues<int>("Label");
355 353 const int numClasses = classCounts.size();
356 354  
... ...
openbr/plugins/independent.cpp
... ... @@ -20,7 +20,7 @@ static TemplateList Downsample(const TemplateList &amp;templates, const Transform *t
20 20 const bool atLeast = transform->instances < 0;
21 21 const int instances = abs(transform->instances);
22 22  
23   - QList<QString> allLabels = templates.collectValues<QString>("Subject");
  23 + QList<QString> allLabels = templates.get<QString>("Subject");
24 24 QList<QString> uniqueLabels = allLabels.toSet().toList();
25 25 qSort(uniqueLabels);
26 26  
... ...
openbr/plugins/output.cpp
... ... @@ -146,8 +146,8 @@ class meltOutput : public MatrixOutput
146 146 QStringList lines;
147 147 if (file.baseName() != "terminal") lines.append(QString("Query,Target,Mask,Similarity%1").arg(keys));
148 148  
149   - QList<QString> queryLabels = queryFiles.collectValues<QString>("Subject");
150   - QList<QString> targetLabels = targetFiles.collectValues<QString>("Subject");
  149 + QList<QString> queryLabels = queryFiles.get<QString>("Subject");
  150 + QList<QString> targetLabels = targetFiles.get<QString>("Subject");
151 151  
152 152 for (int i=0; i<queryFiles.size(); i++) {
153 153 for (int j=(selfSimilar ? i+1 : 0); j<targetFiles.size(); j++) {
... ...
openbr/plugins/svm.cpp
... ... @@ -130,7 +130,7 @@ private:
130 130 Mat lab;
131 131 // If we are doing regression, assume subject has float values
132 132 if (type == EPS_SVR || type == NU_SVR) {
133   - lab = OpenCVUtils::toMat(_data.collectValues<float>("Subject"));
  133 + lab = OpenCVUtils::toMat(_data.get<float>("Subject"));
134 134 }
135 135 // If we are doing classification, assume subject has discrete values, map them
136 136 // and store the mapping data
... ... @@ -200,7 +200,7 @@ private:
200 200 void train(const TemplateList &src)
201 201 {
202 202 const Mat data = OpenCVUtils::toMat(src.data());
203   - const QList<int> lab = src.collectValues<int>("Label");
  203 + const QList<int> lab = src.indexProperty("Subject");
204 204  
205 205 const int instances = data.rows * (data.rows+1) / 2;
206 206 Mat deltaData(instances, data.cols, data.type());
... ...