summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hadamard.cpp9
-rw-r--r--hadamard_mcmc.hpp15
-rw-r--r--hadamard_pt.hpp25
3 files changed, 23 insertions, 26 deletions
diff --git a/hadamard.cpp b/hadamard.cpp
index 86c27d8..a2c4199 100644
--- a/hadamard.cpp
+++ b/hadamard.cpp
@@ -2,9 +2,9 @@
#include "hadamard_pt.hpp"
#include "matrices.hpp"
+#include <chrono>
#include <fstream>
#include <iostream>
-#include <chrono>
class MeasureEnergy : public Measurement {
public:
@@ -44,8 +44,7 @@ public:
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 {
+ void after_step(bool accepted, unsigned i, double, double, const MCMC&, const MCMC&) override {
total_steps[i]++;
if (accepted)
nAccepted[i]++;
@@ -130,7 +129,9 @@ int main(int argc, char* argv[]) {
auto tag = std::chrono::high_resolution_clock::now();
- std::string filename = "hmm_" + std::to_string(n) + "_" + std::to_string(β₀) + "_" + std::to_string(β₁) + "_" + std::to_string(N) + "_" + std::to_string(tag.time_since_epoch().count()) + ".dat";
+ std::string filename = "hmm_" + std::to_string(n) + "_" + std::to_string(β₀) + "_" +
+ std::to_string(β₁) + "_" + std::to_string(N) + "_" +
+ std::to_string(tag.time_since_epoch().count()) + ".dat";
std::ofstream file(filename);
diff --git a/hadamard_mcmc.hpp b/hadamard_mcmc.hpp
index e64eacf..bb948de 100644
--- a/hadamard_mcmc.hpp
+++ b/hadamard_mcmc.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "randutils/randutils.hpp"
#include "pcg-cpp/include/pcg_random.hpp"
+#include "randutils/randutils.hpp"
#include <vector>
using Rng = randutils::random_generator<pcg32>;
@@ -21,9 +21,7 @@ public:
}
}
- Orthogonal(const std::vector<double>& x) : m(x) {
- d = sqrt(x.size());
- }
+ Orthogonal(const std::vector<double>& x) : m(x) { d = sqrt(x.size()); }
unsigned size() const { return d; }
@@ -54,8 +52,7 @@ private:
double Δθ;
public:
- Givens(Orthogonal& m, bool t, unsigned a1, unsigned a2, double θ0, Rng& rng)
- : m(m) {
+ Givens(Orthogonal& m, bool t, unsigned a1, unsigned a2, double θ0, Rng& rng) : m(m) {
transpose = t;
axis_1 = a1;
axis_2 = a2;
@@ -123,11 +120,7 @@ public:
virtual void after_sweep(double, double, const Orthogonal&){};
};
-typedef enum {
- none,
- up,
- down
-} color;
+typedef enum { none, up, down } color;
class MCMC {
private:
diff --git a/hadamard_pt.hpp b/hadamard_pt.hpp
index f07c9ec..593f1f2 100644
--- a/hadamard_pt.hpp
+++ b/hadamard_pt.hpp
@@ -1,8 +1,8 @@
#pragma once
#include "hadamard_mcmc.hpp"
-#include <list>
#include <execution>
+#include <list>
void swap(MCMC& s1, MCMC& s2) {
std::swap(s1.M, s2.M);
@@ -29,7 +29,8 @@ public:
ParallelMeasurement& B;
std::vector<Measurement*>& As;
- PT(double β₀, double β₁, unsigned N, unsigned n, ParallelMeasurement& B, std::vector<Measurement*>& As)
+ PT(double β₀, double β₁, unsigned N, unsigned n, ParallelMeasurement& B,
+ std::vector<Measurement*>& As)
: B(B), As(As) {
Ms.reserve(N);
for (unsigned i = 0; i < N; i++) {
@@ -38,9 +39,7 @@ public:
}
}
- double T(unsigned i) {
- return 1 / Ms[Ms.size() - i - 1].β;
- }
+ double T(unsigned i) { return 1 / Ms[Ms.size() - i - 1].β; }
bool step(unsigned i, unsigned j, bool dry = false) {
double Δβ = Ms[i].β - Ms[j].β;
@@ -69,7 +68,8 @@ public:
std::vector<unsigned> nd(Ms.size(), 0);
for (unsigned i = 0; i < n; i++) {
- std::for_each(std::execution::par_unseq, Ms.begin(), Ms.end(), [m, ε](MCMC& M) {M.tune(m, ε);});
+ std::for_each(std::execution::par_unseq, Ms.begin(), Ms.end(),
+ [m, ε](MCMC& M) { M.tune(m, ε); });
for (unsigned k = 0; k < m * Ms.size(); k++) {
unsigned j = rng.uniform((unsigned)0, (unsigned)(Ms.size() - 2));
@@ -104,14 +104,16 @@ public:
for (signed i = 0; i < f_keep.size() - 1; i++) {
for (unsigned j = f_keep[i]; j < f_keep[i + 1]; j++) {
- f[j] = f[f_keep[i]] + (f[f_keep[i + 1]] - f[f_keep[i]]) / (Ms[f_keep[i+1]].β - Ms[f_keep[i]].β) * (Ms[j].β - Ms[f_keep[i]].β);
+ f[j] = f[f_keep[i]] + (f[f_keep[i + 1]] - f[f_keep[i]]) /
+ (Ms[f_keep[i + 1]].β - Ms[f_keep[i]].β) *
+ (Ms[j].β - Ms[f_keep[i]].β);
}
}
std::vector<double> η(Ms.size() - 1);
for (unsigned i = 0; i < Ms.size() - 1; i++) {
- η[η.size() - i - 1] = sqrt((f[i + 1] - f[i])) / (1 / Ms[i].β - 1 / Ms[i+1].β);
+ η[η.size() - i - 1] = sqrt((f[i + 1] - f[i])) / (1 / Ms[i].β - 1 / Ms[i + 1].β);
}
double C = 0;
@@ -135,11 +137,11 @@ public:
double err = 0;
for (unsigned i = 0; i < T1.size(); i++) {
- err += fabs(T1[i] - 1/ Ms[Ms.size() - i - 2].β);
+ err += fabs(T1[i] - 1 / Ms[Ms.size() - i - 2].β);
Ms[Ms.size() - i - 2].β = 1 / T1[i];
}
- if (err / T1.size() * Ms.size() / (1/Ms.front().β - 1/Ms.back().β) < ε2) {
+ if (err / T1.size() * Ms.size() / (1 / Ms.front().β - 1 / Ms.back().β) < ε2) {
return f;
}
@@ -149,7 +151,8 @@ public:
void run(unsigned n, unsigned m, bool dry = false) {
for (unsigned i = 0; i < n; i++) {
- std::for_each(std::execution::par_unseq, Ms.begin(), Ms.end(), [m, dry](MCMC& M) {M.run(m, dry);});
+ std::for_each(std::execution::par_unseq, Ms.begin(), Ms.end(),
+ [m, dry](MCMC& M) { M.run(m, dry); });
for (unsigned j = 0; j < Ms.size(); j++) {
unsigned k = rng.uniform((unsigned)0, (unsigned)(Ms.size() - 2));
this->step(k, k + 1, dry);