summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2024-04-21 19:39:35 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2024-04-21 19:39:35 +0200
commit7f26af2a51348024f8977a0c64e95753d4e79d7c (patch)
tree42433ccba35d284fa6a3fc2c6a0678864a33c7bc
parent0bcd4de77521203444812eeb34862d2833256453 (diff)
downloadcode-7f26af2a51348024f8977a0c64e95753d4e79d7c.tar.gz
code-7f26af2a51348024f8977a0c64e95753d4e79d7c.tar.bz2
code-7f26af2a51348024f8977a0c64e95753d4e79d7c.zip
Removed some helper functions that were only used once.
-rw-r--r--least_squares.cpp23
1 files 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<Real, Vector> 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 {