summaryrefslogtreecommitdiff
path: root/hmm_aging.cpp
blob: 522dac60143a2010357f7107567a54aff0c1241b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

#include "hadamard_mcmc.hpp"
#include "matrices.hpp"

#include <chrono>
#include <fstream>
#include <iostream>
#include <list>

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<double> 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<Correlation> 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;
}