53 catch (std::exception& e)
55 std::ostringstream msg;
56 msg << e.what() << std::endl <<
"Error reading the training vector";
57 throw std::runtime_error(msg.str());
72 for (
size_t i = 0;
i < op1.
size();
i++)
84 #ifdef UNUSED // detected as unused 29.6.2018 88 unsigned ClassicTrainingVectors::featureSize()
const 131 #ifndef _NO_EXCEPTION 144 if (!sscanf(line.c_str(),
"%ld", &
size))
158 std::vector<floatFeature> v;
160 for (
int j = 0;
j < dim;
j++)
171 #ifndef _NO_EXCEPTION 173 catch (std::exception& e)
175 std::ostringstream msg;
176 msg << e.what() << std::endl <<
"Error reading the training set";
177 throw std::runtime_error(msg.str());
199 std::ifstream fhInRaw(fnInRaw.c_str(),std::ios::binary);
202 std::vector<floatFeature> v;
203 v.resize(vectorSize);
204 auto *
buffer=
new float[vectorSize];
208 for (
size_t objId : vectorContent.
ids())
214 fhInRaw.seekg(order*vectorSize*
sizeof(
float));
215 fhInRaw.read((
char*)
buffer,vectorSize*
sizeof(
float));
219 order,fnInRaw.c_str()));
220 for (
size_t i=0;
i<vectorSize; ++
i)
270 #ifdef UNUSED // detected as unused 29.6.2018 276 void ClassicTrainingVectors::deleteVariable(
int _var)
278 for (
unsigned int it = 0; it <
size(); it++)
296 for (
size_t i = 0;
i < op1.
size();
i++)
308 #ifdef UNUSED // detected as unused 29.6.2018 319 if ((&_ts ==
this) || (
size() +
itemAt(0).
size() != 0))
return false;
337 if (((&_ts ==
this) || (_idx > _ts.
size())) ||
352 bool ClassicTrainingVectors::deleteRow(
unsigned int _idx)
370 std::ostringstream msg;
371 msg <<
"Out of range. No variable at position " << _i;
372 throw std::out_of_range(msg.str());
378 for (
size_t it = 0; it <
size(); it++)
380 if (!isnan(
itemAt(it)[_i]))
391 for (
size_t it = 0; it <
size(); it++)
393 if (!isnan(
itemAt(it)[_i]))
394 sd += (
itemAt(it)[_i] - mean) * (
itemAt(it)[_i] - mean);
401 for (
size_t it = 0; it <
size(); it++)
403 if (!isnan(
itemAt(it)[_i]))
421 for (
unsigned i = 0;
i <
itemAt(0).size();
i++)
434 for (
unsigned it = 0; it <
size(); it++)
436 for (
unsigned i = 0;
i <
itemAt(0).size();
i++)
446 #ifdef UNUSED // detected as unused 29.6.2018 451 double ClassicTrainingVectors::getUnormalizedVar(
unsigned _item,
unsigned _var)
const 456 std::ostringstream msg;
457 msg <<
"Variable is not normalized" << _var;
458 throw std::runtime_error(msg.str());
461 if (_var >
itemAt(0).size())
463 std::ostringstream msg;
464 msg <<
"Out of range. No variable at position " << _var;
465 throw std::out_of_range(msg.str());
470 std::ostringstream msg;
471 msg <<
"Out of range. No item at position " << _var;
472 throw std::out_of_range(msg.str());
476 if (!isnan(
itemAt(_item)[_var]))
512 std::ostringstream msg;
513 msg <<
"Out of range. No variable at position " << _i;
514 throw std::out_of_range(msg.str());
520 for (
size_t it = 0; it <
size(); it++)
522 if (!isnan(
itemAt(it)[_i]))
533 for (
size_t it = 0; it <
size(); it++)
535 if (!isnan(
itemAt(it)[_i]))
536 _sd += (
itemAt(it)[_i] - _mean) * (
itemAt(it)[_i] - _mean);
541 #ifdef UNUSED // detected as unused 29.6.2018 553 for (
unsigned i = 0;
i <
itemAt(0).size();
i++)
String removeSpaces(const String &_str)
#define REPORT_ERROR(nerr, ErrormMsg)
void getFeatureStats(unsigned _i, floatFeature &_mean, floatFeature &_sd)
void sqrt(Image< double > &op)
virtual void saveObject(std::ostream &_os) const
ClassicTrainingVectors(unsigned _vecSize=0, bool _calib=true)
void read(const FileName &fnIn)
bool isNormalized() const
const Target & targetAt(unsigned _i) const
ClassicTrainingVectors & operator=(const ClassicTrainingVectors &op1)
virtual void printSelf(std::ostream &_os) const
virtual void unNormalize()
std::vector< statsStruct > varStats
virtual void loadObject(std::istream &_is)
unsigned dimension() const
virtual void readSelf(std::istream &_is)
std::vector< FeatureVector > theItems
virtual void saveObject(std::ostream &_os) const
File or directory does not exist.
Couldn't read from file.
basic_istream< char, std::char_traits< char > > istream
std::vector< Label > theTargets
virtual void normalizeFeature(unsigned _i)
virtual void printSelf(std::ostream &_os) const
FileName withoutExtension() const
String formatString(const char *format,...)
virtual void loadObject(std::istream &_is)
const Item & itemAt(unsigned _i) const
virtual void add(const FeatureVector &_i, const Label &_tg)