From 47546b445b18cbc13892702cabd4c22968a9bde9 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sat, 21 Dec 2019 15:51:57 -0500 Subject: now using random choice of pairs to swap instead of sweeping left to right --- hadamard.cpp | 11 ++++------- hadamard_pt.hpp | 16 ++++------------ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/hadamard.cpp b/hadamard.cpp index 2f45dcc..d9e5bfd 100644 --- a/hadamard.cpp +++ b/hadamard.cpp @@ -35,19 +35,16 @@ public: class MeasureTransitionRates : public ParallelMeasurement { public: std::vector nAccepted; - unsigned total_steps; + std::vector total_steps; - MeasureTransitionRates(unsigned n) : nAccepted(n - 1, 0) { - total_steps = 0; - } + MeasureTransitionRates(unsigned n) : nAccepted(n - 1, 0), total_steps(n - 1, 0) {} void after_step(bool accepted, unsigned i, double, double, const MCMC&, const MCMC&) override { + total_steps[i]++; if (accepted) nAccepted[i]++; } - - void after_sweep(const std::vector&) override { total_steps++; } }; int main(int argc, char* argv[]) { @@ -139,7 +136,7 @@ int main(int argc, char* argv[]) { file << std::endl; for (unsigned i = 0; i < B.nAccepted.size(); i++) { - file << std::fixed << B.nAccepted[i] / (double)B.total_steps << " "; + file << std::fixed << B.nAccepted[i] / (double)B.total_steps[i] << " "; } file << std::endl; diff --git a/hadamard_pt.hpp b/hadamard_pt.hpp index 67cb710..9365e50 100644 --- a/hadamard_pt.hpp +++ b/hadamard_pt.hpp @@ -11,7 +11,6 @@ void swap(MCMC& s1, MCMC& s2) { class ParallelMeasurement { public: virtual void after_step(bool, unsigned, double, double, const MCMC&, const MCMC&){}; - virtual void after_sweep(const std::vector&){}; }; typedef struct range { @@ -57,13 +56,6 @@ public: return accepted; } - void sweep(bool dry = false) { - - for (unsigned i = 0; i < Ms.size() - 1; i++) { - this->step(i, i + 1, dry); - } - } - std::vector tune(unsigned n0, unsigned m, double ε, double ε2) { unsigned n = n0; @@ -82,7 +74,7 @@ public: } for (unsigned k = 0; k < m * Ms.size() - 1; k++) { - unsigned j = Ms[0].rng.uniform((unsigned)0, (unsigned)(Ms.size() - 2)); + unsigned j = rng.uniform((unsigned)0, (unsigned)(Ms.size() - 2)); if (this->step(j, j + 1, true)) { std::swap(colors[j], colors[j + 1]); @@ -165,9 +157,9 @@ public: for (unsigned j = 0; j < Ms.size(); j++) { Ms[j].run(m, dry); } - this->sweep(dry); - if (!dry) { - B.after_sweep(this->Ms); + for (unsigned j = 0; j < Ms.size() * m; j++) { + unsigned k = rng.uniform((unsigned)0, (unsigned)(Ms.size() - 2)); + this->step(k, k + 1, dry); } } } -- cgit v1.2.3-54-g00ecf