summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2024-04-21 11:55:57 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2024-04-21 11:55:57 +0200
commite468f5893425e8fc5b076739a8ce6a9d92528efa (patch)
treef71d31a1b589bf6aba87bc698986852d46527fd4
parent217e4390f0d83f3fecf4a4200f55b0ab0410c660 (diff)
downloadcode-e468f5893425e8fc5b076739a8ce6a9d92528efa.tar.gz
code-e468f5893425e8fc5b076739a8ce6a9d92528efa.tar.bz2
code-e468f5893425e8fc5b076739a8ce6a9d92528efa.zip
Made the calculation of the Hessian more compact and efficient.
-rw-r--r--least_squares.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/least_squares.cpp b/least_squares.cpp
index 49100b4..c0134d8 100644
--- a/least_squares.cpp
+++ b/least_squares.cpp
@@ -117,8 +117,8 @@ public:
auto [H, ∂H, ∂∂H] = H_∂H_∂∂H(x);
Vector ∇H = makeTangent(∂H, x);
- Matrix HessH = ∂∂H - (∂H * x.transpose() + x.dot(∂H) * Matrix::Identity(N, N)
- + (∂∂H * x) * x.transpose()) / (Real)N + 2.0 * x * x.transpose();
+ Matrix HessH = ∂∂H + (2 * x - (∂H + ∂∂H * x) / N) * x.transpose()
+ - (x.dot(∂H) / N) * Matrix::Identity(N, N);
return {H, ∇H, HessH};
}