-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.h
executable file
·85 lines (65 loc) · 2.15 KB
/
global.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/***************************************************************************
* Copyright (C) 2015 Tian-Li Yu and Shih-Huan Hsu *
* tianliyu@ntu.edu.tw *
***************************************************************************/
#ifndef _GLOBAL_H
#define _GLOBAL_H
#define NDEBUG // for assert
#include <cassert>
#include <cmath>
#include "myrand.h"
#include "bitwisedistance.h"
#include "spin.h"
#include "nk-wa.h"
#include "doublelinkedlistarray.h"
#include "zkey.h"
#include "sat.h"
#define EPSILON (1e-8)
#define INF (1e10)
extern bool GHC;
extern bool SELECTION;
extern bool CACHE;
extern bool SHOW_BISECTION;
extern char outputFilename[100];
extern void gstop ();
extern void outputErrMsg (const char *errMsg);
extern int pow2 (int x);
extern ZKey zKey;
extern MyRand myRand;
extern BitwiseDistance myBD;
extern SPINinstance mySpinGlassParams;
extern SATinstance mySAT;
extern NKWAProblem nkwa;
inline int quotientLong(int a) {
return (a / (sizeof(unsigned long) * 8) );
}
inline int remainderLong(int a) {
return (a & (sizeof(unsigned long) * 8 - 1));
}
inline double jointEntropy(double p00, double p01, double p10, double p11) {
double result = 0.0;
result -= p00 * log(p00);
result -= p01 * log(p01);
result -= p10 * log(p10);
result -= p11 * log(p11);
return result;
}
inline double mutualInformation(double p00, double p01, double p10, double p11) {
double result = 0.0;
double p0x = p00+p01;
double p1x = p10+p11;
double px0 = p00+p10;
double px1 = p01+p11;
result += (p00 < EPSILON) ? 0.0 : p00 * log (p00 / p0x / px0);
result += (p01 < EPSILON) ? 0.0 : p01 * log (p01 / p0x / px1);
result += (p10 < EPSILON) ? 0.0 : p10 * log (p10 / p1x / px0);
result += (p11 < EPSILON) ? 0.0 : p11 * log (p11 / p1x / px1);
return result;
}
inline double metric(double p00, double p01, double p10, double p11) {
return mutualInformation(p00,p01,p10,p11)/jointEntropy(p00,p01,p10,p11);
}
inline double square(double a) {
return a*a;
}
#endif