mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
Stablize the schur ordering algorithm.
The schur ordering is used to construct an elimination ordering for Schur type solvers when the user has not supplied an elimination ordering. The ordering algorithm does an ordered traversal of the sparsity graph of the Hessian. The order in which this is done used to be determined by the degree of the parameter blocks with ties broken arbitrarily using the memory address of the parameter blocks. This introduced non-determinism in the solver, causing subtle numerical differences in the value of the solution everytime the solve was run. This change introduces ComputeStableSchurOrdering which utilizes a new function StableIndependentSetOrdering. The latter takes as input an ordering of the vertices of the graph which is used to break ties when ordering the vertice by degree. The former constructs such an ordering by using the order in which the parameter blocks were added to the Problem. In this way, as long as the construction of the problem is deterministic, the schur ordering will always be deterministic too. I have chosen not to delete the existing unstable implementations of these functions as they are used by the inner iteration minimizer. Sometime in the near future I will clean up some of the duplicate code and see if we can move all the code to using a stable ordering. Change-Id: I8fbfa240d7307a2c3fe9b135f6968aa410d78780
This commit is contained in:
@@ -165,7 +165,7 @@ TEST(Degree2MaximumSpanningForest, StarGraph) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VertexDegreeLessThan, TotalOrdering) {
|
||||
TEST(VertexTotalOrdering, TotalOrdering) {
|
||||
Graph<int> graph;
|
||||
graph.AddVertex(0);
|
||||
graph.AddVertex(1);
|
||||
@@ -178,7 +178,7 @@ TEST(VertexDegreeLessThan, TotalOrdering) {
|
||||
// 0,1 and 2 have degree 1 and 3 has degree 2.
|
||||
graph.AddEdge(0, 1, 1.0);
|
||||
graph.AddEdge(2, 3, 1.0);
|
||||
VertexDegreeLessThan<int> less_than(graph);
|
||||
VertexTotalOrdering<int> less_than(graph);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
EXPECT_FALSE(less_than(i, i)) << "Failing vertex: " << i;
|
||||
@@ -196,5 +196,49 @@ TEST(VertexDegreeLessThan, TotalOrdering) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(StableIndependentSet, BreakTies) {
|
||||
Graph<int> graph;
|
||||
graph.AddVertex(0);
|
||||
graph.AddVertex(1);
|
||||
graph.AddVertex(2);
|
||||
graph.AddVertex(3);
|
||||
|
||||
graph.AddEdge(0, 1);
|
||||
graph.AddEdge(0, 2);
|
||||
graph.AddEdge(0, 3);
|
||||
graph.AddEdge(1, 2);
|
||||
graph.AddEdge(1, 3);
|
||||
graph.AddEdge(2, 3);
|
||||
|
||||
// Since this is a completely connected graph, the independent set
|
||||
// contains exactly one vertex. StableIndependentSetOrdering
|
||||
// guarantees that it will always be the first vertex in the
|
||||
// ordering vector.
|
||||
{
|
||||
vector<int> ordering;
|
||||
ordering.push_back(0);
|
||||
ordering.push_back(1);
|
||||
ordering.push_back(2);
|
||||
ordering.push_back(3);
|
||||
const int independent_set_size =
|
||||
StableIndependentSetOrdering(graph, &ordering);
|
||||
EXPECT_EQ(independent_set_size, 1);
|
||||
EXPECT_EQ(ordering[0], 0);
|
||||
}
|
||||
|
||||
{
|
||||
vector<int> ordering;
|
||||
ordering.push_back(1);
|
||||
ordering.push_back(0);
|
||||
ordering.push_back(2);
|
||||
ordering.push_back(3);
|
||||
const int independent_set_size =
|
||||
StableIndependentSetOrdering(graph, &ordering);
|
||||
EXPECT_EQ(independent_set_size, 1);
|
||||
EXPECT_EQ(ordering[0], 1);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace internal
|
||||
} // namespace ceres
|
||||
|
||||
Reference in New Issue
Block a user