Commit a7712abbb2aee9a81aa26688e23b7509da31c5d0

Authored by Josh Klontz
1 parent ee43de35

fixed bugs introduced in 54a98a9713eb1ace3b7c1d649746470449e307cb

Showing 1 changed file with 10 additions and 14 deletions
openbr/plugins/eigen3.cpp
@@ -302,8 +302,8 @@ class LDATransform : public Transform @@ -302,8 +302,8 @@ class LDATransform : public Transform
302 Q_PROPERTY(int directLDA READ get_directLDA WRITE set_directLDA RESET reset_directLDA STORED false) 302 Q_PROPERTY(int directLDA READ get_directLDA WRITE set_directLDA RESET reset_directLDA STORED false)
303 Q_PROPERTY(float directDrop READ get_directDrop WRITE set_directDrop RESET reset_directDrop STORED false) 303 Q_PROPERTY(float directDrop READ get_directDrop WRITE set_directDrop RESET reset_directDrop STORED false)
304 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) 304 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
305 - Q_PROPERTY(bool isBinary READ get_isBinary WRITE set_isBinary RESET reset_isBinary STORED true)  
306 - Q_PROPERTY(bool normalize READ get_normalize WRITE set_normalize RESET reset_normalize STORED true) 305 + Q_PROPERTY(bool isBinary READ get_isBinary WRITE set_isBinary RESET reset_isBinary STORED false)
  306 + Q_PROPERTY(bool normalize READ get_normalize WRITE set_normalize RESET reset_normalize STORED false)
307 BR_PROPERTY(float, pcaKeep, 0.98) 307 BR_PROPERTY(float, pcaKeep, 0.98)
308 BR_PROPERTY(bool, pcaWhiten, false) 308 BR_PROPERTY(bool, pcaWhiten, false)
309 BR_PROPERTY(int, directLDA, 0) 309 BR_PROPERTY(int, directLDA, 0)
@@ -316,12 +316,6 @@ class LDATransform : public Transform @@ -316,12 +316,6 @@ class LDATransform : public Transform
316 Eigen::VectorXf mean; 316 Eigen::VectorXf mean;
317 Eigen::MatrixXf projection; 317 Eigen::MatrixXf projection;
318 float stdDev; 318 float stdDev;
319 - bool trained;  
320 -  
321 - void init()  
322 - {  
323 - trained = false;  
324 - }  
325 319
326 void train(const TemplateList &_trainingSet) 320 void train(const TemplateList &_trainingSet)
327 { 321 {
@@ -461,9 +455,9 @@ class LDATransform : public Transform @@ -461,9 +455,9 @@ class LDATransform : public Transform
461 projection = ((space2.eVecs.transpose() * space1.eVecs.transpose()) * pca.eVecs.transpose()).transpose(); 455 projection = ((space2.eVecs.transpose() * space1.eVecs.transpose()) * pca.eVecs.transpose()).transpose();
462 dimsOut = dim2; 456 dimsOut = dim2;
463 457
  458 + stdDev = 1; // default initialize
464 if (isBinary) { 459 if (isBinary) {
465 assert(dimsOut == 1); 460 assert(dimsOut == 1);
466 - TemplateList projected;  
467 float posVal = 0; 461 float posVal = 0;
468 float negVal = 0; 462 float negVal = 0;
469 Eigen::MatrixXf results(trainingSet.size(),1); 463 Eigen::MatrixXf results(trainingSet.size(),1);
@@ -493,8 +487,6 @@ class LDATransform : public Transform @@ -493,8 +487,6 @@ class LDATransform : public Transform
493 if (normalize) 487 if (normalize)
494 stdDev = sqrt(results.array().square().sum() / trainingSet.size()); 488 stdDev = sqrt(results.array().square().sum() / trainingSet.size());
495 } 489 }
496 -  
497 - trained = true;  
498 } 490 }
499 491
500 void project(const Template &src, Template &dst) const 492 void project(const Template &src, Template &dst) const
@@ -508,18 +500,22 @@ class LDATransform : public Transform @@ -508,18 +500,22 @@ class LDATransform : public Transform
508 // Do projection 500 // Do projection
509 outMap = projection.transpose() * (inMap - mean); 501 outMap = projection.transpose() * (inMap - mean);
510 502
511 - if (normalize && isBinary && trained) 503 + if (normalize && isBinary)
512 dst.m().at<float>(0,0) = dst.m().at<float>(0,0) / stdDev; 504 dst.m().at<float>(0,0) = dst.m().at<float>(0,0) / stdDev;
513 } 505 }
514 506
515 void store(QDataStream &stream) const 507 void store(QDataStream &stream) const
516 { 508 {
517 - stream << pcaKeep << directLDA << directDrop << dimsOut << mean << projection << stdDev << normalize << isBinary << trained; 509 + stream << pcaKeep << directLDA << directDrop << dimsOut << mean << projection;
  510 + if (normalize && isBinary)
  511 + stream << stdDev;
518 } 512 }
519 513
520 void load(QDataStream &stream) 514 void load(QDataStream &stream)
521 { 515 {
522 - stream >> pcaKeep >> directLDA >> directDrop >> dimsOut >> mean >> projection >> stdDev >> normalize >> isBinary >> trained; 516 + stream >> pcaKeep >> directLDA >> directDrop >> dimsOut >> mean >> projection;
  517 + if (normalize && isBinary)
  518 + stream >> stdDev;
523 } 519 }
524 }; 520 };
525 521