-
Notifications
You must be signed in to change notification settings - Fork 2
/
measure.h
316 lines (229 loc) · 8.03 KB
/
measure.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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#ifndef MEASURE_H
#define MEASURE_H
#include "head_proj.h"
#include "basis.h"
#include <fstream>
#include <cmath>
class Measure: public PARAMS
{
private:
//observables here
double Energy;
double Mag1;
double Mag2;
double Mag3;
vector<double> Renyi; //naiive direct estimator (obsolete)
vector<double> Renyi2;//improved LR cluster estimator
//This is the number of clusters of the unswapped simulation
int ClustNumber;
public:
Measure();
void zero();
void measure_E(const Basis &);
void measure_M(const Basis &, const int &);
void measure_M_mod(const vector<int>&, const vector<int>&);
void Renyi_direct(const int& , const int& , const int& );
vector<int> LRoverlap(const vector<int>&, const vector<int>&, int &);
void output();
//Renyis below
void Calc_Renyi(const vector<int>& , const vector<int>& );
int Renyi_LRclust(const vector<int>& ,const vector<int>&, const vector<int>&);
};
Measure::Measure() {//constructor
Energy = 0.0;
Mag1 = 0.0;
Mag2 = 0.0;
Mag3 = 0.0;
Renyi.assign(nSwap,0.0);
Renyi2.assign(nSwap,0.0);
};
void Measure::zero(){
Energy = 0.0;
Mag1 = 0.0;
Mag2 = 0.0;
Mag3 = 0.0;
Renyi.assign(nSwap,0.0);
Renyi2.assign(nSwap,0.0);
}//zero
void Measure::Renyi_direct(const int& index, const int& numer, const int& denom){
int frac_s = numer-denom;
Renyi[index] += pow(2.0,frac_s);
}//Renyi_direct
void Measure::Calc_Renyi(const vector<int>& Left, const vector<int>& Right){
int frac_s, numer;
int denom = ClustNumber; //global variable calculated in measure_M_mod
for(int ii=0; ii<nSwap; ii++){
numer = Renyi_LRclust(inAreg[ii],Left,Right);
frac_s = numer-denom;
Renyi2.at(ii) += pow(2.0,frac_s);
}
}//Calc_Renyi
//This function calculates the swap operator directly from the Left and Right
// "clusters" that have been calculated in the linked list
//*** NOTE always calculate measure_M_mod *FIRST*
int Measure::Renyi_LRclust(const vector<int>& inA,
const vector<int>& Left, const vector<int>& Right){
vector<int> Mtemp;
int max_index; //this is the maximum cluster index in the overlap
//int frac_s, numer;
//int denom = ClustNumber; //global variable calculated in measure_M_mod
vector<int> RightSwap(Right); //copy constructor?
int temp;
//---PERMUTE! the Right projector here
for (int i=0; i<inA.size(); i++){
if (inA[i] != 0){
if (ratioON == 0 || inAreg[inAreg.size()-1][i] == 0){ //only swap on un-ratioed
temp = RightSwap[i];
for (int rep=0; rep<alpha-1; rep++)
RightSwap[rep*numRealSpin+i] = RightSwap[rep*numRealSpin+i+numRealSpin];
RightSwap[(alpha-1)*numRealSpin+i] = temp;
}
}//inA
}//i
Mtemp = LRoverlap(Left,RightSwap,max_index);
vector<int> MidClustsNum(max_index+1,0);
for (int k=0; k<Mtemp.size(); k++)
MidClustsNum[Mtemp[k]] = 1;
int counter = 0; //number of clusters
for (int k=0; k<MidClustsNum.size(); k++)
counter += MidClustsNum[k];
//numer = counter;
//frac_s = numer-denom;
return counter; //this is the numerator of the ratio of powers
//Renyi2.at() += pow(2.0,frac_s);
}//Renyi_LRclust
void Measure::measure_E(const Basis & basis){
int n_0=0;
for(int i=0; i<basis.OperatorList.size(); i++){
if (basis.OperatorList[i].A == -1)
n_0++;
}//i
Energy += 1.0*n_0;
//cout<<Energy<<endl;
}//measure_E
void Measure::measure_M(const Basis & basis, const int & L2){
int m_0 = 0;
vector<int> S_prop;
S_prop = basis.S_left;
for(int i=0; i<basis.OperatorList.size()/2; i++){
if (basis.OperatorList[i].A == -2) //this is a off-diagonal site operator
S_prop[basis.OperatorList[i].B] = S_prop[basis.OperatorList[i].B]^1 ; //spin flip
}
for (int i=0; i<basis.numSpin; i++)
m_0 += (2*S_prop[i]-1);
Mag1 += 1.0*m_0*m_0; //m^2
Mag2 += 1.0*L2;
}//measure_M
void Measure::measure_M_mod(const vector<int>& Left, const vector<int>& Right){
vector<int> Mtemp;
int max_index; //this is the maximum cluster index in the overlap
Mtemp = LRoverlap(Left,Right,max_index);
vector<int> MidClustsNum(max_index+1,0);
vector<int> MidClustsSize(max_index+1,0);
for (int k=0; k<Mtemp.size(); k++){
MidClustsNum[Mtemp[k]] = 1;
MidClustsSize[Mtemp[k]] += 1;
}
int counter = 0; //number of clusters
int sizesquared = 0;
for (int k=0; k<MidClustsNum.size(); k++){
counter += MidClustsNum[k];
sizesquared += MidClustsSize[k]*MidClustsSize[k];
}
//cout<<"new clust #: "<<counter<<endl;
//cout<<counter<<endl;
ClustNumber = counter; //private global variable
Mag3 += 1.0*sizesquared;
}//measure_M_mod
//a function that takes the L and R "center" cluster vectors and calculates
//the overlap vector
vector<int> Measure::LRoverlap(const vector<int>& Left, const vector<int>& Right, int & max){
// vector<int> RightSwap(Right); //copy constructor?
// //---PERMUTE! the Right projector here
// if (ratioON == 1){
// int Xindex = inAreg.size()-1;
// int temp;
// for (int i=0; i<inAreg[Xindex].size(); i++){
// if (inAreg[Xindex][i] != 0){
// temp = RightSwap[i];
// for (int rep=0; rep<alpha-1; rep++)
// RightSwap[rep*numRealSpin+i] = RightSwap[rep*numRealSpin+i+numRealSpin];
// RightSwap[(alpha-1)*numRealSpin+i] = temp;
// }
// }
// }//if
int Nspin = Left.size();
vector<int> Mtemp;
stack<int> Rstack;
stack<int> Lstack;
int current;
//cout<<Nspin<<endl;
Mtemp.assign(Nspin,0);
bool keepgoing = true;
//for (int ii=1; ii<=Nspin; ii++){
int ii = 0;
while(keepgoing == true){
ii++;
keepgoing = false;
current = ii;
for (int j=0; j<Nspin; j++){
if (Left[j] == current && Mtemp[j] == 0){
Mtemp[j] = ii;
Rstack.push(Right[j]);
}
if (Mtemp[j] == 0) keepgoing = true;
}
do{
while(!Rstack.empty()){
current = Rstack.top();
Rstack.pop();
for (int j=0; j<Nspin; j++)
if (Right[j] == current && Mtemp[j] == 0){
Mtemp[j] = ii;
Lstack.push(Left[j]);
}
}//while Rstack
while(!Lstack.empty()){
current = Lstack.top();
Lstack.pop();
for (int j=0; j<Nspin; j++)
if (Left[j] == current && Mtemp[j] == 0){
Mtemp[j] = ii;
Rstack.push(Right[j]);
}
}//while Rstack
}while(!Lstack.empty() || !Rstack.empty());
//cout<<ii<<": ";
//for (int k=0; k<Mtemp.size(); k++)
// cout<<Mtemp[k]<<" ";
//cout<<endl;
}//ii
//for (int k=0; k<Mtemp.size(); k++)
// cout<<Mtemp[k]<<" ";
//cout<<endl;
max = ii; //this is the maximum cluster index contained in the overlap
return Mtemp;
}//LRoverlap
void Measure::output(){
double one_over_n;
ofstream cfout;
cfout.open("00.data",ios::app);
cfout<<setprecision(8);
one_over_n = Energy/(1.0*MCS_);
//cfout<<numSpin*h_x*2.0*m_ / one_over_n<<" ";
cfout<<-(numSpin*h_x*2.0*m_ / one_over_n - numSpin*h_x - numLattB)/numSpin<<" ";
//cfout<<Mag1/(1.0*MCS_*1.0*numSpin*numSpin)<<" ";
//cfout<<Mag2/(1.0*MCS_*1.0*numSpin*numSpin)<<" ";
cfout<<Mag3/(1.0*MCS_*1.0*numSpin*numSpin);
cfout<<endl;
cfout.close();
cfout.open("01.data",ios::app);
for (int i=0; i<Renyi.size(); i++){
//cfout<<i<<" "<<-log(Renyi[i]/(1.0*MCS_))<<" ";
//cfout<<i+1<<" "<<(1.0/(1.0-1.0*alpha))*log(Renyi2[i]/(1.0*MCS_))<<endl;
cfout<<Renyi2[i]/(1.0*MCS_)<<" ";
}
cfout<<endl;
cfout.close();
}//output
#endif