#include #include #include #include #include #include #include "Dataset.hpp" static void fill_from_string(std::vector& v, const string & str) { double val; istringstream in(str); while (!in.eof()) { in >> val; v.push_back(val); } } Dataset::Dataset(string fname, double enc0, double enc1){ ifstream ifs(fname); if (!ifs.is_open()) { throw runtime_error("Could not open data file."); } string buffer; while (!ifs.eof()){ getline(ifs, buffer); if (buffer.length() == 0) break; vector v; fill_from_string(v,buffer); targetc.push_back(v[v.size()-1]); // put label in v.resize(v.size()-1); // Lose the class label invec.push_back(v); } // Determine number of classes size_t maxc = 0; for (auto c : targetc){ if (c>maxc) maxc = c; } nclasses = maxc; // Fill the classwise counts: ninc.resize(nclasses+1); for (auto & n : ninc) n=0; ninc[0]=nclasses; for (auto c : targetc){ ninc[c]++; } // Prepare prototypes for MLP classifiers: for (size_t i = 0; i p(nclasses); for (size_t j = 0; j & Dataset::prototype(size_t row){ return prototypes[targetc[row]-1]; } const vector & Dataset::row(size_t i) const { return invec[i]; } void Dataset::toStream(ostream & ost) const { for (size_t irow = 0; irow & r = row(irow); for (size_t i=0;i