diff options
-rw-r--r-- | langevin.cpp | 19 | ||||
-rw-r--r-- | stereographic.hpp | 10 | ||||
-rw-r--r-- | tensor.hpp | 22 |
3 files changed, 30 insertions, 21 deletions
diff --git a/langevin.cpp b/langevin.cpp index dcf8c68..d704266 100644 --- a/langevin.cpp +++ b/langevin.cpp @@ -1,8 +1,8 @@ -#include <getopt.h> -#include <cstdlib> -#include <random> #include <complex> +#include <cstdlib> #include <functional> +#include <getopt.h> +#include <random> #include <eigen3/Eigen/Core> #include <eigen3/unsupported/Eigen/CXX11/Tensor> @@ -60,7 +60,8 @@ std::tuple<double, Vector> WdW(const Tensor& J, const Vector& z) { return {W, dW}; } -Vector langevin(const Tensor& J, const Vector& z0, double T, double γ0, std::function<bool(double, unsigned)> quit, Rng& r) { +Vector langevin(const Tensor& J, const Vector& z0, double T, double γ0, + std::function<bool(double, unsigned)> quit, Rng& r) { Vector z = z0; double W; @@ -97,13 +98,13 @@ Vector langevin(const Tensor& J, const Vector& z0, double T, double γ0, std::fu int main(int argc, char* argv[]) { // model parameters unsigned N = 10; // number of spins - double T = 1; // temperature - double Rκ = 1; // real part of distribution parameter - double Iκ = 0; // imaginary part of distribution parameter + double T = 1; // temperature + double Rκ = 1; // real part of distribution parameter + double Iκ = 0; // imaginary part of distribution parameter // simulation parameters - double δ = 1e-2; // threshold for determining saddle - double γ = 1e-2; // step size + double δ = 1e-2; // threshold for determining saddle + double γ = 1e-2; // step size unsigned t = 1000; // number of Langevin steps int opt; diff --git a/stereographic.hpp b/stereographic.hpp index 7a6b411..7dd871c 100644 --- a/stereographic.hpp +++ b/stereographic.hpp @@ -17,7 +17,7 @@ Vector stereographicToEuclidean(const Vector& ζ) { Vector euclideanToStereographic(const Vector& z) { unsigned N = z.size(); Vector ζ(N - 1); - + for (unsigned i = 0; i < N - 1; i++) { ζ(i) = z(i) / (sqrt(N) - z(N - 1)); } @@ -33,7 +33,7 @@ Matrix stereographicJacobian(const Vector& ζ) { for (unsigned i = 0; i < N - 1; i++) { for (unsigned j = 0; j < N - 1; j++) { - J(i, j) = - 4.0 * ζ(i) * ζ(j); + J(i, j) = -4.0 * ζ(i) * ζ(j); if (i == j) { J(i, j) += 2.0 * (1.0 + b); } @@ -55,7 +55,8 @@ Matrix stereographicMetric(const Vector& ζ) { for (unsigned i = 0; i < N; i++) { for (unsigned j = 0; j < N; j++) { - g(i, j) = 16.0 * (std::conj(ζ(i)) * ζ(j) * (1.0 + a) - std::real(std::conj(ζ(i) * ζ(j)) * (1.0 + b))); + g(i, j) = 16.0 * (std::conj(ζ(i)) * ζ(j) * (1.0 + a) - + std::real(std::conj(ζ(i) * ζ(j)) * (1.0 + b))); if (i == j) { g(i, j) += 4.0 * std::abs(1.0 + b); } @@ -66,7 +67,8 @@ Matrix stereographicMetric(const Vector& ζ) { return g; } -std::tuple<std::complex<double>, Vector, Matrix> stereographicHamGradHess(const Tensor3& J, const Vector& ζ) { +std::tuple<std::complex<double>, Vector, Matrix> stereographicHamGradHess(const Tensor3& J, + const Vector& ζ) { Vector grad; Matrix hess; @@ -2,13 +2,14 @@ #include <algorithm> #include <array> -#include <utility> #include <eigen3/unsupported/Eigen/CXX11/Tensor> +#include <utility> #include "factorial.hpp" template <class Scalar, unsigned p, std::size_t... Indices> -void setJ(Scalar z, Eigen::Tensor<Scalar, p>& J, const std::array<unsigned, p>& is, std::index_sequence<Indices...>) { +void setJ(Scalar z, Eigen::Tensor<Scalar, p>& J, const std::array<unsigned, p>& is, + std::index_sequence<Indices...>) { J(std::get<Indices>(is)...) = z; } @@ -20,7 +21,8 @@ Eigen::Tensor<Scalar, p> initializeJ(unsigned N, std::index_sequence<Indices...> } template <class Scalar, unsigned p, class Distribution, class Generator> -void populateCouplings(Eigen::Tensor<Scalar, p>& J, unsigned N, unsigned l, std::array<unsigned, p> is, Distribution d, Generator& r) { +void populateCouplings(Eigen::Tensor<Scalar, p>& J, unsigned N, unsigned l, + std::array<unsigned, p> is, Distribution d, Generator& r) { if (l == 0) { Scalar z = d(r); do { @@ -52,14 +54,18 @@ Eigen::Tensor<Scalar, p> generateCouplings(unsigned N, Distribution d, Generator } template <class Scalar> -Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> contractDown(const Eigen::Tensor<Scalar, 2>& J, const Eigen::Matrix<Scalar, Eigen::Dynamic, 1>& z) { - return Eigen::Map<const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>>(J.data(), z.size(), z.size()); +Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> +contractDown(const Eigen::Tensor<Scalar, 2>& J, const Eigen::Matrix<Scalar, Eigen::Dynamic, 1>& z) { + return Eigen::Map<const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>>(J.data(), z.size(), + z.size()); } template <class Scalar, int r> -Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> contractDown(const Eigen::Tensor<Scalar, r>& J, const Eigen::Matrix<Scalar, Eigen::Dynamic, 1>& z) { - Eigen::Tensor<Scalar, 1> zT = Eigen::TensorMap<Eigen::Tensor<const Scalar, 1>>(z.data(), {z.size()}); - std::array<Eigen::IndexPair<int>, 1> ip = {Eigen::IndexPair<int>(0,0)}; +Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> +contractDown(const Eigen::Tensor<Scalar, r>& J, const Eigen::Matrix<Scalar, Eigen::Dynamic, 1>& z) { + Eigen::Tensor<Scalar, 1> zT = + Eigen::TensorMap<Eigen::Tensor<const Scalar, 1>>(z.data(), {z.size()}); + std::array<Eigen::IndexPair<int>, 1> ip = {Eigen::IndexPair<int>(0, 0)}; Eigen::Tensor<Scalar, r - 1> Jz = J.contract(zT, ip); return contractDown(Jz, z); } |