mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
Expose SubsetPreconditioner in the API
https://github.com/ceres-solver/ceres-solver/issues/270 Detailed list of changes: 1. Add SUBSET to the PreconditionerType enum. 2. Add Solver::Options::residual_blocks_for_subset_preconditioner 3. Integrate SubsetPreconditioner into the CGNR solver. 4. Add the reordering logic needed for this to TrustRegionPreprocessor. 5. Expect CreateJacobianBlockTranspose to take the starting row block so that we can work with subparts of the Jacobian matrix. 6. Extend the denoising example to use this preconditioner. As an illustration of its performance, we consider the performance of denoising -input ../data/ceres_noisy.pgm --foe_file ../data/5x5.foe tl;dr For the same cost, SPARSE_NORMAL_CHOLESKY - 81s CGNR + JACOBI - 718s CGNR + SUBSET - 57s SPARSE_NORMAL_CHOLESKY ====================== Cost: Initial 2.317806e+05 Final 2.232323e+04 Change 2.094574e+05 Minimizer iterations 10 Successful steps 10 Unsuccessful steps 0 Time (in seconds): Preprocessor 2.999746 Residual only evaluation 2.306811 (10) Jacobian & residual evaluation 7.421727 (10) Linear solver 65.517273 (10) Minimizer 78.731011 Postprocessor 0.026079 Total 81.756836 Termination: CONVERGENCE (Function tolerance reached. |cost_change|/cost: 8.573046e-04 <= 1.000000e-03) CGNR + JACOBI ============= Cost: Initial 2.317806e+05 Final 2.232344e+04 Change 2.094572e+05 Minimizer iterations 10 Successful steps 10 Unsuccessful steps 0 Time (in seconds): Preprocessor 0.648814 Residual only evaluation 2.297607 (10) Jacobian & residual evaluation 7.327886 (10) Linear solver 699.601248 (10) Minimizer 712.419493 Postprocessor 0.024014 Total 713.092321 Termination: CONVERGENCE (Function tolerance reached. |cost_change|/cost: 8.528538e-04 <= 1.000000e-03) CGNR + SUBSET (random 20% residuals used for the preconditioner) =============================================================== Cost: Initial 2.317806e+05 Final 2.232327e+04 Change 2.094574e+05 Minimizer iterations 10 Successful steps 10 Unsuccessful steps 0 Time (in seconds): Preprocessor 1.472743 Residual only evaluation 2.428315 (10) Jacobian & residual evaluation 7.367796 (10) Linear solver 42.585999 (10) Minimizer 55.664459 Postprocessor 0.024098 Total 57.161301 Termination: CONVERGENCE (Function tolerance reached. |cost_change|/cost: 8.538277e-04 <= 1.000000e-03) Change-Id: Ifb011408bd53edbb9439b0b7345649a38f999e18
This commit is contained in:
+35
-34
@@ -153,47 +153,38 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.sparse_linear_algebra_library_type == NO_SPARSE) {
|
||||
const char* error_template =
|
||||
"Can't use %s with "
|
||||
"Solver::Options::sparse_linear_algebra_library_type = NO_SPARSE.";
|
||||
const char* name = nullptr;
|
||||
|
||||
if (options.linear_solver_type == SPARSE_NORMAL_CHOLESKY ||
|
||||
options.linear_solver_type == SPARSE_SCHUR) {
|
||||
name = LinearSolverTypeToString(options.linear_solver_type);
|
||||
} else if (options.linear_solver_type == ITERATIVE_SCHUR &&
|
||||
(options.preconditioner_type == CLUSTER_JACOBI ||
|
||||
options.preconditioner_type == CLUSTER_TRIDIAGONAL)) {
|
||||
name = PreconditionerTypeToString(options.preconditioner_type);
|
||||
}
|
||||
|
||||
if (name != nullptr) {
|
||||
*error = StringPrintf(error_template, name);
|
||||
return false;
|
||||
}
|
||||
} else if (!IsSparseLinearAlgebraLibraryTypeAvailable(
|
||||
options.sparse_linear_algebra_library_type)) {
|
||||
const char* error_template =
|
||||
"Can't use %s with "
|
||||
"Solver::Options::sparse_linear_algebra_library_type = %s, "
|
||||
"because support was not enabled when Ceres Solver was built.";
|
||||
{
|
||||
const char* sparse_linear_algebra_library_name =
|
||||
SparseLinearAlgebraLibraryTypeToString(
|
||||
options.sparse_linear_algebra_library_type);
|
||||
const char* name = nullptr;
|
||||
if (options.linear_solver_type == SPARSE_NORMAL_CHOLESKY ||
|
||||
options.linear_solver_type == SPARSE_SCHUR) {
|
||||
name = LinearSolverTypeToString(options.linear_solver_type);
|
||||
} else if (options.linear_solver_type == ITERATIVE_SCHUR &&
|
||||
(options.preconditioner_type == CLUSTER_JACOBI ||
|
||||
options.preconditioner_type == CLUSTER_TRIDIAGONAL)) {
|
||||
} else if ((options.linear_solver_type == ITERATIVE_SCHUR &&
|
||||
(options.preconditioner_type == CLUSTER_JACOBI ||
|
||||
options.preconditioner_type == CLUSTER_TRIDIAGONAL)) ||
|
||||
(options.linear_solver_type == CGNR &&
|
||||
options.preconditioner_type == SUBSET)) {
|
||||
name = PreconditionerTypeToString(options.preconditioner_type);
|
||||
}
|
||||
|
||||
if (name != nullptr) {
|
||||
*error = StringPrintf(error_template,
|
||||
name,
|
||||
SparseLinearAlgebraLibraryTypeToString(
|
||||
options.sparse_linear_algebra_library_type));
|
||||
return false;
|
||||
if (name) {
|
||||
if (options.sparse_linear_algebra_library_type == NO_SPARSE) {
|
||||
*error = StringPrintf(
|
||||
"Can't use %s with "
|
||||
"Solver::Options::sparse_linear_algebra_library_type = %s.",
|
||||
name, sparse_linear_algebra_library_name);
|
||||
return false;
|
||||
} else if (!IsSparseLinearAlgebraLibraryTypeAvailable(
|
||||
options.sparse_linear_algebra_library_type)) {
|
||||
*error = StringPrintf(
|
||||
"Can't use %s with "
|
||||
"Solver::Options::sparse_linear_algebra_library_type = %s, "
|
||||
"because support was not enabled when Ceres Solver was built.",
|
||||
name, sparse_linear_algebra_library_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +217,16 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.linear_solver_type == CGNR &&
|
||||
options.preconditioner_type == SUBSET &&
|
||||
options.residual_blocks_for_subset_preconditioner.size() == 0) {
|
||||
*error =
|
||||
"When using SUBSET preconditioner, "
|
||||
"Solver::Options::residual_blocks_for_subset_preconditioner cannot be "
|
||||
"empty";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user