From bf74938bd5420ef81f8bf647a5360ec24a5c07f6 Mon Sep 17 00:00:00 2001 From: Miroslav Vitkov Date: Tue, 2 Jul 2019 14:55:23 +0200 Subject: [PATCH 1/2] Fixed a bug about input labels. The program used to assume that the set of output labels is contained in the set of target labels. Now it counts the actual classes. It still assumes that _all labels are sequential from 0_! --- src/confusion.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/confusion.hpp b/src/confusion.hpp index a8d9b6f..b2bc9b8 100644 --- a/src/confusion.hpp +++ b/src/confusion.hpp @@ -12,6 +12,7 @@ #include // std::stringstream, std::stringbuf #include #include +#include using namespace std; @@ -39,10 +40,16 @@ class Confusion { confusion(tar, out); } + unsigned calcNumClasses( const vector & v1, const vector & v2 ) + { + std::set all{ v1.cbegin(), v1.cend() }; + all.insert( v2.cbegin(), v2.cend() ); + return all.size(); + } + void convertToBooleanMatrix(vector targets, vector outputs, vector> &tar, vector> &out) { - int numClasses = - *max_element(targets.begin(), targets.end()) - *min_element(targets.begin(), targets.end()) + 1; + int numClasses = calcNumClasses( targets, outputs ); int numSamples = targets.size(); vector> t(numClasses, vector(numSamples)); vector> o(numClasses, vector(numSamples)); From f7cc87d256259f1318e4d3fb16d8e039cc3e7083 Mon Sep 17 00:00:00 2001 From: Miroslav Vitkov Date: Tue, 2 Jul 2019 15:02:00 +0200 Subject: [PATCH 2/2] Fixed a signedness warning. --- src/confusion.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/confusion.hpp b/src/confusion.hpp index b2bc9b8..765c913 100644 --- a/src/confusion.hpp +++ b/src/confusion.hpp @@ -300,8 +300,8 @@ class Confusion { } void print(vector> vec) { - for (int i = 0; i < vec.size(); ++i) { - for (int j = 0; j < vec[0].size(); ++j) { + for (unsigned i = 0; i < vec.size(); ++i) { + for (unsigned j = 0; j < vec[0].size(); ++j) { cout << vec[i][j] << " "; } cout << endl;