From e5163658f659f6863ee4ef6473f9124884e7957c Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 11 Feb 2021 14:25:52 +0100 Subject: Added aging code. --- hmm_aging.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hmm_correlation.cpp | 8 ++-- 2 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 hmm_aging.cpp diff --git a/hmm_aging.cpp b/hmm_aging.cpp new file mode 100644 index 0000000..522dac6 --- /dev/null +++ b/hmm_aging.cpp @@ -0,0 +1,125 @@ + +#include "hadamard_mcmc.hpp" +#include "matrices.hpp" + +#include +#include +#include +#include + +std::string getFilename(unsigned n, double β1, double β2, double θ₀, unsigned m, unsigned s) { + auto tag = std::chrono::high_resolution_clock::now(); + return "aging_" + std::to_string(n) + "_" + std::to_string(β1) + "_" + std::to_string(β2) + "_" + + std::to_string(θ₀) + "_" + std::to_string(m) + "_" + std::to_string(s) + "_" + std::to_string(tag.time_since_epoch().count()) + ".dat"; +} + +class Correlation { + public: + Orthogonal M0; + std::list C; + + Correlation(const Orthogonal& M) : M0(M) {} + + void add(const Orthogonal& M) { + C.push_back(M0 * M); + } +}; + +class MeasureCorrelation : public Measurement { +public: + unsigned s; + unsigned n; + unsigned N; + std::list Cs; + + MeasureCorrelation(unsigned m, unsigned skip) : N(m), s(skip) { + n = 0; + } + + void after_sweep(double, double, const Orthogonal& M) override { + if (n % N == 0) { + Cs.push_back(Correlation(M)); + } + + if (n % s == 0) { + for (Correlation& C : Cs) { + C.add(M); + } + } + + n++; + } +}; + +int main(int argc, char* argv[]) { + // model parameters + unsigned n = 2; // matrix size over four + + // simulation settings + double β1 = 5; // temperature + double β2 = 15; // temperature + unsigned M = 1e4; // number of relaxation sweeps + unsigned N = 1e4; // number of measurement sweeps + unsigned m = 1e3; + unsigned s = 10; + double θ₀ = 0.05; // standard deviation of step size + + bool loadDataFromFile = false; + + int opt; + + while ((opt = getopt(argc, argv, "n:b:c:M:N:m:t:s:")) != -1) { + switch (opt) { + case 'n': + n = atoi(optarg); + break; + case 'b': + β1 = atof(optarg); + break; + case 'c': + β2 = atof(optarg); + break; + case 'M': + M = (unsigned)atof(optarg); + break; + case 'N': + N = (unsigned)atof(optarg); + break; + case 'm': + m = (unsigned)atof(optarg); + break; + case 't': + θ₀ = atof(optarg); + break; + case 's': + s = (unsigned)atof(optarg); + break; + default: + exit(1); + } + } + + MeasureCorrelation Q(m, s); + MCMC simulation(n, β1, Q, θ₀); + + simulation.run(M, true); + std::cout << "Finished initial relaxation at " << β1 << ", quenching to " << β2 << "." << std::endl; + + simulation.β = β2; + simulation.run(N * m); + + std::cout << "Finished simulation." << std::endl; + + std::string filename = getFilename(n, β1, β2, θ₀, m, s); + std::ofstream file(filename); + + for (const Correlation& C : Q.Cs) { + for (double x : C.C) { + file << x << " "; + } + file << std::endl; + } + + return 0; +} + diff --git a/hmm_correlation.cpp b/hmm_correlation.cpp index 80a6927..522367f 100644 --- a/hmm_correlation.cpp +++ b/hmm_correlation.cpp @@ -7,9 +7,9 @@ #include #include -std::string getFilename(unsigned n, double β, double θ₀, unsigned lag, unsigned skip) { +std::string getFilename(unsigned n, double β, double θ₀, unsigned m, unsigned lag, unsigned skip) { return "correlation_" + std::to_string(n) + "_" + std::to_string(β) + "_" + - std::to_string(θ₀) + "_" + std::to_string(lag) + "_" + std::to_string(skip) + std::to_string(θ₀) + "_" + std::to_string(m) + "_" + std::to_string(lag) + "_" + std::to_string(skip) + ".dat"; } @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) { MCMC simulation(n, β, Q, θ₀); if (loadDataFromFile) { - Q.Q.read(getFilename(n, β, θ₀, l, s)); + Q.Q.read(getFilename(n, β, θ₀, m, l, s)); std::cout << "Imported data from file, number of steps " << Q.Q.num_added() << "." << std::endl; } @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) { simulation.run(N); std::cout << "Finished simulation of " << β << ", writing output file." << std::endl; - std::string filename = getFilename(n, β, θ₀, l, s); + std::string filename = getFilename(n, β, θ₀, m, l, s); Q.Q.write(filename); return 0; -- cgit v1.2.3-54-g00ecf