summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2019-12-21 15:51:57 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2019-12-21 15:51:57 -0500
commit47546b445b18cbc13892702cabd4c22968a9bde9 (patch)
tree71bbe199b78b488e34118ed0ae355baf5909b05c
parent5f947be0d1d4af7d777c6af569f8ce5ead1f76a4 (diff)
downloadcode-47546b445b18cbc13892702cabd4c22968a9bde9.tar.gz
code-47546b445b18cbc13892702cabd4c22968a9bde9.tar.bz2
code-47546b445b18cbc13892702cabd4c22968a9bde9.zip
now using random choice of pairs to swap instead of sweeping left to right
-rw-r--r--hadamard.cpp11
-rw-r--r--hadamard_pt.hpp16
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<unsigned> nAccepted;
- unsigned total_steps;
+ std::vector<unsigned> 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<MCMC>&) 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<MCMC>&){};
};
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<double> 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);
}
}
}