From 7f26af2a51348024f8977a0c64e95753d4e79d7c Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 21 Apr 2024 19:39:35 +0200 Subject: Removed some helper functions that were only used once. --- least_squares.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/least_squares.cpp b/least_squares.cpp index 36bb1c3..49e9af7 100644 --- a/least_squares.cpp +++ b/least_squares.cpp @@ -36,22 +36,10 @@ Vector normalize(const Vector& x) { return x * sqrt(x.size() / x.squaredNorm()); } -Vector makeTangent(const Vector& v, const Vector& x) { - return v - (v.dot(x) / x.squaredNorm()) * x; -} - -Real HFromV(const Vector& V) { - return 0.5 * V.squaredNorm(); -} - Vector ∂HFromV∂V(const Vector& V, const Matrix& ∂V) { return V.transpose() * ∂V; } -Vector ∇HFromV∂Vx(const Vector& V, const Matrix& ∂V, const Vector& x) { - return makeTangent(∂HFromV∂V(V, ∂V), x); -} - Vector VFromABJx(const Vector& b, const Matrix& A, const Matrix& Jx, const Vector& x) { return b + (A + 0.5 * Jx) * x; } @@ -104,17 +92,14 @@ public: } Real getHamiltonian(const Vector& x) const { - return HFromV(VFromABJx(b, A, J * x, x)); + Vector V = VFromABJx(b, A, J * x, x); + return 0.5 * V.squaredNorm(); } Vector getGradient(const Vector& x) const { auto [V, ∂V, ∂∂V] = V_∂V_∂∂V(x); - return ∇HFromV∂Vx(V, ∂V, x); - } - - std::tuple getHamGrad(const Vector& x) const { - auto [V, ∂V, ∂∂V] = V_∂V_∂∂V(x); - return {HFromV(V), ∇HFromV∂Vx(V, ∂V, x)}; + Vector ∂H = ∂HFromV∂V(V, ∂V); + return ∂H - (∂H.dot(x) / x.squaredNorm()) * x; } Matrix getHessian(const Vector& x) const { -- cgit v1.2.3-70-g09d2