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