-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SymForce] Add test for LinearDeltaError
Also stores the update in the stats when debug_stats is on, makes the stored residual and jacobian double precision, and clarifies when some of the debug stats are present. Topic: sf-linear-test GitOrigin-RevId: 841fc05473dd8b68123efd8d528237d65db45965
- Loading branch information
1 parent
bd7c210
commit e5b6b7e
Showing
12 changed files
with
194 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* ---------------------------------------------------------------------------- | ||
* SymForce - Copyright 2022, Skydio, Inc. | ||
* This source code is under the Apache 2.0 license found in the LICENSE file. | ||
* ---------------------------------------------------------------------------- */ | ||
|
||
#pragma once | ||
|
||
#include <catch2/catch_approx.hpp> | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
#include <symforce/opt/optimization_stats.h> | ||
|
||
namespace sym { | ||
|
||
/// Check that the linear error in the optimization stats matches the linear error computed from the | ||
/// Jacobian | ||
/// | ||
/// Use from tests, adds Catch2 checks. Requires debug_stats and include_jacobians to be turned on. | ||
template <typename OptimizationStats> | ||
void CheckLinearError(const OptimizationStats& stats) { | ||
const sym::optimization_iteration_t* last_accepted_iteration = &stats.iterations.at(0); | ||
for (int i = 1; i < static_cast<int>(stats.iterations.size()); ++i) { | ||
const auto& iteration = stats.iterations.at(i); | ||
|
||
const auto J = stats.JacobianView(*last_accepted_iteration).template cast<double>().eval(); | ||
CAPTURE(J); | ||
const Eigen::VectorXd new_residual = J * iteration.update + last_accepted_iteration->residual; | ||
|
||
const auto new_cost = 0.5 * new_residual.squaredNorm(); | ||
|
||
CAPTURE(i, last_accepted_iteration->iteration - 1); | ||
CHECK(new_cost == Catch::Approx(iteration.new_error_linear).epsilon(1e-6)); | ||
|
||
if (iteration.update_accepted) { | ||
last_accepted_iteration = &iteration; | ||
} | ||
} | ||
} | ||
|
||
} // namespace sym |
Oops, something went wrong.