summaryrefslogtreecommitdiff
path: root/p-spin.hpp
diff options
context:
space:
mode:
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};
}