Add residuals and jacobian getters to TinySolver.

- Add methods to aceess the cached residuals and jacobian computed in
the optimization process in TinySolver. Usage of such methods will
retrieve the corresponding values associated with the converged
parameter.
- Reorder the Update() call to ensure that the jacobian/residuals
associated with the converged parameter are computed and cached.

Change-Id: If82e19d67d28b057833357f2c9a75b2d0fd139af
This commit is contained in:
connorlee77
2025-02-11 20:07:34 +00:00
parent c29b5257e2
commit 2c90a63af9
2 changed files with 20 additions and 3 deletions
+8
View File
@@ -121,6 +121,14 @@ void TestHelper(const Function& f, const Vector& x0) {
TinySolver<Function> solver;
solver.Solve(f, &x);
EXPECT_NEAR(0.0, solver.summary.final_cost, 1e-10);
// Getter methods for residuals and jacobian should match the corresponding
// values evaluated at the converged parameter value.
Vec2 expected_residuals;
Eigen::Matrix<double, 2, 3> expected_jacobian;
f(x.data(), expected_residuals.data(), expected_jacobian.data());
EXPECT_TRUE(expected_residuals.isApprox(solver.Residuals()));
EXPECT_TRUE(expected_jacobian.isApprox(solver.Jacobian()));
}
// A test case for when the cost function is statically sized.