-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
280 lines (209 loc) · 15.6 KB
/
main.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// To compile: g++ -std=c++11 -O3 main.cpp Data_Manipulation.cpp LogL_LogE.cpp Complexity.cpp Basis_Choice.cpp MCM_info.cpp P_s.cpp Best_MCM.cpp
// To run: time ./a.out
//
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <map>
#include <vector>
#include <cmath> /* tgamma */
#include <ctime> // for chrono
#include <ratio> // for chrono
#include <chrono> // for chrono
using namespace std;
using namespace std::chrono;
/********************************************************************/
/************************** CONSTANTS *************************/
/********************************************************************/
#include "data.h"
#include "library.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
vector<pair<uint32_t, unsigned int>> Nset = read_datafile(&N, datafilename);
cout << endl << "*******************************************************************************************";
cout << endl << "********************************** !! IMPORTANT !! ****************************************";
cout << endl << "*******************************************************************************************";
cout << endl << "****************************** CHOICE OF THE BASIS: *************************************";
cout << endl << "*******************************************************************************************" << endl;
cout << endl << "Choice of the basis for building the Minimally Complex Model (MCM):" << endl;
// *** Basis elements are written using the integer representation of the operator
// *** For instance, a basis element on the last two spin variable would be written:
// *** --> Op = s1 s2 Spin operator
// *** --> Op = 000000011 Binary representation
// *** --> Op = 3 Integer representation ( 000000011 = 3 )
// *** One can simply use the original basis of the data: // This is the most natural choice a priori
// list<uint32_t> Basis_li = Original_Basis();
// *** The basis can be specified by hand here:
/*
uint32_t Basis_Choice[] = {3, 5, 9, 48, 65, 129, 272, 256, 1}; // Ex. This is the best basis for the "Shapes" dataset
unsigned int m = sizeof(Basis_Choice) / sizeof(uint32_t);
list<uint32_t> Basis_li; Basis_li.assign (Basis_Choice, Basis_Choice + m);
*/
// *** The basis can also be read from a file:
// list<uint32_t> Basis_li = Read_BasisOp_IntegerRepresentation();
list<uint32_t> Basis_li = Read_BasisOp_BinaryRepresentation();
// *** Print info about the Basis:
PrintTerm_Basis(Basis_li);
cout << "Number of spin variables, n=" << n << endl;
cout << "Number of basis elements, m=" << Basis_li.size() << endl;
if (Basis_li.size() > n) { cout << " --> Error: the number 'm' of basis elements is larger than the size 'n' of the system." << endl; }
else {
cout << " --> m <= n : Everything seems fine." << endl;
cout << "Make sure that the set of basis elements provided are orthogonal to each other." << endl;
}
cout << endl << "*******************************************************************************************";
cout << endl << "****************************** CHANGE THE BASIS OF THE DATA *****************************";
cout << endl << "************************************** Build Kset: **************************************";
cout << endl << "*******************************************************************************************" << endl;
cout << endl << "INFORMATION:\n\t To look for the best MCM on a chosen basis, the data needs first to be re-written in that basis.";
cout << endl << "\t The following function re-write the histogram of the data in the basis specified above.";
cout << endl << "\t If the specified basis is the original basis, then this transformation is not needed." << endl;
cout << endl << "/!\\ IMPORTANT: If m<n:";
cout << endl << "\t If the size 'm' of the basis is strictly smaller than the number 'n' of variables, ";
cout << endl << "\t then the data will be truncated to the 'm' first basis elements." << endl;
cout << endl << "Transform the data in the basis specified above:" << endl;
vector<pair<uint32_t, unsigned int>> Kset = build_Kset(Nset, Basis_li, false);
cout << endl << "*******************************************************************************************";
cout << endl << "******************************** All Independent Models: ********************************";
cout << endl << "*******************************************************************************************" << endl << endl;
cout << "Independent models in the new basis:" << endl;
PrintInfo_All_Indep_Models(Kset, N);
cout << endl << "*******************************************************************************************";
cout << endl << "************************** All Successive Sub-Complete Models: **************************";
cout << endl << "*******************************************************************************************" << endl << endl;
cout << "Sub-Complete models in the new basis:" << endl;
PrintInfo_All_SubComplete_Models(Kset, N);
cout << endl << "*******************************************************************************************";
cout << endl << "*********************************** Define your own MCM: ********************************";
cout << endl << "******************************* and get information about it: ***************************";
cout << endl << "*******************************************************************************************" << endl << endl;
// *** The MCM can be specified by hand here:
uint32_t MCM_Choice[] = {384, 64, 32, 16, 8, 4, 2, 1}; // Ex. this is the best MCM for the "Shape" dataset
unsigned int k = sizeof(MCM_Choice) / sizeof(uint32_t); // Number of parts
map<uint32_t, uint32_t> MCM_Partition0 = Create_MCM(MCM_Choice, k);
// *** The MCM can also be read from a file:
// map<uint32_t, uint32_t> MCM_Partition0 = Read_MCMParts_BinaryRepresentation("./INPUT/Shapes_n9_MCM_Binary.dat");
if(check_partition(MCM_Partition0).first)
{
PrintTerminal_MCM_Info(Kset, N, MCM_Partition0);
}
else { cout << "The set of 'parts' provided does not form a partition of the basis elements." << endl; }
cout << endl << "*******************************************************************************************";
cout << endl << "******************************* Find the Best MCM: **************************************";
cout << endl << "*******************************************************************************************";
cout << endl;
cout << endl << "*******************************************************************************************";
cout << endl << "********************************* THREE EXAMPLES: ****************************************";
cout << endl << "***************** The three following functions search for the BEST MCM ******************";
cout << endl << "************************* based on the BASIS specified above *****************************";
cout << endl << "*******************************************************************************************" << endl;
cout << endl << "/!\\ IMPORTANT: prior to using the three following functions:";
cout << endl << "\tThe choice of the basis must have been provided in the variable \'Basis_li\',";
cout << endl << "\tand the data (initially stored in \'Nset\') must have been re-written in that basis using the function \'build_Kset()\'.";
cout << endl << "\tThe variable \'Kset\' then contains the transformed data." << endl;
cout << endl << "/!\\ SPECIAL CASE: ANALYSIS IN THE ORIGINAL BASIS:";
cout << endl << "\tThe data may also be analyzed untransformed, i.e. in its original basis.";
cout << endl << "\tIn this case:\n\t\t-- there is no need to specify \'Basis_li\', nor to transformed the data with \'build_Kset()\',";
cout << endl << "\t\t-- the three following functions can be used directly with the variable \'Nset\' instead of \'Kset\'." << endl;
cout << endl << "*******************************************************************************************";
cout << endl << "******************************* Find the Best MCM: **************************************";
cout << endl << "*********************************** VERSION 1 *******************************************";
cout << endl << "*******************************************************************************************";
cout << endl << "********************** Compare all MCMs of a given rank 'r' ******************************";
cout << endl << "********************* based on the 'r' first basis Operators: ***************************";
cout << endl << "*******************************************************************************************" << endl;
cout << endl << "/!\\ INFORMATION:";
cout << endl << "\tThe following function searches for the best MCM among all the MCMs based on the 'r' first basis operators";
cout << endl << "\ti.e., among only among MCMs of rank exactly equal to 'r'" << endl;
cout << endl << "/!\\ IMPORTANT: Condition on the value of 'r': r <= m <= n ";
cout << endl << "\t'r' must be smaller or equal to the number 'm' of basis element provided, 'm=Basis_li.size()',";
cout << endl << "\twhich must be smaller or equal to the number 'n' of spin variables." << endl << endl;
auto start = chrono::system_clock::now();
int r1 = 9;
double LogE_BestMCM1 = 0;
if (r1 <= Basis_li.size())
{
map<uint32_t, uint32_t> MCM_Partition1 = MCM_GivenRank_r(Kset, N, &LogE_BestMCM1, r1, false);
//cout << "\t Best LogE = " << LogE_BestMCM1 << endl;
PrintTerminal_MCM_Info(Kset, N, MCM_Partition1);
MCM_Partition0 = MCM_Partition1;
}
else { cout << "The condition on the value of 'r' is not respected" << endl; }
// *** Time it takes to go through all the partition:
auto end = chrono::system_clock::now();
chrono::duration<double> elapsed = end - start;
cout << "Elapsed time : " << elapsed.count() << "s" << endl;
cout << endl << "*******************************************************************************************";
cout << endl << "******************************* Find the Best MCM: **************************************";
cout << endl << "*********************************** VERSION 2 *******************************************";
cout << endl << "*******************************************************************************************";
cout << endl << "**************** Compare all MCMs of rank 'k', with 1 <= k <=r' **************************";
cout << endl << "****************** based on the 'k' first basis Operators: ******************************";
cout << endl << "*******************************************************************************************" << endl;
cout << endl << "/!\\ INFORMATION:";
cout << endl << "\tThe following function searches among all the MCMs based on the 'k' FIRST basis operators provided, for all k in [1; r]" << endl;
cout << endl << "/!\\ IMPORTANT: Condition on the value of 'r': r <= m <= n ";
cout << endl << "\t'r' must be smaller or equal to the number 'm' of basis element provided, 'm=Basis_li.size()',";
cout << endl << "\twhich must be smaller or equal to the number 'n' of spin variables." << endl;
cout << endl << "\tPlease check the function declaration for the default arguments." << endl << endl;
/******************************************************************************/
// *** By default: - r=n
// *** - the function doesn't print the logE-values for all the tested MCMs. To activate --> print_bool = true
/******************************************************************************/
int r2 = 9;
double LogE_BestMCM2 = 0;
if (r2 <= Basis_li.size())
{
map<uint32_t, uint32_t> MCM_Partition2 = MCM_AllRank_SmallerThan_r_Ordered(Kset, N, &LogE_BestMCM2, r2, false);
//cout << "\t Best LogE = " << LogE_BestMCM2 << endl;
PrintTerminal_MCM_Info(Kset, N, MCM_Partition2);
MCM_Partition0 = MCM_Partition2;
}
else { cout << "The condition on the value of 'r' is not respected" << endl; }
cout << endl << "*******************************************************************************************";
cout << endl << "******************************* Find the Best MCM: **************************************";
cout << endl << "*********************************** VERSION 3 *******************************************";
cout << endl << "*******************************************************************************************";
cout << endl << "**************** Compare all MCMs of rank 'k', with 1 <= k <=r' **************************";
cout << endl << "*********** based on any 'k' subset of the basis Operators provided *********************";
cout << endl << "*******************************************************************************************" << endl;
cout << endl << "/!\\ INFORMATION:";
cout << endl << "The following function searches among all MCMs based on ANY SUBSET of 'k' operators of the basis provided, for all k=1 to r" << endl;
cout << endl << "/!\\ IMPORTANT: Conditions on the value of 'r': r <= m <= n ";
cout << endl << "\t'r' must be smaller or equal to the number 'm' of basis element provided, 'm=Basis_li.size()',";
cout << endl << "\twhich must be smaller or equal to the number 'n' of spin variables." << endl;
cout << endl << "\tPlease check the function declaration for the default arguments." << endl << endl;
/******************************************************************************/
// *** By default: - r=n
// *** - the function doesn't print the logE-values for all the tested MCMs. To activate --> print_bool = true
/******************************************************************************/
int r3 = 9;
double LogE_BestMCM3 = 0;
if (r3 <= Basis_li.size())
{
map<uint32_t, uint32_t> MCM_Partition3 = MCM_AllRank_SmallerThan_r_nonOrdered(Kset, N, &LogE_BestMCM3, r3, false);
//cout << "\t Best LogE = " << LogE_BestMCM3 << endl;
PrintTerminal_MCM_Info(Kset, N, MCM_Partition3);
MCM_Partition0 = MCM_Partition3;
}
else { cout << "The condition on the value of 'r' is not respected" << endl; }
cout << endl << "*******************************************************************************************";
cout << endl << "*********************************** PRINT TO FILE ***********************************";
cout << endl << "**************************** DATA VS MODEL PROBABILITIES: ***************************";
cout << endl << "*******************************************************************************************" << endl << endl;
// Print Information about the:
PrintFile_StateProbabilites_OriginalBasis(Nset, Basis_li, MCM_Partition0, N, "Result");
PrintFile_StateProbabilites_NewBasis(Kset, MCM_Partition0, N, "Result");
return 0;
}