forked from clelidm/MinCompSpin_Greedy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
128 lines (97 loc) · 6.04 KB
/
Copy pathmain.cpp
File metadata and controls
128 lines (97 loc) · 6.04 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// To compile: g++ -std=c++11 -O3 main.cpp Operations_OnData.cpp LogE.cpp LogL.cpp Complexity.cpp info_quant.cpp best_basis.cpp Basis_Choice.cpp P_s.cpp metropolis.cpp Best_MCM_Greedy.cpp
// To run: time ./a.out
//
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <bitset>
#include <map>
#include <cmath> /* tgamma */
#include <random>
#include <ctime> // for chrono
#include <ratio> // for chrono
#include <chrono> // for chrono
using namespace std;
using namespace std::chrono;
/******************************************************************************/
/********************** CONSTANTS AND FUNCTIONS *************************/
/******************************************************************************/
#include "data.h"
#include "library.h"
//#include "library_Metropolis.h"
/******************************************************************************/
/******************************* main function ****************************/
/******************************************************************************/
int main()
{
cout << "--->> Create OUTPUT Folder: (if needed) ";
system(("mkdir -p " + OUTPUT_directory).c_str());
cout << endl;
cout << endl << "*******************************************************************************************";
cout << endl << "*********************************** READ THE DATA: **************************************";
cout << endl << "*******************************************************************************************" << endl;
unsigned int N = 0; // will contain the number of datapoints in the dataset
map<__int128_t, unsigned int> Nset = read_datafile(&N);
if (N == 0) { return 0; } // Terminate program if the file can't be found
cout << endl << " ###### File has been read succesfully ######" << endl;
cout << "Number of datapoints = " << N << endl;
cout << "Number of different observed states = " << Nset.size() << endl;
cout << endl << "*******************************************************************************************";
cout << endl << "****************************** CHOICE OF THE BASIS: *************************************";
cout << endl << "*******************************************************************************************" << endl;
// list<__int128_t> Basis_li = Original_Basis(); // original basis of the data: this is the most natural choice a priori
// *** The basis can also be read from a file:
list<__int128_t> Basis_li = Read_BasisOp_IntegerRepresentation();
// list<__int128_t> Basis_li = Read_BasisOp_BinaryRepresentation();
PrintTerm_Basis(Basis_li);
cout << endl << "*******************************************************************************************";
cout << endl << "************************ Transform the data in the new basis ***************************";
cout << endl << "********************************** Build Kset: ****************************************";
cout << endl << "*******************************************************************************************" << endl;
//// *** Transform the data in the specified in Basis_SCModel[];
map<__int128_t, unsigned int> Kset = build_Kset(Nset, Basis_li, false);
cout << endl << "*******************************************************************************************";
cout << endl << "****************************** Hierachical merging result: ******************************";
cout << endl << "*******************************************************************************************" << endl;
// *** Calculate the optimal partition
auto start = chrono::system_clock::now();
map<unsigned int, __int128_t> fp1 = Matrix(Kset, N);
auto end = chrono::system_clock::now();
// *** Time it takes to find partition
chrono::duration<double> elapsed = end - start;
cout << "######### EMPERICAL #########" << endl;
// Entropy of dataset
double H = Entropy(Kset, N);
cout << "H : " << H << ". Range: [0, " << n << "]" << endl << endl;
cout << "######### GREEDY #########" << endl;
// Log evidence of MCM
double LE_g = LogE_MCM(Kset, fp1, N);
Print_Partition(fp1);
cout << "Elapsed time : " << elapsed.count() << "s" << endl;
cout << "Log-evidence : " << LE_g << endl;
cout << "Average comm size : " << (double)n / (double)fp1.size() << endl << endl;
cout << "######### THEORETICAL #########" << endl;
map<unsigned int, __int128_t> fp2 = read_communities(communityfile);
double LE_t = LogE_MCM(Kset, fp2, N);
Print_Partition(fp2);
cout << "Log-evidence : " << LE_t << endl;
cout << "Average comm size : " << (double)n / (double)fp2.size() << endl << endl;
cout << "######### COMPARATIVE MEASURES #########" << endl;
double VOI = Var_of_Inf(fp1, fp2);
double NMI = Norm_Mut_info(fp1, fp2);
string istrue = is_subset(fp1, fp2) ? "Yes" : "No";
cout << "Is MCM_g \'subset\' of MCM_t : " << istrue << endl;
cout << "Variation of Information : " << VOI << endl;
cout << "Normalized Mutual Information : " << NMI << endl;
cout << "Difference in Log-Evidence : " << LE_g - LE_t << endl << endl;
cout << endl << "*******************************************************************************************";
cout << endl << "********************** Print information about the found MCM: ***************************";
cout << endl << "*******************************************************************************************" << endl;
// Prints 1) information about the MCM; 2) the state probabilities P(s) (in the Data VS MCM); 3) the probability P(k) of observing a state with k values "+1" (in the Data VS MCM)
PrintFile_StateProbabilites_OriginalBasis(Nset, Basis_li, fp1, N, "Result");
// Print the state probabilities P(s) (in the Data VS MCM) using the data transformed in the bew basis:
PrintFile_StateProbabilites_NewBasis(Kset, fp1, N, "Result");
return 0;
}