-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmrpt-highlevel.cpp
1644 lines (1418 loc) · 67.7 KB
/
mrpt-highlevel.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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. See the enclosed file LICENSE for a copy or if
* that was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright 2017 Max H. Gerlach
*
* */
/*
* mrpt-highlevel.cpp
*
* Created on: Aug 5, 2011
* Author: max
*/
// generalized for SDW DQMC (2015-02-06 - )
#include <iostream>
#include <fstream>
#include <exception>
#include <map>
#include <memory> // shared_ptr
#include <array>
#include <string>
#include "metadata.h"
#include "tools.h"
#include "statistics.h"
#include "datamapwriter.h"
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "dlib/cmd_line_parser.h" // for simplicity: keep using DLIB for this instead of rewriting the handling below with Boost
#include "boost/filesystem.hpp"
#pragma GCC diagnostic pop
#include "mrpt.h"
#include "mrpt-jk.h"
#include "mrpt-highlevel.h"
using namespace std;
//variables in the following anonymous namespace are local to this file
namespace {
MultireweightHistosPT* mr = 0;
enum BC { PBC=0, APBCX=1, APBCY=2, APBCXY=3, NONE };
const std::array<BC, 4> all_BC = {{PBC, APBCX, APBCY, APBCXY}};
std::array<std::shared_ptr<MultireweightHistosPT>, 4> mrbc;
unsigned binCount = 0;
bool discreteIsingBins = false;
bool use_jackknife = false;
unsigned jackknifeBlocks = 0;
bool do_directEstimates = false;
bool non_iterative = true;
unsigned maxIterations = 10000;
double iterationTolerance = 1E-7;
bool be_quiet = false;
ofstream dev_null("/dev/null");
string outputDirPrefix;
string infoFilename;
std::array<std::string, 4> infoFilenamesBC;
typedef dlib::cmd_line_parser<char>::check_1a_c clp;
clp parser;
unsigned subsampleHowMuch = 1;
unsigned discardSamples = 0;
bool sortByCp = false;
bool saveTauInt = false;
string zInFile;
string zOutFile;
bool globalTau = false;
bool noTau = false;
bool autocorrPlots = false;
bool crossCorr = false;
bool crossCorrAlt = false;
string headerSuffix;
enum { COL1, COL2 } timeSeriesFormat;
}
void initFromCommandLine(int argc, char** argv) {
//Command line parsing
parser.add_option("help", "display this help message");
parser.add_option("q", "be less verbose");
parser.add_option("info", "info generated by simulation (\"info.dat\")", 1);
parser.add_option("b", "number of energy bins", 1);
parser.add_option("discrete-ising-bins", "Pass this instead of -b to set up energy bins that match the natural discrete energies of the 2D Ising model of this system size.");
parser.add_option("i", "max number of iterations to determine Z[cp]", 1);
parser.add_option("t", "tolerance in iterative determination of Z[cp]", 1);
parser.add_option("loadz", "load partition functions from the indicated file", 1);
parser.add_option("savez", "save partition functions to the indicated file", 1);
parser.add_option("direct", "also calculate direct averages from the time series at the original temperatures without any reweighting");
parser.add_option("non-iterative", "first do a non-iterative estimation of the density of states as in Fenwick, 2008");
parser.add_option("constant-overlap", "iteratively reweight energy histograms until constant overlap is achieved");
parser.add_option("n", "indicates number of target temperatures if --constant-overlap is passed. Default: same as input.", 1);
parser.add_option("cp-range", "Takes three arguments to determine the range of control parameters to reweight to: the minimum, the maximum and the step size", 3);
parser.add_option("cp-auto-range", "Takes one argument to determine the control parameter to reweight to: the step size; minimum and maximum are determinded automatically", 1);
parser.add_option("cp-range-discrete", "Takes three arguments to determine the range of inverse temperatures to discretely reweight energy and heat capacity to: the minimum, the maximum and the step size", 3);
parser.add_option("j", "use jack-knife error estimation, indicate number of blocks", 1);
parser.add_option("h", "write reweighted histograms at each target cp");
parser.add_option("max-susc", "Search the maximum of the observable susceptibiliy between the inverse temperatures given as arguments", 2);
parser.add_option("min-binder", "Search the minimum of the binder cumulant of the observable between the inverse temperatures given as arguments", 2);
parser.add_option("max-specific-heat", "Search the maximum of the specific heat between the inverse temperatures given as arguments", 2);
parser.add_option("energy-double-peak", "Search equal-height and equal-weight double-peak energy histograms between the inverse temperatures given as arguments", 2);
parser.add_option("obs-double-peak", "Search an equal-height and equal-weight double-peak observable histograms between the inverse temperatures given as arguments", 2);
parser.add_option("peak-tolerance", "tolerance factor in determining dip in double-peak histograms. Default: 0.1", 1);
parser.add_option("reldip-at", "Determine relative dips in histograms at given target cp", 1);
parser.add_option("sub-sample", "Sub samples the time series as they are read in (pass number of data points to be put into one sample", 1);
parser.add_option("d", "Discard the first samples of the time series (pass number of samples to be left out) -- allows for further thermalization.", 1);
parser.add_option("sort", "Sort replica timeseries by temperatures before doing any processing (simulate canonical data). This could hide correlations.");
parser.add_option("save-tau-int", "Estimate and write out integrated autocorrelation times. Requires --sort");
parser.add_option("global-tau", "Do not estimate statistical inefficiencies for individual bins, but only globally for each temperature -- g_km = g_k");
parser.add_option("no-tau", "Ignore all differences in statistical inefficiencies when reweighting -- g_km = 1");
parser.add_option("cross-corr", "Calculate (histogram bin) cross-correlation coefficients for H_km, H_kn");
parser.add_option("cross-corr-alt", "Calculate (histogram bin) cross-correlation coefficients for H_km, H_kn using an alternative method (probably slow and bad)");
parser.add_option("autocorr-plots", "Write out the data points used to estimate (bin) statistical inefficiencies to check the form of the auto-correlation functions");
parser.add_option("time-series-format", "Set to number of columns: 1 (default) or 2; 1-column time series are already sorted by control parameter", 1);
//further general arguments: file names of energy/observable time series
parser.parse(argc, argv);
//echo whole commandline:
cout << "command line: ";
for (int arg = 0; arg < argc; ++arg) {
cout << argv[arg] << " ";
}
cout << endl;
const char* one_time_opts[] = {"info", "b", "loadz", "savez", "n", "cp-range", "cp-auto-range", "j", "i", "sub-sample", "sort", "time-series-format"};
parser.check_one_time_options(one_time_opts);
const char* incompatible1[] = {"global-tau", "no-tau"};
parser.check_incompatible_options(incompatible1);
const char* incompatible2[] = {"autocorr-plots", "no-tau"};
parser.check_incompatible_options(incompatible2);
const char* incompatible3[] = {"b", "discrete-ising-bins"};
parser.check_incompatible_options(incompatible3);
const char* incompatible4[] = {"cp-range", "cp-auto-range"};
parser.check_incompatible_options(incompatible4);
if (parser.option("help")) {
cout << "Multihistogram reweighting for time series originating from parallel tempering or canonical simulations" << endl;
cout << "Command line options understood:" << endl;
parser.print_options(cout);
cout << endl;
return;
}
if (const clp::option_type& jk = parser.option("j")) {
setJackknife(true, fromString<unsigned>(jk.argument()));
}
be_quiet = parser.option("q");
infoFilename = (parser.option("info") ?
parser.option("info").argument() : "info.dat");
if (not parser.option("b")) {
if (parser.option("discrete-ising-bins")) {
discreteIsingBins = true;
} else {
cerr << "energy bin count not specified (option -b)!" << endl;
}
} else {
binCount = dlib::sa = parser.option("b").argument();
}
do_directEstimates = parser.option("direct");
non_iterative = parser.option("non-iterative");
maxIterations = (non_iterative ? 0 : 10000); //if non-iterative estimation is attempted, by default don't do any iterations, else default to 1000
if (parser.option("i")) {
maxIterations = dlib::sa = parser.option("i").argument();
}
if (parser.option("t")) {
iterationTolerance = dlib::sa = parser.option("t").argument();
}
bool createHistograms = parser.option("h");
if (const clp::option_type& ss = parser.option("sub-sample")) {
subsampleHowMuch = dlib::sa = ss.argument();
}
if (const clp::option_type& dd = parser.option("d")) {
discardSamples = dlib::sa = dd.argument();
}
sortByCp = parser.option("sort");
saveTauInt = sortByCp and parser.option("save-tau-int");
zInFile = (parser.option("loadz") ? parser.option("loadz").argument() : "");
zOutFile = (parser.option("savez") ? parser.option("savez").argument() : "");
globalTau = parser.option("global-tau");
noTau = parser.option("no-tau");
autocorrPlots = parser.option("autocorr-plots");
crossCorr = parser.option("cross-corr");
crossCorrAlt = parser.option("cross-corr-alt");
if (const clp::option_type& tsf_opt = parser.option("time-series-format")) {
std::string tsf = tsf_opt.argument();
if (tsf == "1") {
timeSeriesFormat = COL1;
} else if (tsf == "2") {
timeSeriesFormat = COL2;
} else {
cerr << "Invalid time series format -- should be \"1\" or \"2\"" << endl;
}
}
init();
if (const clp::option_type& rr = parser.option("cp-range")) {
double cpMin = dlib::sa = rr.argument(0);
double cpMax = dlib::sa = rr.argument(1);
double cpStep = dlib::sa = rr.argument(2);
reweightRange(cpMin, cpMax, cpStep, createHistograms);
}
if (const clp::option_type& rr = parser.option("cp-auto-range")) {
// double cpMin = dlib::sa = rr.argument(0);
// double cpMax = dlib::sa = rr.argument(1);
auto cpMinMax = std::minmax_element(mr->controlParameterValues.begin(),
mr->controlParameterValues.end());
double cpMin = *cpMinMax.first;
double cpMax = *cpMinMax.second;
double cpStep = dlib::sa = rr.argument(0);
reweightRange(cpMin, cpMax, cpStep, createHistograms);
}
if (const clp::option_type& rr = parser.option("cp-range-discrete")) {
double cpMin = dlib::sa = rr.argument(0);
double cpMax = dlib::sa = rr.argument(1);
double cpStep = dlib::sa = rr.argument(2);
reweightDiscreteRange(cpMin, cpMax, cpStep, createHistograms);
}
if (const clp::option_type& fms = parser.option("max-susc")) {
double findMaxSuscCpStart = dlib::sa = fms.argument(0);
double findMaxSuscCpEnd = dlib::sa = fms.argument(1);
findMaxSusc(findMaxSuscCpStart, findMaxSuscCpEnd);
}
if (const clp::option_type& fms = parser.option("min-binder")) {
double findMinBinderCpStart = dlib::sa = fms.argument(0);
double findMinBinderCpEnd = dlib::sa = fms.argument(1);
findMinBinder(findMinBinderCpStart, findMinBinderCpEnd);
}
if (const clp::option_type& fms = parser.option("max-specific-heat")) {
double findMaxSpecificHeatCpStart = dlib::sa = fms.argument(0);
double findMaxSpecificHeatCpEnd = dlib::sa = fms.argument(1);
findMaxSpecificHeat(findMaxSpecificHeatCpStart, findMaxSpecificHeatCpEnd);
}
double peakTolerance = .05;
if (const clp::option_type& pt = parser.option("peak-tolerance")) {
peakTolerance = dlib::sa = pt.argument(0);
}
if (const clp::option_type& dp = parser.option("energy-double-peak")) {
double cpStart = dlib::sa = dp.argument(0);
double cpEnd = dlib::sa = dp.argument(1);
findEnergyDoublePeak(cpStart, cpEnd, peakTolerance);
}
if (const clp::option_type& dp = parser.option("obs-double-peak")) {
double cpStart = dlib::sa = dp.argument(0);
double cpEnd = dlib::sa = dp.argument(1);
findObservableDoublePeak(cpStart, cpEnd, peakTolerance);
}
if (const clp::option_type& rda = parser.option("reldip-at")) {
double targetControlParameter = dlib::sa = rda.argument(0);
findEnergyRelDip(targetControlParameter, peakTolerance);
findObservableRelDip(targetControlParameter, peakTolerance);
}
}
//maps cp->observable (or function there of, their errors)
//reset in init(), afterwards grow after various reweighting calls
typedef map<double, double> Map;
typedef std::shared_ptr<Map> MapPtr;
//results from multi-histogram reweighting:
MapPtr energy;
MapPtr specificHeat;
MapPtr observable; // <m> = 1/systemSize * <M>
MapPtr susceptibilityPart; // systemSize * <m^2>
MapPtr susceptibility; // systemSize * (<m^2> - <m>^2)
MapPtr binder;
MapPtr binderRatio;
MapPtr energyError;
MapPtr specificHeatError;
MapPtr observableError;
MapPtr susceptibilityPartError;
MapPtr susceptibilityError;
MapPtr binderError;
MapPtr binderRatioError;
//results from direct averaging of time series sorted by temperature:
MapPtr direct_energy;
MapPtr direct_specificHeat;
MapPtr direct_observable;
MapPtr direct_susceptibilityPart;
MapPtr direct_susceptibility;
MapPtr direct_binder;
MapPtr direct_binderRatio;
MapPtr direct_energyError;
MapPtr direct_specificHeatError;
MapPtr direct_observableError;
MapPtr direct_susceptibilityPartError;
MapPtr direct_susceptibilityError;
MapPtr direct_binderError;
MapPtr direct_binderRatioError;
//internal function to output the above maps
void writeOutResults() {
//reweighting results:
if (energy and not energy->empty()) {
DoubleMapWriter energyOut;
energyOut.setData(energy);
if (use_jackknife) energyOut.setErrors(energyError);
energyOut.addHeaderText("MRPT estimates of energy");
if (use_jackknife) energyOut.addHeaderText("jackknife error estimation");
energyOut.addMeta("energyBins", binCount);
energyOut.addMeta("observable", "energy");
energyOut.addMeta("L", getSystemL());
energyOut.addMeta("N", getSystemN());
energyOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) energyOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
energyOut.addHeaderText(getControlParameterName()+"\t energy" + headerSuffix);
energyOut.writeToFile(outputDirPrefix + "mrpt-energy-l-" + numToString(getSystemL()) + ".values");
}
if (specificHeat and not specificHeat->empty()) {
DoubleMapWriter specificHeatOut;
specificHeatOut.setData(specificHeat);
if (use_jackknife) specificHeatOut.setErrors(specificHeatError);
specificHeatOut.addHeaderText("MRPT estimates of specific heat");
if (use_jackknife) specificHeatOut.addHeaderText("jackknife error estimation");
specificHeatOut.addMeta("energyBins", binCount);
specificHeatOut.addMeta("observable", "specificHeat");
specificHeatOut.addMeta("L", getSystemL());
specificHeatOut.addMeta("N", getSystemN());
specificHeatOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) specificHeatOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
specificHeatOut.addHeaderText(getControlParameterName()+"\t specificHeat" + headerSuffix);
specificHeatOut.writeToFile(outputDirPrefix + "mrpt-specific-heat-l-" + numToString(getSystemL()) + ".values");
}
if (observable and not observable->empty()) {
DoubleMapWriter observableOut;
observableOut.setData(observable);
if (use_jackknife) observableOut.setErrors(observableError);
observableOut.addHeaderText("MRPT estimates of " + getObservableName());
if (use_jackknife) observableOut.addHeaderText("jackknife error estimation");
observableOut.addMeta("energyBins", binCount);
observableOut.addMeta("observable", getObservableName());
observableOut.addMeta("L", getSystemL());
observableOut.addMeta("N", getSystemN());
observableOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) observableOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
observableOut.addHeaderText(getControlParameterName()+"\t " + getObservableName() + headerSuffix);
observableOut.writeToFile(outputDirPrefix + "mrpt-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (susceptibilityPart and not susceptibilityPart->empty()) {
DoubleMapWriter susceptibilityPartOut;
susceptibilityPartOut.setData(susceptibilityPart);
if (use_jackknife) susceptibilityPartOut.setErrors(susceptibilityPartError);
susceptibilityPartOut.addHeaderText("MRPT estimates of " + getObservableName() + " part susceptibility");
if (use_jackknife) susceptibilityPartOut.addHeaderText("jackknife error estimation");
susceptibilityPartOut.addMeta("energyBins", binCount);
susceptibilityPartOut.addMeta("observable", "suscpart-" + getObservableName());
susceptibilityPartOut.addMeta("L", getSystemL());
susceptibilityPartOut.addMeta("N", getSystemN());
susceptibilityPartOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) susceptibilityPartOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
susceptibilityPartOut.addHeaderText(getControlParameterName()+"\t " +
getObservableName() + "SusceptibilityPart" +
headerSuffix);
susceptibilityPartOut.writeToFile(outputDirPrefix + "mrpt-suscpart-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (susceptibility and not susceptibility->empty()) {
DoubleMapWriter susceptibilityOut;
susceptibilityOut.setData(susceptibility);
if (use_jackknife) susceptibilityOut.setErrors(susceptibilityError);
susceptibilityOut.addHeaderText("MRPT estimates of " + getObservableName() + " susceptibility");
if (use_jackknife) susceptibilityOut.addHeaderText("jackknife error estimation");
susceptibilityOut.addMeta("energyBins", binCount);
susceptibilityOut.addMeta("observable", "susc-" + getObservableName());
susceptibilityOut.addMeta("L", getSystemL());
susceptibilityOut.addMeta("N", getSystemN());
susceptibilityOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) susceptibilityOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
susceptibilityOut.addHeaderText(getControlParameterName()+"\t susc" + headerSuffix);
susceptibilityOut.writeToFile(outputDirPrefix + "mrpt-susc-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (binder and not binder->empty()) {
DoubleMapWriter binderOut;
binderOut.setData(binder);
if (use_jackknife) binderOut.setErrors(binderError);
binderOut.addHeaderText("MRPT estimates of " + getObservableName() + " binder parameter");
if (use_jackknife) binderOut.addHeaderText("jackknife error estimation");
binderOut.addMeta("energyBins", binCount);
binderOut.addMeta("observable", "binder-" + getObservableName());
binderOut.addMeta("L", getSystemL());
binderOut.addMeta("N", getSystemN());
binderOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) binderOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
binderOut.addHeaderText(getControlParameterName()+"\t binder" + headerSuffix);
binderOut.writeToFile(outputDirPrefix + "mrpt-binder-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (binderRatio and not binderRatio->empty()) {
DoubleMapWriter binderRatioOut;
binderRatioOut.setData(binderRatio);
if (use_jackknife) binderRatioOut.setErrors(binderRatioError);
binderRatioOut.addHeaderText("MRPT estimates of " + getObservableName() + " binder ratio parameter");
if (use_jackknife) binderRatioOut.addHeaderText("jackknife error estimation");
binderRatioOut.addMeta("energyBins", binCount);
binderRatioOut.addMeta("observable", "binderRatio-" + getObservableName());
binderRatioOut.addMeta("L", getSystemL());
binderRatioOut.addMeta("N", getSystemN());
binderRatioOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) binderRatioOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
binderRatioOut.addHeaderText(getControlParameterName()+"\t binderRatio" + headerSuffix);
binderRatioOut.writeToFile(outputDirPrefix + "mrpt-binderRatio-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
//results from direct averaging:
if (direct_energy and not direct_energy->empty()) {
DoubleMapWriter energyOut;
energyOut.setData(direct_energy);
if (use_jackknife) energyOut.setErrors(direct_energyError);
energyOut.addHeaderText("Direct estimates of energy");
if (use_jackknife) energyOut.addHeaderText("jackknife error estimation");
energyOut.addMeta("observable", "energy");
energyOut.addMeta("L", getSystemL());
energyOut.addMeta("N", getSystemN());
energyOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) energyOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
energyOut.addHeaderText(getControlParameterName()+"\t energy" + headerSuffix);
energyOut.writeToFile(outputDirPrefix + "mrpt-direct-energy-l-" + numToString(getSystemL()) + ".values");
}
if (direct_specificHeat and not direct_specificHeat->empty()) {
DoubleMapWriter specificHeatOut;
specificHeatOut.setData(direct_specificHeat);
if (use_jackknife) specificHeatOut.setErrors(direct_specificHeatError);
specificHeatOut.addHeaderText("Direct estimates of specific heat");
if (use_jackknife) specificHeatOut.addHeaderText("jackknife error estimation");
specificHeatOut.addMeta("observable", "specificHeat");
specificHeatOut.addMeta("L", getSystemL());
specificHeatOut.addMeta("N", getSystemN());
specificHeatOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) specificHeatOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
specificHeatOut.addHeaderText(getControlParameterName()+"\t specificHeat" + headerSuffix);
specificHeatOut.writeToFile(outputDirPrefix + "mrpt-direct-specific-heat-l-" + numToString(getSystemL()) + ".values");
}
if (direct_observable and not direct_observable->empty()) {
DoubleMapWriter observableOut;
observableOut.setData(direct_observable);
if (use_jackknife) observableOut.setErrors(direct_observableError);
observableOut.addHeaderText("Direct estimates of " + getObservableName());
if (use_jackknife) observableOut.addHeaderText("jackknife error estimation");
observableOut.addMeta("observable", getObservableName());
observableOut.addMeta("L", getSystemL());
observableOut.addMeta("N", getSystemN());
observableOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) observableOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
observableOut.addHeaderText(getControlParameterName()+"\t " + getObservableName() + headerSuffix);
observableOut.writeToFile(outputDirPrefix + "mrpt-direct-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (direct_susceptibilityPart and not direct_susceptibilityPart->empty()) {
DoubleMapWriter susceptibilityPartOut;
susceptibilityPartOut.setData(direct_susceptibilityPart);
if (use_jackknife) susceptibilityPartOut.setErrors(direct_susceptibilityPartError);
susceptibilityPartOut.addHeaderText("Direct estimates of " + getObservableName() + " part susceptibility");
if (use_jackknife) susceptibilityPartOut.addHeaderText("jackknife error estimation");
susceptibilityPartOut.addMeta("observable", "suscpart-" + getObservableName());
susceptibilityPartOut.addMeta("L", getSystemL());
susceptibilityPartOut.addMeta("N", getSystemN());
susceptibilityPartOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) susceptibilityPartOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
susceptibilityPartOut.addHeaderText(getControlParameterName()+"\t " +
getObservableName() + " suscpart" +
headerSuffix);
susceptibilityPartOut.writeToFile(outputDirPrefix + "mrpt-direct-suscpart-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (direct_susceptibility and not direct_susceptibility->empty()) {
DoubleMapWriter susceptibilityOut;
susceptibilityOut.setData(direct_susceptibility);
if (use_jackknife) susceptibilityOut.setErrors(direct_susceptibilityError);
susceptibilityOut.addHeaderText("Direct estimates of " + getObservableName() + " susceptibility");
if (use_jackknife) susceptibilityOut.addHeaderText("jackknife error estimation");
susceptibilityOut.addMeta("observable", "susc-" + getObservableName());
susceptibilityOut.addMeta("L", getSystemL());
susceptibilityOut.addMeta("N", getSystemN());
susceptibilityOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) susceptibilityOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
susceptibilityOut.addHeaderText(getControlParameterName()+"\t susc" + headerSuffix);
susceptibilityOut.writeToFile(outputDirPrefix + "mrpt-direct-susc-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (direct_binder and not direct_binder->empty()) {
DoubleMapWriter binderOut;
binderOut.setData(direct_binder);
if (use_jackknife) binderOut.setErrors(direct_binderError);
binderOut.addHeaderText("Direct estimates of " + getObservableName() + " binder parameter");
if (use_jackknife) binderOut.addHeaderText("jackknife error estimation");
binderOut.addMeta("observable", "binder-" + getObservableName());
binderOut.addMeta("L", getSystemL());
binderOut.addMeta("N", getSystemN());
binderOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) binderOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
binderOut.addHeaderText(getControlParameterName()+"\t binder" + headerSuffix);
binderOut.writeToFile(outputDirPrefix + "mrpt-direct-binder-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
if (direct_binderRatio and not direct_binderRatio->empty()) {
DoubleMapWriter binderRatioOut;
binderRatioOut.setData(direct_binderRatio);
if (use_jackknife) binderRatioOut.setErrors(direct_binderRatioError);
binderRatioOut.addHeaderText("Direct estimates of " + getObservableName() + " binder ratio parameter");
if (use_jackknife) binderRatioOut.addHeaderText("jackknife error estimation");
binderRatioOut.addMeta("observable", "binderRatio-" + getObservableName());
binderRatioOut.addMeta("L", getSystemL());
binderRatioOut.addMeta("N", getSystemN());
binderRatioOut.addMeta("controlParameterName", getControlParameterName());
if (use_jackknife) binderRatioOut.addMeta("jackknifeBlockcount", jackknifeBlocks);
binderRatioOut.addHeaderText(getControlParameterName()+"\t binderRatio" + headerSuffix);
binderRatioOut.writeToFile(outputDirPrefix + "mrpt-direct-binderRatio-" + getObservableName() + "-l-" + numToString(getSystemL()) + ".values");
}
}
void setSubsample(unsigned samplesSize) {
subsampleHowMuch = samplesSize;
}
void setOutputDirectory(const char *dir) {
string directory = dir;
if (directory == "") directory = ".";
outputDirPrefix = directory + "/";
}
void setInfoFilename(const char *filename) {
infoFilename = filename;
}
void setBins(unsigned bins) {
binCount = bins;
}
void setJackknife(bool useJackknife, unsigned blocks) {
use_jackknife = useJackknife;
jackknifeBlocks = blocks;
headerSuffix = (use_jackknife ? "\t error" : "");
}
void setQuiet(bool quiet) {
be_quiet = quiet;
}
void setMaxIterations(unsigned max_iterations) {
maxIterations = max_iterations;
}
void setTolerance(double tolerance) {
iterationTolerance = tolerance;
}
void init() {
destroy(mr);
energy = MapPtr(new Map());
specificHeat = MapPtr(new Map());
observable = MapPtr(new Map());
susceptibilityPart = MapPtr(new Map());
susceptibility = MapPtr(new Map());
binder = MapPtr(new Map());
binderRatio = MapPtr(new Map());
energyError = MapPtr(new Map());
specificHeatError = MapPtr(new Map());
observableError = MapPtr(new Map());
susceptibilityPartError = MapPtr(new Map());
susceptibilityError = MapPtr(new Map());
binderError = MapPtr(new Map());
binderRatioError = MapPtr(new Map());
direct_energy = MapPtr(new Map());
direct_specificHeat = MapPtr(new Map());
direct_observable = MapPtr(new Map());
direct_susceptibilityPart = MapPtr(new Map());
direct_susceptibility = MapPtr(new Map());
direct_binder = MapPtr(new Map());
direct_binderRatio = MapPtr(new Map());
direct_energyError = MapPtr(new Map());
direct_specificHeatError = MapPtr(new Map());
direct_observableError = MapPtr(new Map());
direct_susceptibilityPartError = MapPtr(new Map());
direct_susceptibilityError = MapPtr(new Map());
direct_binderError = MapPtr(new Map());
direct_binderRatioError = MapPtr(new Map());
mr = (use_jackknife ?
new MultireweightHistosPTJK(jackknifeBlocks, be_quiet ? dev_null : cout) :
new MultireweightHistosPT(be_quiet ? dev_null : cout));
mr->addSimulationInfo(infoFilename);
//TODO: currently command line arguments are the only way to specify
//input time series
for (unsigned arg = 0; arg < parser.number_of_arguments(); ++arg) {
switch (timeSeriesFormat) {
case COL1:
mr->addInputTimeSeries_singleColumn(parser[arg], subsampleHowMuch, discardSamples);
break;
case COL2:
mr->addInputTimeSeries_twoColumn(parser[arg], subsampleHowMuch, discardSamples);
break;
}
}
if (sortByCp) {
mr->sortTimeSeriesByControlParameter();
}
if (do_directEstimates) {
directResults();
}
if (discreteIsingBins) {
mr->createHistogramsIsing();
} else {
mr->createHistograms(binCount);
}
mr->saveH_km(outputDirPrefix + "Hkm.table");
if (crossCorr) {
mr->computeAndSaveHistogramCrossCorr();
}
if (crossCorrAlt) {
mr->computeAndSaveHistogramCrossCorrAlt();
}
if (use_jackknife) {
//TODO: ugly, ugly, ugly
dynamic_cast<MultireweightHistosPTJK*>(mr)->
saveH_km_errors(outputDirPrefix + "Hkm-errors.table");
}
mr->saveU_m(outputDirPrefix + "Um.table");
if (non_iterative) {
mr->findDensityOfStatesNonIteratively();
}
if (noTau) {
mr->setBinInefficienciesToUnity();
} else if (globalTau) {
mr->measureGlobalInefficiencies(autocorrPlots);
} else {
mr->measureBinInefficiencies(autocorrPlots);
}
if (saveTauInt) {
mr->writeOutEnergyTauInt("mrpt-tauint-energy.dat");
mr->writeOutObsTauInt("mrpt-tauint-" + mr->observable + ".dat");
}
mr->saveg_km(outputDirPrefix + "gkm.table");
mr->updateEffectiveCounts();
//those quantities are not really interesting:
// mr->saveNeff_lm(outputDirPrefix + "Nefflm.table");
// mr->saveNeff_l(outputDirPrefix + "Neffl.table");
if (zInFile != "") {
//load partition functions as starting point for iteration
mr->loadPartitionFunctions(zInFile);
}
if (maxIterations > 0) {
mr->findPartitionFunctionsAndDensityOfStates(iterationTolerance, maxIterations);
}
if (discreteIsingBins) {
mr->saveLogDensityOfStatesIsing(outputDirPrefix + "mrpt-dos.dat");
} else {
mr->saveLogDensityOfStates(outputDirPrefix + "mrpt-dos.dat");
}
if (zOutFile != "") {
mr->savePartitionFunctions(zOutFile);
}
}
void directResults() {
typedef MultireweightHistosPT::ResultsMap ResMap;
ResMap* results = mr->directNoReweighting();
for (ResMap::const_iterator iter = results->begin();
iter != results->end(); ++iter) {
double cp = iter->first;
ReweightingResult values = iter->second;
(*direct_energy)[cp] = values.energyAvg;
(*direct_specificHeat)[cp] = values.heatCapacity;
(*direct_observable)[cp] = values.obsAvg;
(*direct_susceptibilityPart)[cp] = values.obsSuscPart;
(*direct_susceptibility)[cp] = values.obsSusc;
(*direct_binder)[cp] = values.obsBinder;
(*direct_binderRatio)[cp] = values.obsBinderRatio;
if (use_jackknife) {
(*direct_energyError)[cp] = values.energyError;
(*direct_specificHeatError)[cp] = values.heatCapacityError;
(*direct_observableError)[cp] = values.obsError;
(*direct_susceptibilityPartError)[cp] = values.obsSuscPartError;
(*direct_susceptibilityError)[cp] = values.obsSuscError;
(*direct_binderError)[cp] = values.obsBinderError;
(*direct_binderRatioError)[cp] = values.obsBinderRatioError;
}
}
writeOutResults();
destroy(results);
}
//inline class somewhat like lambda function (restriction: can't access "auto" variables
//in containing function):
class ReweightAndHandle {
bool createHistograms;
public:
ReweightAndHandle(bool withHistograms = false) : createHistograms(withHistograms)
{ }
void operator()(double cp) {
ReweightingResult result = (
createHistograms ?
mr->reweightWithHistograms(cp, binCount) :
mr->reweight(cp));
(*energy)[cp] = result.energyAvg;
(*specificHeat)[cp] = result.heatCapacity;
(*observable)[cp] = result.obsAvg;
(*susceptibilityPart)[cp] = result.obsSuscPart;
(*susceptibility)[cp] = result.obsSusc;
(*binder)[cp] = result.obsBinder;
(*binderRatio)[cp] = result.obsBinderRatio;
if (use_jackknife) {
(*energyError)[cp] = result.energyError;
(*specificHeatError)[cp] = result.heatCapacityError;
(*observableError)[cp] = result.obsError;
(*susceptibilityPartError)[cp] = result.obsSuscPartError;
(*susceptibilityError)[cp] = result.obsSuscError;
(*binderError)[cp] = result.obsBinderError;
(*binderRatioError)[cp] = result.obsBinderRatioError;
}
if (createHistograms) {
result.energyHistogram->save("mrpt-energy-" + getControlParameterName() +
numToString(cp) + ".hist");
result.obsHistogram->save("mrpt-" + getObservableName() + "-" +
getControlParameterName() + numToString(cp) + ".hist");
}
result.freeMemory();
}
};
class ReweightAndHandleDiscrete {
bool createHistogram;
public:
ReweightAndHandleDiscrete(bool withHistogram = false) : createHistogram(withHistogram)
{ }
void operator()(double cp) {
ReweightingResult result =
mr->reweightDiscrete(cp);
(*energy)[cp] = result.energyAvg;
(*specificHeat)[cp] = result.heatCapacity;
if (use_jackknife) {
(*energyError)[cp] = result.energyError;
(*specificHeatError)[cp] = result.heatCapacityError;
}
if (createHistogram) {
result.energyHistogram = mr->reweightEnergyHistogram(cp);
result.energyHistogram->save("mrpt-energy-" + getControlParameterName()
+ numToString(cp) + ".hist");
}
result.freeMemory();
}
};
void reweight(double cp, bool createHistogramsToo) {
ReweightAndHandle reweight(createHistogramsToo);
reweight(cp);
writeOutResults();
}
void reweightDiscrete(double cp, bool createHistogramToo) {
ReweightAndHandleDiscrete reweight(createHistogramToo);
reweight(cp);
writeOutResults();
}
void reweightEnergyHistogram(double cp) {
HistogramDouble* histo = mr->reweightEnergyHistogram(cp);
histo->save("mrpt-energy-" + getControlParameterName()
+ numToString(cp) + ".hist");
destroy(histo);
}
void reweightObservableHistogram(double cp) {
HistogramDouble* histo = mr->reweightObservableHistogram(cp, binCount);
histo->save("mrpt-" + getObservableName() + "-" + getControlParameterName()
+ numToString(cp) + ".hist");
destroy(histo);
}
void reweightRange(double cpMin, double cpMax, double cpStep,
bool createHistogramsToo) {
ReweightAndHandle reweight(createHistogramsToo);
for (double cp = cpMin; cp <= cpMax; cp += cpStep) {
reweight(cp);
}
writeOutResults();
}
void reweightDiscreteRange(double cpMin, double cpMax, double cpStep, bool createHistogramsToo) {
ReweightAndHandleDiscrete reweight(createHistogramsToo);
for (double cp = cpMin; cp <= cpMax; cp += cpStep) {
reweight(cp);
}
writeOutResults();
}
void findMaxSusc(double cpStart, double cpEnd) {
double cpMax;
double suscMax;
double cpMaxError;
double suscMaxError;
if (not use_jackknife) {
mr->findMaxObservableSusceptibility(cpMax, suscMax,
*susceptibility,
cpStart, cpEnd);
} else {
//TODO: store evaluated points somewhere
vector<map<double,double> > v(jackknifeBlocks);
static_cast<MultireweightHistosPTJK*>(mr)->
findMaxObservableSusceptibility(cpMax, cpMaxError,
suscMax, suscMaxError,
*susceptibility, v,
cpStart, cpEnd);
}
HistogramDouble* histo = mr->
reweightObservableHistogram(cpMax, binCount);
histo->save(outputDirPrefix + "mrpt-max-susc.hist");
destroy(histo);
MetadataMap meta;
meta["L"] = numToString(mr->systemL);
meta["N"] = numToString(mr->systemN);
meta["systemSize"] = numToString(mr->systemSize);
meta[getControlParameterName()] = numToString(cpMax, 16);
meta["susc"] = numToString(suscMax, 16);
if (use_jackknife) {
meta[getControlParameterName() + "Error"] = numToString(cpMaxError, 16);
meta["suscError"] = numToString(suscMaxError, 16);
}
string comments = "Maximum of " + mr->observable + " susceptibility, from MRPT\n";
if (use_jackknife) {
comments += "Jackknife error estimation, blockCount: "
+ numToString(jackknifeBlocks) + "\n";
}
writeOnlyMetaData(outputDirPrefix + "mrpt-max-susc.dat", meta,
comments);
writeOutResults();
}
void findMinBinder(double cpStart, double cpEnd) {
double cpMin;
double binderMin;
double cpMinError;
double binderMinError;
if (not use_jackknife) {
mr->findMinBinder(cpMin, binderMin,
*binder,
cpStart, cpEnd);
} else {
//TODO: store evaluated points somewhere
vector<map<double,double> > v(jackknifeBlocks);
static_cast<MultireweightHistosPTJK*>(mr)->
findMinBinder(cpMin, cpMinError,
binderMin, binderMinError,
*binder, v, cpStart, cpEnd);
}
HistogramDouble* histo = mr->
reweightObservableHistogram(cpMin, binCount);
histo->save(outputDirPrefix + "mrpt-min-binder.hist");
destroy(histo);
MetadataMap meta;
meta["L"] = numToString(mr->systemL);
meta["N"] = numToString(mr->systemN);
meta["systemSize"] = numToString(mr->systemSize);
meta[getControlParameterName()] = numToString(cpMin, 16);
meta["binder"] = numToString(binderMin, 16);
if (use_jackknife) {
meta[getControlParameterName()+"Error"] = numToString(cpMinError, 16);
meta["binderError"] = numToString(binderMinError, 16);
}
string comments = "Minimum of " + mr->observable + " binder cumulant, from MRPT\n";
if (use_jackknife) {
comments += "Jackknife error estimation, blockCount: "
+ numToString(jackknifeBlocks) + "\n";
}
writeOnlyMetaData(outputDirPrefix + "mrpt-min-binder.dat", meta,
comments);
writeOutResults();
}
void findMaxSpecificHeat(double cpStart, double cpEnd) {
double cpMax;
double specificHeatMax;
double cpMaxError;
double specificHeatMaxError;
if (not use_jackknife) {
mr->findMaxSpecificHeatDiscrete(cpMax, specificHeatMax,
*specificHeat,
cpStart, cpEnd);
} else {
//TODO: store evaluated points somewhere
vector<map<double,double> > v(jackknifeBlocks);
static_cast<MultireweightHistosPTJK*>(mr)->
findMaxSpecificHeatDiscrete(cpMax, cpMaxError,
specificHeatMax, specificHeatMaxError,
*specificHeat, v,
cpStart, cpEnd);
}
HistogramDouble* histo = mr->reweightEnergyHistogram(cpMax);
histo->save(outputDirPrefix + "mrpt-max-heat-capacity.hist");
destroy(histo);
MetadataMap meta;
meta["L"] = numToString(mr->systemL);
meta["N"] = numToString(mr->systemN);
meta["systemSize"] = numToString(mr->systemSize);
meta[getControlParameterName()] = numToString(cpMax, 16);
meta["heatCapacity"] = numToString(specificHeatMax, 16);
if (use_jackknife) {
meta[getControlParameterName() + "Error"] = numToString(cpMaxError, 16);
meta["heatCapacityError"] = numToString(specificHeatMaxError, 16);
}
string comments = "Maximum of heat capacity, from MRPT\n";
if (use_jackknife) {
comments += "Jackknife error estimation, blockCount: "
+ numToString(jackknifeBlocks) + "\n";
}
writeOnlyMetaData(outputDirPrefix + "mrpt-heat-capacity.dat", meta,
comments);
writeOutResults();
}
void findEnergyDoublePeak(double cpStart, double cpEnd, double tolerance) {
double cpDoubleEH;
double relDipEH;
double cpDoubleErrorEH;