Medial Code Documentation
Loading...
Searching...
No Matches
MedUtils.h
1//
2// MedUtils: Collection of several needed utilities (Files IO, Matrix data type, Data structures, etc)
3//
4
5// This is a simple h file to include all library parts
6
7#ifndef __MED_UTILS_H__
8#define __MED_UTILS_H__
9
10//#include "MedGenUtils.h"
11//#include "MedMat.h"
12//#include "MedMedical.h"
13//#include "MedDataStructures.h"
15#include "assert.h"
16#include "MedPlot.h"
17#include <boost/program_options.hpp>
18#include <boost/spirit/home/support/detail/hold_any.hpp>
19#include <boost/algorithm/string.hpp>
20#include <unordered_map>
21#include <MedMat/MedMat/MedMatConstants.h>
22#include "MedRunPath.h"
23#include "MedSamplingHelper.h"
24
25using namespace std;
26
27enum MedBinningType {
28 BIN_EQUIDIST,
29 BIN_EQUISIZE,
30 BIN_LAST
31};
32
33// Discretization
34template <class S> int discretize(vector<S>& x, vector<int>& binned_x, int& nbins, int max_bins);
35template <class S> int discretize(vector<S>& x, vector<int>& binned_x, int& nbins, int max_bins, float missing_value);
36template <class S> int discretize(vector<S>& x, vector<int>& binned_x, int& nbins, int max_bins, MedBinningType binning);
37template <class S> int discretize(vector<S>& x, vector<int>& binned_x, int& nbins, int max_bins, float missing_value, MedBinningType binning);
38
39namespace po = boost::program_options;
40
44namespace medial {
48 namespace print {
50 template<class T> string print_obj(T obj, const string &format);
52 template<class T> void print_vec(const vector<T> &vec, const string &title, const string &format, const string &delimeter = ", ");
54 void print_vec(const vector<string> &vec, const string &title, const string &delimeter = ", ");
56 template<class T> void print_hist_vec(const vector<T> &vec, const string &title, const string &format, const vector<double> *prctile_samples = NULL);
58 string print_any(po::variable_value &a);
59
60 void log_with_file(ofstream &fw, const char *format_str, ...);
61 }
65 namespace process {
67 template<class T> void prctils(const vector<T> &x, const vector<double> &prc, vector<T> &res, const vector<float> *weights = NULL);
69 template<typename T> int binary_search_index(const T *begin, const T *end, T val);
71 template<typename T> int binary_search_position(const T *begin, const T *end, T val, bool reversed = false);
73 template<typename T> int binary_search_position_last(const T *begin, const T *end, T val, bool reversed = false);
74
76 template<class T> int binary_search_position(const vector<T> &v, T search);
78 template<class T> int binary_search_position(const vector<T> &v, T search,int start, int end);
79 }
80
84 namespace sort_ops {
86 template<typename T> void get_sort_indexes(const vector<T> &x, const bool descending_order, bool const abs_val, vector<int> &indexes);
87 }
88
89
93 namespace io {
95 void read_codes_file(const string &file_path, vector<string> &tokens);
96 template<class T> string get_list(const unordered_map<string, T> &ls, const string &delimeter = ",") {
97 string res = "";
98 for (auto it = ls.begin(); it != ls.end(); ++it)
99 if (it == ls.begin())
100 res += it->first;
101 else
102 res += delimeter + it->first;
103 return res;
104 }
105 template<class T> string get_list_op(const unordered_map<T, string> &ls, const string &delimeter = ",") {
106 string res = "";
107 for (auto it = ls.begin(); it != ls.end(); ++it)
108 if (it == ls.begin())
109 res += it->second;
110 else
111 res += delimeter + it->second;
112 return res;
113 }
114 template<class ContainerType> string get_list(const ContainerType &ls, const string &delimeter = ",");
123 private:
124 string base_config;
125 bool init_called;
126
127 po::options_description desc;
131 virtual void post_process() {};
133 string get_section(const string &full_help, const string &search);
134
136 void list_sections(const string &full_help, vector<string> &all_sec);
137 protected:
139 void init(po::options_description &prg_options, const string &app_l = "");
141 ProgramArgs_base() { init_called = false; debug = false; }
142 public:
143 bool debug;
144 po::variables_map vm;
145 string app_logo = "\
146## ## ######## ######## #### ### ## \n\
147### ### ## ## ## ## ## ## ## \n\
148#### #### ## ## ## ## ## ## ## \n\
149## ### ## ###### ## ## ## ## ## ## \n\
150## ## ## ## ## ## ######### ## \n\
151## ## ## ## ## ## ## ## ## \n\
152## ## ######## ######## #### ## ## ######## ";
153
154
155
157 virtual int parse_parameters(int argc, char *argv[]);
158
159 };
160 }
161
163 string get_git_version();
164}
165
166#include "MedUtils_imp.h"
167
168#endif
Logger.h - allowing logs with more control.
A Library to plot graphs in HTML using plotly.js Example Code: vector<map<float,...
A basic class wrapper to parse command args has default "h", "help", "debug" and "base_config" for re...
Definition MedUtils.h:122
string app_logo
the application logo/name
Definition MedUtils.h:145
void init(po::options_description &prg_options, const string &app_l="")
an init function
Definition MedUtils.cpp:355
bool debug
a debug flag for verbose printing. will be init from command args
Definition MedUtils.h:143
ProgramArgs_base()
the ctor of base class
Definition MedUtils.h:141
virtual int parse_parameters(int argc, char *argv[])
the main function to parse the command arguments
Definition MedUtils.cpp:403
process(fname, allow_type)
Definition lint.py:152
void read_codes_file(const string &file_path, vector< string > &tokens)
reads file with codes name to vector
Definition MedUtils.cpp:530
void print_hist_vec(const vector< T > &vec, const string &title, const string &format, const vector< double > *prctile_samples=NULL)
printing vector elements hist prctiles in list [] with title to MLOG
Definition MedUtils.cpp:139
string print_obj(T obj, const string &format)
general print to string woth format
Definition MedUtils.cpp:47
string print_any(po::variable_value &a)
print boost program options object
Definition MedUtils.cpp:335
void print_vec(const vector< T > &vec, const string &title, const string &format, const string &delimeter=", ")
printing vector elements in list [] with title to MLOG
Definition MedUtils.cpp:113
int binary_search_position(const T *begin, const T *end, T val, bool reversed=false)
binary search for position to add new element in sorted manner (first position if equal elements foun...
Definition MedUtils.cpp:232
void prctils(const vector< T > &x, const vector< double > &prc, vector< T > &res, const vector< float > *weights=NULL)
calc prctile
Definition MedUtils.cpp:57
int binary_search_index(const T *begin, const T *end, T val)
binary search for index. -1 if not found
Definition MedUtils.cpp:205
int binary_search_position_last(const T *begin, const T *end, T val, bool reversed=false)
binary search for position to add new element in sorted manner (last position if equal elements found...
Definition MedUtils.cpp:277
void get_sort_indexes(const vector< T > &x, const bool descending_order, bool const abs_val, vector< int > &indexes)
sorts x (or abs(x)) and returns the indexes of sorted values in indexes (descending or ascending)
Definition MedUtils.cpp:12
medial namespace for function
Definition InfraMed.h:667
string get_git_version()
general print to string woth format
Definition MedUtils.cpp:551
Definition StdDeque.h:58