summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2020-02-03 15:29:46 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2020-02-03 15:29:46 -0500
commit0b116ad92b7403989c2958c9c33e158049ecc6e1 (patch)
tree5cfcfe0904cb6d832d8257a6305f564f2d06fba7
parentdbee70fe5eb7abca31c01c046ec2174f2dde7665 (diff)
downloadcode-0b116ad92b7403989c2958c9c33e158049ecc6e1.tar.gz
code-0b116ad92b7403989c2958c9c33e158049ecc6e1.tar.bz2
code-0b116ad92b7403989c2958c9c33e158049ecc6e1.zip
replaced mersenne twister with pcg32
-rw-r--r--.gitmodules3
-rw-r--r--hadamard_mcmc.hpp9
-rw-r--r--hadamard_pt.hpp2
m---------pcg-cpp0
4 files changed, 10 insertions, 4 deletions
diff --git a/.gitmodules b/.gitmodules
index 94345fd..a14394b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
[submodule "randutils"]
path = randutils
url = https://gist.github.com/imneme/540829265469e673d045
+[submodule "pcg-cpp"]
+ path = pcg-cpp
+ url = https://github.com/imneme/pcg-cpp
diff --git a/hadamard_mcmc.hpp b/hadamard_mcmc.hpp
index bca8ae2..218f8d1 100644
--- a/hadamard_mcmc.hpp
+++ b/hadamard_mcmc.hpp
@@ -1,8 +1,11 @@
#pragma once
#include "randutils/randutils.hpp"
+#include "pcg-cpp/include/pcg_random.hpp"
#include <vector>
+using Rng = randutils::random_generator<pcg32>;
+
inline double Ei(double x) { return -fabs(x); }
class Orthogonal {
@@ -53,7 +56,7 @@ private:
std::vector<double> rows;
public:
- Givens(Orthogonal& m, bool t, unsigned a1, unsigned a2, double θ0, randutils::mt19937_rng& rng)
+ Givens(Orthogonal& m, bool t, unsigned a1, unsigned a2, double θ0, Rng& rng)
: m(m), rows(2 * m.size()) {
transpose = t;
axis_1 = a1;
@@ -61,7 +64,7 @@ public:
Δθ = rng.uniform(-θ0, θ0);
}
- Givens(Orthogonal& m, double θ0, randutils::mt19937_rng& rng) : m(m), rows(2 * m.size()) {
+ Givens(Orthogonal& m, double θ0, Rng& rng) : m(m), rows(2 * m.size()) {
Δθ = rng.uniform(-θ0, θ0);
unsigned axis1axis2 = rng.uniform((unsigned)0, m.size() * (m.size() - 1) - 1);
@@ -134,7 +137,7 @@ private:
double θ0;
public:
- randutils::mt19937_rng rng;
+ Rng rng;
double β;
double E;
Orthogonal M;
diff --git a/hadamard_pt.hpp b/hadamard_pt.hpp
index 7b53b92..8d0a1f7 100644
--- a/hadamard_pt.hpp
+++ b/hadamard_pt.hpp
@@ -21,7 +21,7 @@ typedef struct range {
class PT {
private:
- randutils::mt19937_rng rng;
+ Rng rng;
public:
std::vector<MCMC> Ms;
diff --git a/pcg-cpp b/pcg-cpp
new file mode 160000
+Subproject b263c73ec965ad515de8be8286086d78c67c2f0