From 5ee6815f0734b2089c5b4c068cc21f2983bdba24 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 5 Jan 2021 18:11:21 +0100 Subject: A lot of work, and fixed a huge bug regarding the meaning of .dot in the Eigen library for complex vectors. --- p-spin.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'p-spin.hpp') diff --git a/p-spin.hpp b/p-spin.hpp index 1ed4d8e..a522aee 100644 --- a/p-spin.hpp +++ b/p-spin.hpp @@ -24,7 +24,7 @@ std::tuple hamGradHess(const Tensor& J, const Vector& z) Matrix hessian = ((p - 1) * p / f) * Jz; Vector gradient = (p / f) * Jzz; - Scalar hamiltonian = (1 / f) * Jzz.dot(z); + Scalar hamiltonian = (1 / f) * Jzz.transpose() * z; return {hamiltonian, gradient, hessian}; } @@ -34,10 +34,10 @@ std::tuple WdW(const Tensor& J, const Vector& z) { Matrix hessian; std::tie(std::ignore, gradient, hessian) = hamGradHess(J, z); - Vector projectedGradient = gradient - (gradient.dot(z) / (double)z.size()) * z; + Vector projectedGradient = (gradient - ((Scalar)(gradient.transpose() * z) / (double)z.size()) * z).conjugate(); double W = projectedGradient.cwiseAbs2().sum(); - Vector dW = hessian.conjugate() * projectedGradient; + Vector dW = hessian * projectedGradient - ((z.transpose() * gradient) * projectedGradient + (z.transpose() * projectedGradient) * (gradient + hessian * z)) / (double)z.size(); return {W, dW}; } -- cgit v1.2.3-54-g00ecf