summaryrefslogtreecommitdiff
path: root/hadamard_mcmc.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'hadamard_mcmc.hpp')
-rw-r--r--hadamard_mcmc.hpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/hadamard_mcmc.hpp b/hadamard_mcmc.hpp
index 5ef062f..9f0d8c0 100644
--- a/hadamard_mcmc.hpp
+++ b/hadamard_mcmc.hpp
@@ -156,7 +156,7 @@ public:
E = M.energy();
}
- bool step(Givens& g) {
+ bool step(Givens& g, bool dry = false) {
double ΔE = g.tryRotation();
bool accepted = ΔE < 0 || exp(-β * ΔE) > rng.uniform((double)0.0, 1.0);
@@ -166,11 +166,13 @@ public:
g.acceptRotation();
}
- A.after_step(accepted, g, θ0, E, ΔE, M);
+ if (!dry) {
+ A.after_step(accepted, g, θ0, E, ΔE, M);
+ }
return accepted;
}
- double sweep() {
+ double sweep(bool dry = false) {
unsigned total = 0;
unsigned accepted = 0;
@@ -179,9 +181,9 @@ public:
Givens g1(M, false, i, j, θ0, rng);
Givens g2(M, true, i, j, θ0, rng);
- if (this->step(g1))
+ if (this->step(g1, dry))
accepted++;
- if (this->step(g2))
+ if (this->step(g2, dry))
accepted++;
total += 2;
@@ -193,7 +195,7 @@ public:
void tune(unsigned N, double ε) {
for (unsigned i = 0; i < N; i++) {
- double ratio_accepted = this->sweep();
+ double ratio_accepted = this->sweep(true);
if (ratio_accepted > 0.5) {
θ0 *= 1 + ε;
} else {
@@ -202,10 +204,12 @@ public:
}
}
- void run(unsigned N) {
+ void run(unsigned N, bool dry = false) {
for (unsigned i = 0; i < N; i++) {
- this->sweep();
- A.after_sweep(θ0, E, M);
+ this->sweep(dry);
+ if (!dry) {
+ A.after_sweep(θ0, E, M);
+ }
}
}
};