summaryrefslogtreecommitdiff
path: root/complex_normal.hpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 10:59:51 +0100
committerJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 10:59:51 +0100
commit1c79cff86e5cfae48e00184842101a9678b89903 (patch)
tree02cdd0dc28542127a3276024f141869bd5404af7 /complex_normal.hpp
parent85d168276c10a42c16283bacc61391b82b9ee399 (diff)
downloadcode-1c79cff86e5cfae48e00184842101a9678b89903.tar.gz
code-1c79cff86e5cfae48e00184842101a9678b89903.tar.bz2
code-1c79cff86e5cfae48e00184842101a9678b89903.zip
Lots of work, refactoring.
Diffstat (limited to 'complex_normal.hpp')
-rw-r--r--complex_normal.hpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/complex_normal.hpp b/complex_normal.hpp
new file mode 100644
index 0000000..0819758
--- /dev/null
+++ b/complex_normal.hpp
@@ -0,0 +1,26 @@
+#pragma once
+#include <complex>
+#include <random>
+
+template <class T = double> class complex_normal_distribution {
+private:
+ std::normal_distribution<T> d;
+ double δx;
+ double δy;
+ std::complex<T> μ;
+ std::complex<T> eθ;
+
+public:
+ complex_normal_distribution(std::complex<T> μ, T σ, std::complex<T> κ) : μ(μ), d(0, σ / sqrt(2)) {
+ δx = sqrt(1 + std::abs(κ));
+ δy = sqrt(1 - std::abs(κ));
+ eθ = std::polar(1.0, std::arg(κ));
+ }
+
+ template <class Generator> std::complex<T> operator()(Generator& g) {
+ // First generate an axis-aligned complex number centered at the origin.
+ std::complex<T> z(d(g) * δx, d(g) * δy);
+ // Shift and rotate the number.
+ return μ + eθ * z;
+ }
+};