summaryrefslogtreecommitdiff
path: root/p-spin.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'p-spin.hpp')
-rw-r--r--p-spin.hpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/p-spin.hpp b/p-spin.hpp
index 13fbd98..480b3ca 100644
--- a/p-spin.hpp
+++ b/p-spin.hpp
@@ -21,6 +21,11 @@ std::tuple<Scalar, Vector<Scalar>, Matrix<Scalar>> hamGradHess(const Tensor<Scal
}
template <class Scalar>
+Vector<Scalar> normalize(const Vector<Scalar>& z) {
+ return z * sqrt((double)z.size() / (Scalar)(z.transpose() * z));
+}
+
+template <class Scalar>
Vector<Scalar> project(const Vector<Scalar>& z, const Vector<Scalar>& x) {
Scalar xz = x.transpose() * z;
return x - (xz / z.squaredNorm()) * z.conjugate();