From e468f5893425e8fc5b076739a8ce6a9d92528efa Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 21 Apr 2024 11:55:57 +0200 Subject: Made the calculation of the Hessian more compact and efficient. --- least_squares.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'least_squares.cpp') 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}; } -- cgit v1.2.3-70-g09d2