From 0b116ad92b7403989c2958c9c33e158049ecc6e1 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 3 Feb 2020 15:29:46 -0500 Subject: replaced mersenne twister with pcg32 --- .gitmodules | 3 +++ hadamard_mcmc.hpp | 9 ++++++--- hadamard_pt.hpp | 2 +- pcg-cpp | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) create mode 160000 pcg-cpp 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 +using Rng = randutils::random_generator; + inline double Ei(double x) { return -fabs(x); } class Orthogonal { @@ -53,7 +56,7 @@ private: std::vector 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 Ms; diff --git a/pcg-cpp b/pcg-cpp new file mode 160000 index 0000000..b263c73 --- /dev/null +++ b/pcg-cpp @@ -0,0 +1 @@ +Subproject commit b263c73ec965ad515de8be8286086d78c67c2f01 -- cgit v1.2.3-70-g09d2