StatMech
Loading...
Searching...
No Matches
RandomMatrices.hpp
Go to the documentation of this file.
1#ifndef RANDOM_MATRICES_HPP
2#define RANDOM_MATRICES_HPP
11#include "Eigen/Dense"
12#include <iostream>
13#include <random>
14
19template<typename RealType = double>
21 private:
22 std::mt19937 mt;
23 std::normal_distribution<RealType> Gaussian;
24 mutable unsigned long long count;
25
26 public:
32 GUEgenerator(int seed = 0, RealType stddev = 1.0)
33 : mt(seed), Gaussian{0.0, stddev}, count{0} {};
34
39 template<typename EigenMatrix>
40 void operator()(EigenMatrix& mat) {
41 mat = mat.NullaryExpr(mat.rows(), mat.cols(), [&]() {
42 return Complex_t<RealType>(Gaussian(mt), Gaussian(mt));
43 });
44 mat = (mat + mat.adjoint().eval()) / 2.0;
45 count += 2 * mat.size();
46 }
47
54 void status(void) const {
55 std::cout << "GUEgenerator.status()"
56 << "\n";
57 std::cout << "\tMean: " << Gaussian.mean() << "\n";
58 std::cout << "\tStddev: " << Gaussian.stddev() << "\n";
59 std::cout << "\tCount: " << this->count << std::endl;
60 }
61
67 void discard(unsigned long long num) {
68 for(auto j = 0; j < num; ++j) Gaussian(mt);
69 count += num;
70 }
71
79 template<typename EigenMatrix>
80 void discard(EigenMatrix const& mat, unsigned long long num) {
81 this->discard(num * 2 * mat.size());
82 }
83};
84
89template<typename RealType = double>
91 private:
92 std::mt19937 mt;
93 std::normal_distribution<RealType> Gaussian;
94 unsigned long long count;
95
96 public:
102 GOEgenerator(int seed = 0, RealType stddev = 1.0)
103 : mt(seed), Gaussian{0.0, stddev}, count{0} {};
104
109 template<typename EigenMatrix>
110 void operator()(EigenMatrix& res) {
111 res = res.NullaryExpr(res.rows(), res.cols(), [&]() { return Gaussian(mt); });
112 res = (res + res.transpose().eval()) / 2.0;
113 count += res.size();
114 }
115
122 void status(void) const {
123 std::cout << "GOEgenerator.status()"
124 << "\n";
125 std::cout << "\tMean: " << Gaussian.mean() << "\n";
126 std::cout << "\tStddev: " << Gaussian.stddev() << "\n";
127 std::cout << "\tCount: " << this->count << std::endl;
128 }
129
135 void discard(unsigned long long num) {
136 mt.discard(num);
137 count += num;
138 }
139
147 template<typename EigenMatrix>
148 void discard(EigenMatrix const& mat, unsigned long long num = 1) {
149 this->discard(num * mat.size());
150 }
151};
152
153#endif
Generator of matrices in the Gaussian Orthogonal Ensemble (GOE)
Definition RandomMatrices.hpp:90
void discard(EigenMatrix const &mat, unsigned long long num=1)
Discards instances of random matrices to advance internal states of the random number generator.
Definition RandomMatrices.hpp:148
void discard(unsigned long long num)
Discards random numbers to advance internal states of the random number generator.
Definition RandomMatrices.hpp:135
std::mt19937 mt
Definition RandomMatrices.hpp:92
std::normal_distribution< RealType > Gaussian
Definition RandomMatrices.hpp:93
void status(void) const
Show the current status of the generator.
Definition RandomMatrices.hpp:122
unsigned long long count
Definition RandomMatrices.hpp:94
GOEgenerator(int seed=0, RealType stddev=1.0)
Constructor.
Definition RandomMatrices.hpp:102
void operator()(EigenMatrix &res)
Generates an instance of a random matrix.
Definition RandomMatrices.hpp:110
Generator of matrices in the Gaussian Unitary Ensemble (GUE)
Definition RandomMatrices.hpp:20
void discard(unsigned long long num)
Discards random numbers to advance internal states of the random number generator.
Definition RandomMatrices.hpp:67
std::normal_distribution< RealType > Gaussian
Definition RandomMatrices.hpp:23
void operator()(EigenMatrix &mat)
Generates an instance of a random matrix.
Definition RandomMatrices.hpp:40
std::mt19937 mt
Definition RandomMatrices.hpp:22
GUEgenerator(int seed=0, RealType stddev=1.0)
Constructor.
Definition RandomMatrices.hpp:32
unsigned long long count
Definition RandomMatrices.hpp:24
void discard(EigenMatrix const &mat, unsigned long long num)
Discards instances of random matrices to advance internal states of the random number generator.
Definition RandomMatrices.hpp:80
void status(void) const
Show the current status of the generator.
Definition RandomMatrices.hpp:54