summaryrefslogtreecommitdiff
path: root/p-spin.hpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 18:11:21 +0100
committerJaron Kent-Dobias <jaron@kent-dobias.com>2021-01-05 18:11:21 +0100
commit5ee6815f0734b2089c5b4c068cc21f2983bdba24 (patch)
tree179e2ec28f57662ce91491d79799270f2727b144 /p-spin.hpp
parent7c3e71970b6f2d48530bc2ab4fc0f2932522b98b (diff)
downloadcode-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.hpp6
1 files changed, 3 insertions, 3 deletions
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<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};
}