StatMech
Loading...
Searching...
No Matches
EstimateCredibility.cpp File Reference

Functions

int main (int argc, char **argv)
 

Variables

namespace filesystem = std::experimental::filesystem
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
27 {
28 if(argc != 3) {
29 std::cerr << "Usage: 1.This 2.Directory 3.Nsample\n";
30 std::exit(EX_USAGE);
31 }
32 constexpr int NMAX = 20;
33 Integer_t const Nsample = std::atoll(argv[2]);
34 std::string const baseDir(argv[1]);
35 std::string const OutDIR(baseDir+"/Output");
36 filesystem::create_directory(OutDIR);
37 std::cout << "Directory: " << baseDir << "\n";
38
39 std::string InFname(OutDIR+"/Stat_MaxFluc.txt");
40 std::ifstream InFs(InFname); checkIsFileOpen(InFs, InFname);
41 std::string line;
42 skip_header(InFs);
43 debug_print("# Input: " << InFname);
44
45 int n, Nmax=0, Nmin=NMAX;
46 double dtemp;
47 std::vector<double> Mean(NMAX+1, NAN), Stddev(NMAX+1, NAN);
48 std::vector<Integer_t> Ndata(NMAX+1, NAN);
49 try {
50 for(getline(InFs, line); !InFs.eof(); getline(InFs, line)) {
51 std::istringstream inStream(line);
52 inStream >> n;
53 inStream >> Mean[n] >> Stddev[n] >> dtemp >> Ndata[n];
54 Stddev[n] /= sqrt((double)Ndata[n]);
55 Nmax = (n > Nmax? n: Nmax);
56 Nmin = (n < Nmin? n: Nmin);
57 }
58 } catch(std::exception& e) {
59 if( !InFs.eof() )
60 std::cerr << "Error(" << InFs.eof() << InFs.fail() << InFs.bad() << "):" << e.what() << std::endl;
61 }
62 InFs.close();
63 for(n = Nmax;n >= Nmin; --n) {
64 std::cout << n << "\t" << Mean[n] << "\t" << Stddev[n] << std::endl;
65 }
66
67 bool flag;
68 std::vector<double> Rand(NMAX+1);
69 std::vector<double> ProbDec(NMAX,0.0), ProbInc(NMAX,0.0);
70 std::vector<double> ProbDecMax(NMAX,0.0), ProbIncMax(NMAX,0.0);
71 for(size_t sample = 0;sample < Nsample; ++sample) {
72 for(n = Nmin;n <= Nmax; ++n) Rand[n] = Mean[n] + Stddev[n]*Gaussian();
73 for(int mod=0; mod <= 1; ++mod) {
74 flag = true;
75 for(n = Nmax-2;n >= Nmin; --n) {
76 if(n%2 != mod) continue;
77 if(Rand[n]<Rand[n+2] || flag==false) flag = false;
78 else ProbDec[n] += 1.0/(double)Nsample;
79 if(Rand[n] > Rand[(Nmax/2)*2-mod]) ProbDecMax[n] += 1.0/(double)Nsample;
80 debug_print("# sample(" << sample << ") Rand[" << n+2 << "] = " << Rand[n+2]);
81 }
82 debug_print("# sample(" << sample << ") Rand[" << n << "] = " << Rand[n]);
83 debug_print("");
84
85 flag = true;
86 for(n = Nmax-2;n >= Nmin; --n) {
87 if(n%2 != mod) continue;
88 if(Rand[n]>Rand[n+2] || flag==false) flag = false;
89 else ProbInc[n] += 1.0/(double)Nsample;
90 if(Rand[n] < Rand[(Nmax/2)*2-mod]) ProbIncMax[n] += 1.0/(double)Nsample;
91 }
92 }
93 debug_print("");
94 }
95
96 std::string OutFname(OutDIR+"/Stat_MaxFluc_Credibitity.txt");
97 std::ofstream OutFs(OutFname); checkIsFileOpen(OutFs, OutFname);
98 OutFs << "# Nsample = " << Nsample << "\n";
99 OutFs << "# 1.Start 2.End 3.ProbDec 4.ProbInc 5.ProbDecMax 6.ProbIncMax\n";
100 for(int mod=0; mod <= 1; ++mod) {
101 for(n = Nmax-2;n >= Nmin; --n) {
102 if(n%2 != mod) continue;
103 OutFs << n << " "
104 << (Nmax/2)*2-mod << " "
105 << ProbDec[n] << " "
106 << ProbInc[n] << " "
107 << ProbDecMax[n] << " "
108 << ProbIncMax[n] << "\n";
109 }
110 OutFs << "\n";
111 }
112 OutFs.close();
113
114
115 return 0;
116}
Integer_t const NMAX
Definition OpErgodicity.cpp:13
bool checkIsFileOpen(std::ifstream &file, std::string const &filename)
Definition file_util.hpp:22
debug_print("# Determining GPU configuration.")
MKL_INT Integer_t
Definition mytypes.hpp:359

Variable Documentation

◆ filesystem

namespace filesystem = std::experimental::filesystem