diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-11-08 23:19:54 +0100 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-11-08 23:19:54 +0100 |
commit | 54416465850a9280a121127e0b5301d97ad13a61 (patch) | |
tree | dd6cdf2fdb63e6dd268db45dfb7300a079041ebc /dynamics.hpp | |
parent | 6b42ce01cd289567a6109d831fe86a0667d18f37 (diff) | |
download | code-54416465850a9280a121127e0b5301d97ad13a61.tar.gz code-54416465850a9280a121127e0b5301d97ad13a61.tar.bz2 code-54416465850a9280a121127e0b5301d97ad13a61.zip |
Removed some unused files.
Diffstat (limited to 'dynamics.hpp')
-rw-r--r-- | dynamics.hpp | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/dynamics.hpp b/dynamics.hpp index 21afd30..7d04b1a 100644 --- a/dynamics.hpp +++ b/dynamics.hpp @@ -4,45 +4,7 @@ #include <eigen3/Eigen/LU> #include <random> -#include <iostream> - #include "p-spin.hpp" -#include "stereographic.hpp" - -class gradientDescentStallException: public std::exception { - virtual const char* what() const throw() { - return "Gradient descent stalled."; - } -}; - -template <class Real, class Scalar, int p> -std::tuple<Real, Vector<Scalar>> gradientDescent(const Tensor<Scalar, p>& J, const Vector<Scalar>& z0, Real ε, Real γ0 = 1, Real δγ = 2) { - Vector<Scalar> z = z0; - Real γ = γ0; - - auto [W, dW] = WdW(J, z); - - while (W > ε) { - Vector<Scalar> zNew = normalize(z - γ * dW.conjugate()); - - auto [WNew, dWNew] = WdW(J, zNew); - - if (WNew < W) { // If the step lowered the objective, accept it! - z = zNew; - W = WNew; - dW = dWNew; - γ = γ0; - } else { // Otherwise, shrink the step and try again. - γ /= δγ; - } - - if (γ < 1e-50) { - throw gradientDescentStallException(); - } - } - - return {W, z}; -} template <class Real, int p> Vector<Real> findMinimum(const Tensor<Real, p>& J, const Vector<Real>& z0, Real ε) { @@ -98,8 +60,6 @@ Vector<Scalar> findSaddle(const Tensor<Scalar, p>& J, const Vector<Scalar>& z0, std::tie(std::ignore, dH, ddH) = hamGradHess(J, z); - std::cout << "error : " << g.norm() / z.size() << std::endl; - zz = z.transpose() * z; g = dH - (z.transpose() * dH) * z / (Real)z.size() + z * (zz - (Real)z.size()); M = ddH - (dH * z.transpose() + (z.transpose() * dH) * Matrix<Scalar>::Identity(z.size(), z.size()) + (ddH * z) * z.transpose()) / (Real)z.size() + Matrix<Scalar>::Identity(z.size(), z.size()) * (zz - (Real)z.size()) + 2.0 * z * z.transpose(); @@ -119,30 +79,6 @@ Vector<Scalar> randomVector(unsigned N, Distribution d, Generator& r) { return z; } -template <class Real, class Scalar, int p, class Distribution, class Generator> -std::tuple<Real, Vector<Scalar>> metropolis(const Tensor<Scalar, p>& J, const Vector<Scalar>& z0, - std::function<Real(const Tensor<Scalar, p>&, const Vector<Scalar>&)>& energy, - Real T, Real γ, unsigned N, Distribution d, Generator& r) { - Vector<Scalar> z = z0; - - Real E = energy(J, z); - - std::uniform_real_distribution<Real> D(0, 1); - - for (unsigned i = 0; i < N; i++) { - Vector<Scalar> zNew = normalize(z + γ * randomVector<Scalar>(z.size(), d, r)); - - Real ENew = energy(J, zNew); - - if (E - ENew > T * log(D(r))) { - z = zNew; - E = ENew; - } - } - - return {E, z}; -} - template <class Real, int p, class Distribution, class Generator> Vector<Real> randomMinimum(const Tensor<Real, p>& J, Distribution d, Generator& r, Real ε) { Vector<Real> zSaddle; |