My Project
Loading...
Searching...
No Matches
lambda.h
1void Initialize_WangLandauIteration(LAMBDA& lambda);
2void Sample_WangLandauIteration(LAMBDA& lambda);
3void Finalize_WangLandauIteration(LAMBDA& lambda);
4void Adjust_WangLandauIteration(LAMBDA& lambda);
5
6double get_lambda(LAMBDA& lambda);
7int selectNewBin(LAMBDA& lambda);
8
9void Initialize_WangLandauIteration(LAMBDA& lambda)
10{
11 lambda.WangLandauScalingFactor = 1.0;
12 std::fill(lambda.Histogram.begin(), lambda.Histogram.end(), 0.0);
13 std::fill(lambda.biasFactor.begin(), lambda.biasFactor.end(), 0.0);
14 printf("Initialize WL\n");
15}
16
17void Sample_WangLandauIteration(LAMBDA& lambda)
18{
19 //printf("Before Update: bin %zu, Factor: %.5f\n", lambda.currentBin, lambda.biasFactor[lambda.currentBin]);
20 lambda.biasFactor[lambda.currentBin] -= lambda.WangLandauScalingFactor;
21 //printf("Current Bias for %zu bin: %.5f, WL Factor: %.5f\n", lambda.currentBin, lambda.biasFactor[lambda.currentBin], lambda.WangLandauScalingFactor);
22 lambda.Histogram[lambda.currentBin] += 1.0;
23
24 //printf("Total Bin: %zu\n", lambda.biasFactor.size());
25 //for(size_t i = 0; i < lambda.biasFactor.size(); i++)
26 // printf("Bin %zu, Factor: %.5f\n", i, lambda.biasFactor[i]);
27}
28
29void Adjust_WangLandauIteration(LAMBDA& lambda)
30{
31 //Checking for flatness criteria//
32 std::vector<double>::iterator minValueIterator = std::min_element(lambda.Histogram.begin(), lambda.Histogram.end());
33 double minimumValue = *minValueIterator;
34 //printf("Min Histogram Value: %.5f\n", minimumValue);
35 if(minimumValue>0.01 && lambda.WangLandauScalingFactor > 1e-3)
36 {
37 //printf("Adjusting WL Factor!\n");
38 double sumOfHistogram = std::accumulate(lambda.Histogram.begin(), lambda.Histogram.end(), 0.0);
39 if(minimumValue / sumOfHistogram > 0.01)
40 {
41 lambda.WangLandauScalingFactor *= 0.5;
42 }
43 }
44 std::fill(lambda.Histogram.begin(), lambda.Histogram.end(), 0.0);
45 //printf("Adjusting WL Factor: %.5f\n", lambda.WangLandauScalingFactor);
46}
47
48void Finalize_WangLandauIteration(LAMBDA& lambda)
49{
50 //std::fill(lambda.Histogram.begin(), lambda.Histogram.end(), 0.0);
51
52 double normalize = lambda.biasFactor[0];
53 for(double &bias : lambda.biasFactor)
54 {
55 bias -= normalize;
56 }
57 printf("Finalize WL\n");
58}
59
60inline double get_lambda(LAMBDA& lambda)
61{
62 return static_cast<double>(lambda.currentBin) * lambda.delta;
63}
64
65inline int selectNewBin(LAMBDA& lambda)
66{
67 return lambda.currentBin + static_cast<int>(static_cast<double>(lambda.binsize) * (Get_Uniform_Random() - 0.5));
68}
69
70inline int selectNewBinTMMC(LAMBDA& lambda)
71{
72 //Think about whether the code can stay at the same bin//
73 //Staying at the same bin may help the WL biasing//
74 int delta = 1; if(Get_Uniform_Random() < 0.5) delta = -1;
75 return lambda.currentBin + delta;
76}
Definition data_struct.h:73