-
Notifications
You must be signed in to change notification settings - Fork 3
/
library.h
147 lines (113 loc) · 9.29 KB
/
library.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
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
#include <sstream>
#include <list>
#include <map>
#include <vector>
/******************************************************************************/
/******************************************************************************/
/********************* SPECIFY the BASIS *******************************/
/******************************************************************************/
/******************************************************************************/
/*** Original Basis: ***********************************************/
/******************************************************************************/
list<uint32_t> Original_Basis(); // return the original basis, i.e., {s1, s2, ..., sn}
/*** READ BASIS from a FILE: ***********************************************/
/******************************************************************************/
list<uint32_t> Read_BasisOp_BinaryRepresentation(string Basis_binary_filename = basis_BinaryRepresentation_filename); // default filename to specify in data.h
list<uint32_t> Read_BasisOp_IntegerRepresentation(string Basis_integer_filename = basis_IntegerRepresentation_filename);
/*** Print Basis Info in the Terminal: *************************************/
/******************************************************************************/
void PrintTerm_Basis(list<uint32_t> Basis_li);
/******************************************************************************/
/******************************************************************************/
/****************** READ and TRANSFORM DATA ****************************/
/******************************************************************************/
/******************************************************************************/
/*** READ DATA and STORE data in Nset: *************************************/
/******************************************************************************/
vector<pair<uint32_t, unsigned int>> read_datafile(unsigned int *N, string filename = datafilename); // filename to specify in data.h
/*** DATA CHANGE of BASIS: *************************************************/
/******************************************************************************/
// *** Build Kset with the following definitions:
// *** mu_m = states of the systems written in the basis specified in `list<uint32_t> Basis`
// *** Kset[sig_m] = Number of times the state mu_m appears in the transformed dataset
//
// *** Rem: the new basis can have a lower dimension then the original dataset;
// *** in which case the function will reduce the dataset to the subspace defined by the specified basis.
vector<pair<uint32_t, unsigned int>> build_Kset(vector<pair<uint32_t, unsigned int>> Nset, list<uint32_t> Basis, bool print_bool=false);
/******************************************************************************/
/******************************************************************************/
/***************** Log-LIKELIHOOD (LogL), Log-EVIDENCE (LogE) *****************/
/*************************** and COMPLEXITY ********************************/
/******************************************************************************/
/******************************************************************************/
/**************** for a sub-Complete Model (SubCM) ************************/
/******************************************************************************/
// *** the SubCM is the one specified in Ai;
// *** Ai must be an integer encoded on at least n bits, where each 1 indicates the basis elements included in the part:
// *** For ex. Ai = 01001 is encoded on n=5 basis elements, and element Op1 and Op4 belong to the part;
// *** Rem: Basis elements are ordered from the right to the left.
// *** Complexity of a SC model based on m basis Operators: m >= 1. Rem: C_geom(m=1) = log(pi):
double GeomComplexity_ICC(unsigned int m); // Geometric complexity
double ParamComplexity_ICC(unsigned int m, unsigned int N); // Complexity due to the number of parameters
/****************** for a Complete Model (CM) *****************************/
/******************************************************************************/
double LogL_CM(vector<pair<uint32_t, unsigned int>> Kset, unsigned int N);
/**************************** for a MCM ********************************/
/******************************************************************************/
double Complexity_MCM(map<uint32_t, uint32_t> Partition, unsigned int N, double *C_param, double *C_geom);
double LogL_MCM(vector<pair<uint32_t, unsigned int>> Kset, map<uint32_t, uint32_t> Partition, unsigned int N);
double LogE_MCM(vector<pair<uint32_t, unsigned int>> Kset, map<uint32_t, uint32_t> Partition, unsigned int N);
/******************************************************************************/
/******************************************************************************/
/******************** DEFINE MCMs and PRINT INFO **************************/
/******************************************************************************/
/******************************************************************************/
// *** Define an MCM by hand:
map<uint32_t, uint32_t> Create_MCM(uint32_t MCM_table[], int k);
// *** Define an MCM from a file; Each part must be encoded in a binary number over n spins:
map<uint32_t, uint32_t> Read_MCMParts_BinaryRepresentation(string MCM_binary_filename);
// *** Check that the provided model corresponds to a partition of the basis variables (i.e. properly defines an MCM):
pair<bool, uint32_t> check_partition(map<uint32_t, uint32_t> Partition); // the second element is the rank of the partition (dimension of the MCM)
// *** Print information about the MCM specified in `MCM_Partition`:
void PrintTerminal_MCM_Info(vector<pair<uint32_t, unsigned int>> Kset, unsigned int N, map<uint32_t, uint32_t> MCM_Partition);
// *** Create successive independent models defined on the new basis, and print the corresponding information:
void PrintInfo_All_Indep_Models(vector<pair<uint32_t, unsigned int>> Kset, unsigned int N);
// *** Create successive Sub-complete models defined on the new basis, and print the corresponding information:
void PrintInfo_All_SubComplete_Models(vector<pair<uint32_t, unsigned int>> Kset, unsigned int N);
/******************************************************************************/
/******************************************************************************/
/*************************** Find Best MCM ********************************/
/******************************************************************************/
/******************************************************************************/
// *** Compute all partitions of a set using Algorithm H:
/******************************************************************************/
// *** Version 1: Compare all the MCMs of rank r,
// *** based on the r first elements of the basis used to build Kset:
// *** By default: - r=n
// *** - the function doesn't print the logE-values for all the tested MCMs. To activate --> print_bool = true
map<uint32_t, uint32_t> MCM_GivenRank_r(vector<pair<uint32_t, unsigned int>> Kset, unsigned int N, double *LogE_best, unsigned int r=n, bool print_bool=false);
/******************************************************************************/
// *** Version 2:
// *** Compare all the MCMs
// *** based on the k first elements of the basis used to build Kset
// *** for all k=1 to r, where r <= basis.size()
// *** By default: - r=n
// *** - the function doesn't print the logE-values for all the tested MCMs. To activate --> print_bool = true
map<uint32_t, uint32_t> MCM_AllRank_SmallerThan_r_Ordered(vector<pair<uint32_t, unsigned int>> Kset, unsigned int N, double *LogE_best, unsigned int r=n, bool print_bool=false);
/******************************************************************************/
// *** Version 3:
// *** Compare all the MCMs based on any subset of k elements
// *** of the of r first elements of the basis used to build Kset
// *** for all k=1 to r, where r <= basis.size()
// *** By default: - r=n
// *** - the function doesn't print the logE-values for all the tested MCMs. To activate --> print_bool = true
map<uint32_t, uint32_t> MCM_AllRank_SmallerThan_r_nonOrdered(vector<pair<uint32_t, unsigned int>> Kset, unsigned int N, double *LogE_best, unsigned int r=n, bool print_bool=false);
/******************************************************************************/
/******************************************************************************/
/*************************** PRINT TO FILE: ********************************/
/****************** DATA VS MODEL STATE PROBABILITIES **********************/
/******************************************************************************/
/******************************************************************************/
// *** Functions in the file "P_s.cpp":
void PrintFile_StateProbabilites_OriginalBasis(vector<pair<uint32_t, unsigned int>> Nset, list<uint32_t> Basis, map<uint32_t, uint32_t> MCM_Partition, unsigned int N, string filename = "Result");
void PrintFile_StateProbabilites_NewBasis(vector<pair<uint32_t, unsigned int>> Kset, map<uint32_t, uint32_t> MCM_Partition, unsigned int N, string filename = "Result");