summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 11:30:23 +0100
committerJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 11:30:23 +0100
commit541243f05f0830fab7dd874ce047bfe3bbe5cc4b (patch)
tree9b968f5ecb6202695abb978465be244bb5cfeb3d
parentc0cbb233d16306fec19c7c4325d61ae4b1248c1c (diff)
downloadcode-541243f05f0830fab7dd874ce047bfe3bbe5cc4b.tar.gz
code-541243f05f0830fab7dd874ce047bfe3bbe5cc4b.tar.bz2
code-541243f05f0830fab7dd874ce047bfe3bbe5cc4b.zip
Slightly better treatement of the global constant.
-rw-r--r--langevin.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/langevin.cpp b/langevin.cpp
index d704266..119a64b 100644
--- a/langevin.cpp
+++ b/langevin.cpp
@@ -13,13 +13,13 @@
#include "complex_normal.hpp"
#include "tensor.hpp"
-#define P_SPIN_P 3
-const unsigned p = P_SPIN_P;
+#define PSPIN_P 3
+const unsigned p = PSPIN_P; // polynomial degree of Hamiltonian
using Scalar = std::complex<double>;
using Vector = Eigen::VectorXcd;
using Matrix = Eigen::MatrixXcd;
-using Tensor = Eigen::Tensor<Scalar, p>;
+using Tensor = Eigen::Tensor<Scalar, PSPIN_P>;
using Rng = randutils::random_generator<pcg32>;
@@ -40,9 +40,11 @@ std::tuple<Scalar, Vector, Matrix> hamGradHess(const Tensor& J, const Vector& z)
Matrix Jz = contractDown(J, z);
Vector Jzz = Jz * z;
- Matrix hessian = ((p - 1) * (double)p / factorial(p)) * Jz;
- Vector gradient = ((double)p / factorial(p)) * Jzz;
- Scalar hamiltonian = (1.0 / factorial(p)) * Jzz.dot(z);
+ double f = factorial(p);
+
+ Matrix hessian = ((p - 1) * p / f) * Jz;
+ Vector gradient = (p / f) * Jzz;
+ Scalar hamiltonian = (1 / f) * Jzz.dot(z);
return {hamiltonian, gradient, hessian};
}
@@ -142,7 +144,7 @@ int main(int argc, char* argv[]) {
Rng r;
complex_normal_distribution<> d(0, σ, κ);
- Tensor J = generateCouplings<Scalar, p>(N, d, r.engine());
+ Tensor J = generateCouplings<Scalar, PSPIN_P>(N, d, r.engine());
Vector z = initializeVector(N, r);
std::function<bool(double, unsigned)> findSaddle = [δ](double W, unsigned) {