2012-04-30 23:09:08 -07:00
|
|
|
// Ceres Solver - A fast non-linear least squares minimizer
|
2015-03-17 22:30:16 -07:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
|
// http://ceres-solver.org/
|
2012-04-30 23:09:08 -07:00
|
|
|
//
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
|
//
|
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
|
// * Neither the name of Google Inc. nor the names of its contributors may be
|
|
|
|
|
// used to endorse or promote products derived from this software without
|
|
|
|
|
// specific prior written permission.
|
|
|
|
|
//
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
//
|
|
|
|
|
// Author: sameeragarwal@google.com (Sameer Agarwal)
|
|
|
|
|
|
|
|
|
|
#ifndef CERES_INTERNAL_ITERATIVE_SCHUR_COMPLEMENT_SOLVER_H_
|
|
|
|
|
#define CERES_INTERNAL_ITERATIVE_SCHUR_COMPLEMENT_SOLVER_H_
|
|
|
|
|
|
2018-03-30 16:16:59 -07:00
|
|
|
#include <memory>
|
2020-09-20 21:45:24 +02:00
|
|
|
|
2022-02-07 23:43:19 +01:00
|
|
|
#include "ceres/internal/disable_warnings.h"
|
2012-04-30 23:09:08 -07:00
|
|
|
#include "ceres/internal/eigen.h"
|
2022-02-07 23:43:19 +01:00
|
|
|
#include "ceres/internal/export.h"
|
2020-09-20 21:45:24 +02:00
|
|
|
#include "ceres/linear_solver.h"
|
2012-04-30 23:09:08 -07:00
|
|
|
#include "ceres/types.h"
|
|
|
|
|
|
|
|
|
|
namespace ceres {
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
2013-04-24 11:58:24 -07:00
|
|
|
class BlockSparseMatrix;
|
2012-04-30 23:09:08 -07:00
|
|
|
class ImplicitSchurComplement;
|
2013-02-17 16:50:37 -08:00
|
|
|
class Preconditioner;
|
2012-04-30 23:09:08 -07:00
|
|
|
|
|
|
|
|
// This class implements an iterative solver for the linear least
|
2013-02-17 16:50:37 -08:00
|
|
|
// squares problems that have a bi-partite sparsity structure common
|
2012-04-30 23:09:08 -07:00
|
|
|
// to Structure from Motion problems.
|
|
|
|
|
//
|
|
|
|
|
// The algorithm used by this solver was developed in a series of
|
|
|
|
|
// papers - "Agarwal et al, Bundle Adjustment in the Large, ECCV 2010"
|
|
|
|
|
// and "Wu et al, Multicore Bundle Adjustment, submitted to CVPR
|
|
|
|
|
// 2011" at the Univeristy of Washington.
|
|
|
|
|
//
|
|
|
|
|
// The key idea is that one can run Conjugate Gradients on the Schur
|
|
|
|
|
// Complement system without explicitly forming the Schur Complement
|
|
|
|
|
// in memory. The heavy lifting for this is done by the
|
|
|
|
|
// ImplicitSchurComplement class. Not forming the Schur complement in
|
|
|
|
|
// memory and factoring it results in substantial savings in time and
|
|
|
|
|
// memory. Further, iterative solvers like this open up the
|
|
|
|
|
// possibility of solving the Newton equations in a non-linear solver
|
|
|
|
|
// only approximately and terminating early, thereby saving even more
|
|
|
|
|
// time.
|
|
|
|
|
//
|
|
|
|
|
// For the curious, running CG on the Schur complement is the same as
|
|
|
|
|
// running CG on the Normal Equations with an SSOR preconditioner. For
|
|
|
|
|
// a proof of this fact and others related to this solver please see
|
|
|
|
|
// the section on Domain Decomposition Methods in Saad's book
|
|
|
|
|
// "Iterative Methods for Sparse Linear Systems".
|
2022-02-17 17:06:49 -08:00
|
|
|
class CERES_NO_EXPORT IterativeSchurComplementSolver final
|
2020-01-28 12:09:30 -05:00
|
|
|
: public BlockSparseMatrixSolver {
|
2012-04-30 23:09:08 -07:00
|
|
|
public:
|
2022-02-20 02:22:17 +01:00
|
|
|
explicit IterativeSchurComplementSolver(LinearSolver::Options options);
|
2020-09-20 21:45:24 +02:00
|
|
|
IterativeSchurComplementSolver(const IterativeSchurComplementSolver&) =
|
|
|
|
|
delete;
|
2018-04-12 20:44:56 -07:00
|
|
|
void operator=(const IterativeSchurComplementSolver&) = delete;
|
|
|
|
|
|
2022-02-09 00:34:05 +01:00
|
|
|
~IterativeSchurComplementSolver() override;
|
2012-04-30 23:09:08 -07:00
|
|
|
|
|
|
|
|
private:
|
2020-09-20 21:45:24 +02:00
|
|
|
LinearSolver::Summary SolveImpl(BlockSparseMatrix* A,
|
|
|
|
|
const double* b,
|
|
|
|
|
const LinearSolver::PerSolveOptions& options,
|
|
|
|
|
double* x) final;
|
2012-04-30 23:09:08 -07:00
|
|
|
|
2017-05-31 19:44:23 -07:00
|
|
|
void CreatePreconditioner(BlockSparseMatrix* A);
|
2017-05-26 10:43:13 -07:00
|
|
|
|
2012-04-30 23:09:08 -07:00
|
|
|
LinearSolver::Options options_;
|
2018-03-30 16:16:59 -07:00
|
|
|
std::unique_ptr<internal::ImplicitSchurComplement> schur_complement_;
|
|
|
|
|
std::unique_ptr<Preconditioner> preconditioner_;
|
2012-04-30 23:09:08 -07:00
|
|
|
Vector reduced_linear_system_solution_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
} // namespace ceres
|
|
|
|
|
|
2022-02-07 23:43:19 +01:00
|
|
|
#include "ceres/internal/reenable_warnings.h"
|
|
|
|
|
|
2012-04-30 23:09:08 -07:00
|
|
|
#endif // CERES_INTERNAL_ITERATIVE_SCHUR_COMPLEMENT_SOLVER_H_
|