summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2019-12-11 09:50:13 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2019-12-11 09:50:13 -0500
commit833e325c0a5531d07b9b9deed0201b26a5152e51 (patch)
treee1c61912bac359c60416bd9d36fab5a191cfca87
parentb967570eae9167e8bf353ab84b76d2d2039215d4 (diff)
downloadcode-833e325c0a5531d07b9b9deed0201b26a5152e51.tar.gz
code-833e325c0a5531d07b9b9deed0201b26a5152e51.tar.bz2
code-833e325c0a5531d07b9b9deed0201b26a5152e51.zip
added support in parallel tempering for specifying different densities of temperatures in different intervals
-rw-r--r--hadamard.cpp4
-rw-r--r--hadamard_pt.hpp18
2 files changed, 16 insertions, 6 deletions
diff --git a/hadamard.cpp b/hadamard.cpp
index b8ebdde..9364d3c 100644
--- a/hadamard.cpp
+++ b/hadamard.cpp
@@ -104,7 +104,9 @@ int main(int argc, char* argv[]) {
}
MeasureTransitionRates B(num);
- PT p(β0, βf, num, n, B, As);
+ range r = {β0, βf, num};
+
+ PT p({r}, n, B, As);
for (MCMC& sim : p.Ms) {
sim.M = walsh(k);
diff --git a/hadamard_pt.hpp b/hadamard_pt.hpp
index 404129c..744c866 100644
--- a/hadamard_pt.hpp
+++ b/hadamard_pt.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "hadamard_mcmc.hpp"
+#include <list>
void swap(MCMC& s1, MCMC& s2) {
std::swap(s1.M, s2.M);
@@ -13,6 +14,12 @@ public:
virtual void after_sweep(const std::vector<MCMC>&){};
};
+typedef struct range {
+ double β0;
+ double β1;
+ unsigned N;
+} range;
+
class PT {
private:
randutils::mt19937_rng rng;
@@ -22,13 +29,14 @@ public:
ParallelMeasurement& B;
std::vector<Measurement*>& As;
- PT(double β0, double β1, unsigned N, unsigned n, ParallelMeasurement& B,
+ PT(std::list<range> ranges, unsigned n, ParallelMeasurement& B,
std::vector<Measurement*>& As)
: B(B), As(As) {
- Ms.reserve(N);
- for (unsigned i = 0; i < N; i++) {
- double β = β0 + i * (β1 - β0) / (N - 1);
- Ms.push_back(MCMC(n, β, *As[i]));
+ for (range r : ranges) {
+ for (unsigned i = 0; i < r.N; i++) {
+ double β = r.β0 + i * (r.β1 - r.β0) / (r.N - 1);
+ Ms.push_back(MCMC(n, β, *As[i]));
+ }
}
}