From 833e325c0a5531d07b9b9deed0201b26a5152e51 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 11 Dec 2019 09:50:13 -0500 Subject: added support in parallel tempering for specifying different densities of temperatures in different intervals --- hadamard.cpp | 4 +++- hadamard_pt.hpp | 18 +++++++++++++----- 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 void swap(MCMC& s1, MCMC& s2) { std::swap(s1.M, s2.M); @@ -13,6 +14,12 @@ public: virtual void after_sweep(const std::vector&){}; }; +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& As; - PT(double β0, double β1, unsigned N, unsigned n, ParallelMeasurement& B, + PT(std::list ranges, unsigned n, ParallelMeasurement& B, std::vector& 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])); + } } } -- cgit v1.2.3-54-g00ecf