UFJF - Machine Learning Toolkit  0.51.8
Utils.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 #define PRECISION 1E-9
9 #define MAX_NUMBER_STRING_SIZE 32
10 #define INF 1E8
11 
12 #include <vector>
13 #include <cstring>
14 #include <string>
15 #include <sstream>
16 #include <iterator>
17 #include <ctime>
18 
19 namespace mltk{
20  enum NormType {NORM_LINF = 0, NORM_L1 = 1, NORM_L2 = 2};
21  typedef std::vector<std::vector<double> > dMatrix;
22 
23  namespace utils {
24  void printConfusionMatrix(const std::vector<int>& classes, const std::vector<std::string>& classes_names, const std::vector<std::vector<size_t> > &confusion_m, bool show_names=false);
30  bool is_number(std::string str);
31 
37  int stoin(std::string str);
38 
44  double atod(const char* str);
45 
51  std::string itos(int n);
52 
58  std::string dtoa(double n);
59 
60  std::vector<std::string> tokenize(const std::string &str, const char delim);
61 
62  std::string timestamp();
63 
64  // trim from start (in place)
65  static inline void ltrim(std::string &s) {
66  s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
67  return !std::isspace(ch);
68  }));
69  }
70 
71 // trim from end (in place)
72  static inline void rtrim(std::string &s) {
73  s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
74  return !std::isspace(ch);
75  }).base(), s.end());
76  }
77 
78 // trim from both ends (in place)
79  static inline void trim(std::string &s) {
80  ltrim(s);
81  rtrim(s);
82  }
83 
84 // trim from start (copying)
85  static inline std::string ltrim_copy(std::string s) {
86  ltrim(s);
87  return s;
88  }
89 
90 // trim from end (copying)
91  static inline std::string rtrim_copy(std::string s) {
92  rtrim(s);
93  return s;
94  }
95 
96 // trim from both ends (copying)
97  static inline std::string trim_copy(std::string s) {
98  trim(s);
99  return s;
100  }
101  }
102 }
std::string dtoa(double n)
dtoa Double to string conversion.
Definition: Utils.cpp:94
double atod(const char *str)
Converts the string to a double.
Definition: Utils.cpp:40
int stoin(std::string str)
Converts the string to an integer.
Definition: Utils.cpp:20
bool is_number(std::string str)
Verify if the string is a number.
Definition: Utils.cpp:15
std::string itos(int n)
itos Integer to string conversion.
Definition: Utils.cpp:60
UFJF-MLTK main namespace for core functionalities.
Definition: classifier/Classifier.hpp:11