Medial Code Documentation
Loading...
Searching...
No Matches
Utils.h
1//
2// General utils
3//
4
5#ifndef __UTILS_H__
6#define __UTILS_H__
7
8#include <cstdlib>
9#include <vector>
10#include <random>
11using namespace std;
12
13#define MAX(x,y) ((x)>(y)?(x):(y))
14#define MIN(x,y) ((x)<(y)?(x):(y))
15
16//#define FRAND30 ((double)((unsigned int)(my_rand()<<15)+(unsigned int)(my_rand()))/(double)(1<<30))
17//#define FRAND30 ((double)((unsigned int)(rand()<<15)+(unsigned int)(rand()))/(double)(1<<30))
18//#define FRAND30_R(s) ((double)((unsigned int)(rand_r(s)<<15)+(unsigned int)(rand_r(s)))/(double)(1<<30))
19//#define IRAND(S) ((int)((double)(S) * FRAND30))
20//#define IRAND_R(S,s) ((int)((double)(S) * FRAND30_R(s)))
21
22#define SQUARE(x) ((x)*(x))
23#define POWER_2(x) ((x)*(x))
24#define POWER_3(x) ((x)*(x)*(x))
25
26double Get_AUC(vector<float> &scores, vector<char> &Y);
27double Get_AUC(vector<float> &scores, vector<char> &Y, vector<double> &spe, vector<double> &sen);
28
30{
31public:
32 static std::minstd_rand::result_type rand() { return getInstance()._rng(); };
33 static unsigned int rand30() { return ((getInstance()._rng() << 15) ^ getInstance()._rng()) & 0x4fffffff; };
34 static void srand(std::minstd_rand::result_type val) { getInstance()._rng.seed(val); };
35 static const std::minstd_rand::result_type max() { return getInstance()._rng.max(); };
36
37private:
38 std::minstd_rand _rng;
39
40 static QRFglobalRNG& getInstance()
41 {
42 static QRFglobalRNG instance; // instansiated on first call
43 return instance;
44 }
45
46 QRFglobalRNG() : _rng(20150715) {}; // constructor
47
48 QRFglobalRNG(QRFglobalRNG const&) { fprintf(stderr, "Error: copying is forbidden for the globalRNG object\n"); exit(-1); }; // no copy constructor
49 void operator=(QRFglobalRNG const&) { fprintf(stderr, "Error: assignment is forbidden for the globalRNG object\n"); exit(-1); }; // no assignment operator
50
51};
52
53#endif
Definition Utils.h:30
Definition StdDeque.h:58