From 199b129c08242be6a2726aae3c9918ca2f2484f7 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 15 Jan 2021 16:29:59 +0100 Subject: More changes. --- dynamics.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'dynamics.hpp') diff --git a/dynamics.hpp b/dynamics.hpp index 85eef71..b373659 100644 --- a/dynamics.hpp +++ b/dynamics.hpp @@ -92,26 +92,26 @@ Vector randomVector(unsigned N, Distribution d, Generator& r) { } template -std::tuple> langevin(const Tensor& J, const Vector& z0, double T, double γ, unsigned N, Distribution d, Generator& r) { +std::tuple> metropolis(const Tensor& J, const Vector& z0, + std::function&, const Vector&)>& energy, + double T, double γ, unsigned N, Distribution d, Generator& r) { Vector z = z0; - double W; - std::tie(W, std::ignore) = WdW(J, z); + double E = energy(J, z); std::uniform_real_distribution D(0, 1); for (unsigned i = 0; i < N; i++) { - Vector zNewTmp = z + randomVector(z.size(), d, r); + Vector zNewTmp = z + γ * randomVector(z.size(), d, r); Vector zNew = normalize(zNewTmp); - double WNew; - std::tie(WNew, std::ignore) = WdW(J, zNew); + double ENew = energy(J, zNew); - if (exp((W - WNew) / T) > D(r)) { + if (E - ENew > T * log(D(r))) { z = zNew; - W = WNew; + E = ENew; } } - return {W, z}; + return {E, z}; } -- cgit v1.2.3-54-g00ecf