diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-01-05 18:11:21 +0100 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2021-01-05 18:11:21 +0100 |
commit | 5ee6815f0734b2089c5b4c068cc21f2983bdba24 (patch) | |
tree | 179e2ec28f57662ce91491d79799270f2727b144 /p-spin.hpp | |
parent | 7c3e71970b6f2d48530bc2ab4fc0f2932522b98b (diff) | |
download | code-5ee6815f0734b2089c5b4c068cc21f2983bdba24.tar.gz code-5ee6815f0734b2089c5b4c068cc21f2983bdba24.tar.bz2 code-5ee6815f0734b2089c5b4c068cc21f2983bdba24.zip |
A lot of work, and fixed a huge bug regarding the meaning of .dot in the Eigen library for complex vectors.
Diffstat (limited to 'p-spin.hpp')
-rw-r--r-- | p-spin.hpp | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -24,7 +24,7 @@ std::tuple<Scalar, Vector, Matrix> 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<double, Vector> 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}; } |