From 2e375ce824d44531ba512cb7aed3bdae956abcf4 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 20 Mar 2025 07:33:47 -0300 Subject: Added Makefile and code to generate eigenvalues from actual matrix --- Makefile | 7 +++++++ walk.cpp | 27 +++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7e1ed7d --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: walk + +CC := clang++ -std=c++17 -Wno-mathematical-notation-identifier-extension -O3 -march=native -mtune=native + +walk: walk.cpp + $(CC) walk.cpp -o walk + diff --git a/walk.cpp b/walk.cpp index 2e22395..cd07253 100644 --- a/walk.cpp +++ b/walk.cpp @@ -5,11 +5,13 @@ #include "randutils/randutils.hpp" #include "eigen/Eigen/Dense" +#include "eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h" using Rng = randutils::random_generator; using Real = double; using Vector = Eigen::Matrix; +using Matrix = Eigen::Matrix; Vector normalizeVector(const Vector& x) { return x * sqrt(x.size() / x.squaredNorm()); @@ -54,9 +56,26 @@ private: public: unsigned N; - QuadraticModel(unsigned N, Rng& r) : J(N), N(N) { - for (Real& Jᵢ : J) { - Jᵢ = wignerInverse(r.uniform(0.0, 1.0)); + QuadraticModel(unsigned N, Rng& r, bool diag = false) : J(N), N(N) { + if (diag) { + Matrix Jtmp(N, N); + + for (unsigned j = 0; j < N; j++) { + for (unsigned i = j; i < N; i++) { + Jtmp(i, j) = r.variate(0, 1 / sqrt(N)); + Jtmp(j, i) = Jtmp(i, j); + } + } + + std::cerr << "Beginning diagonalization" << std::endl; + Eigen::SelfAdjointEigenSolver es; + es.compute(Jtmp); + J = es.eigenvalues(); + std::cerr << "Finished diagonalization" << std::endl; + } else { + for (Real& Jᵢ : J) { + Jᵢ = wignerInverse(r.uniform(0.0, 1.0)); + } } } @@ -142,7 +161,7 @@ int main(int argc, char* argv[]) { } Rng r; - QuadraticModel model(N, r); + QuadraticModel model(N, r, true); Vector x₀ = normalizeVector(randomVector(N, r)); x₀ = gradientDescent(model, x₀, E); -- cgit v1.2.3-70-g09d2