forked from mortele/variational-monte-carlo-fys4411
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampler.cpp
69 lines (61 loc) · 2.19 KB
/
sampler.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
#include <memory>
#include <iostream>
#include <cmath>
#include <vector>
#include "system.h"
#include "sampler.h"
#include "particle.h"
#include "Hamiltonians/hamiltonian.h"
#include "WaveFunctions/wavefunction.h"
using std::cout;
using std::endl;
Sampler::Sampler(
unsigned int numberOfParticles,
unsigned int numberOfDimensions,
double stepLength,
unsigned int numberOfMetropolisSteps)
{
m_stepNumber = 0;
m_numberOfMetropolisSteps = numberOfMetropolisSteps;
m_numberOfParticles = numberOfParticles;
m_numberOfDimensions = numberOfDimensions;
m_energy = 0;
m_cumulativeEnergy = 0;
m_stepLength = stepLength;
m_numberOfAcceptedSteps = 0;
}
void Sampler::sample(bool acceptedStep, System* system) {
/* Here you should sample all the interesting things you want to measure.
* Note that there are (way) more than the single one here currently.
*/
auto localEnergy = system->computeLocalEnergy();
m_cumulativeEnergy += localEnergy;
m_stepNumber++;
m_numberOfAcceptedSteps += acceptedStep;
}
void Sampler::printOutputToTerminal(System& system) {
auto pa = system.getWaveFunctionParameters();
auto p = pa.size();
cout << endl;
cout << " -- System info -- " << endl;
cout << " Number of particles : " << m_numberOfParticles << endl;
cout << " Number of dimensions : " << m_numberOfDimensions << endl;
cout << " Number of Metropolis steps run : 10^" << std::log10(m_numberOfMetropolisSteps) << endl;
cout << " Step length used : " << m_stepLength << endl;
cout << " Ratio of accepted steps: " << ((double) m_numberOfAcceptedSteps) / ((double) m_numberOfMetropolisSteps) << endl;
cout << endl;
cout << " -- Wave function parameters -- " << endl;
cout << " Number of parameters : " << p << endl;
for (unsigned int i=0; i < p; i++) {
cout << " Parameter " << i+1 << " : " << pa.at(i) << endl;
}
cout << endl;
cout << " -- Results -- " << endl;
cout << " Energy : " << m_energy << endl;
cout << endl;
}
void Sampler::computeAverages() {
/* Compute the averages of the sampled quantities.
*/
m_energy = m_cumulativeEnergy / m_numberOfMetropolisSteps;
}