Blame internal/ceres/schur_jacobi_preconditioner.h

Packit ea1746
// Ceres Solver - A fast non-linear least squares minimizer
Packit ea1746
// Copyright 2015 Google Inc. All rights reserved.
Packit ea1746
// http://ceres-solver.org/
Packit ea1746
//
Packit ea1746
// Redistribution and use in source and binary forms, with or without
Packit ea1746
// modification, are permitted provided that the following conditions are met:
Packit ea1746
//
Packit ea1746
// * Redistributions of source code must retain the above copyright notice,
Packit ea1746
//   this list of conditions and the following disclaimer.
Packit ea1746
// * Redistributions in binary form must reproduce the above copyright notice,
Packit ea1746
//   this list of conditions and the following disclaimer in the documentation
Packit ea1746
//   and/or other materials provided with the distribution.
Packit ea1746
// * Neither the name of Google Inc. nor the names of its contributors may be
Packit ea1746
//   used to endorse or promote products derived from this software without
Packit ea1746
//   specific prior written permission.
Packit ea1746
//
Packit ea1746
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit ea1746
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit ea1746
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit ea1746
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit ea1746
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit ea1746
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit ea1746
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit ea1746
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit ea1746
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit ea1746
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit ea1746
// POSSIBILITY OF SUCH DAMAGE.
Packit ea1746
//
Packit ea1746
// Author: sameeragarwal@google.com (Sameer Agarwal)
Packit ea1746
//
Packit ea1746
// Detailed descriptions of these preconditions beyond what is
Packit ea1746
// documented here can be found in
Packit ea1746
//
Packit ea1746
// Bundle Adjustment in the Large
Packit ea1746
// S. Agarwal, N. Snavely, S. Seitz & R. Szeliski, ECCV 2010
Packit ea1746
// http://www.cs.washington.edu/homes/sagarwal/bal.pdf
Packit ea1746
Packit ea1746
#ifndef CERES_INTERNAL_SCHUR_JACOBI_PRECONDITIONER_H_
Packit ea1746
#define CERES_INTERNAL_SCHUR_JACOBI_PRECONDITIONER_H_
Packit ea1746
Packit ea1746
#include <set>
Packit ea1746
#include <vector>
Packit ea1746
#include <utility>
Packit ea1746
#include "ceres/collections_port.h"
Packit ea1746
#include "ceres/internal/macros.h"
Packit ea1746
#include "ceres/internal/scoped_ptr.h"
Packit ea1746
#include "ceres/preconditioner.h"
Packit ea1746
Packit ea1746
namespace ceres {
Packit ea1746
namespace internal {
Packit ea1746
Packit ea1746
class BlockRandomAccessDiagonalMatrix;
Packit ea1746
class BlockSparseMatrix;
Packit ea1746
struct CompressedRowBlockStructure;
Packit ea1746
class SchurEliminatorBase;
Packit ea1746
Packit ea1746
// This class implements the SCHUR_JACOBI preconditioner for Structure
Packit ea1746
// from Motion/Bundle Adjustment problems. Full mathematical details
Packit ea1746
// can be found in
Packit ea1746
//
Packit ea1746
// Bundle Adjustment in the Large
Packit ea1746
// S. Agarwal, N. Snavely, S. Seitz & R. Szeliski, ECCV 2010
Packit ea1746
// http://www.cs.washington.edu/homes/sagarwal/bal.pdf
Packit ea1746
//
Packit ea1746
// Example usage:
Packit ea1746
//
Packit ea1746
//   Preconditioner::Options options;
Packit ea1746
//   options.preconditioner_type = SCHUR_JACOBI;
Packit ea1746
//   options.elimination_groups.push_back(num_points);
Packit ea1746
//   options.elimination_groups.push_back(num_cameras);
Packit ea1746
//   SchurJacobiPreconditioner preconditioner(
Packit ea1746
//      *A.block_structure(), options);
Packit ea1746
//   preconditioner.Update(A, NULL);
Packit ea1746
//   preconditioner.RightMultiply(x, y);
Packit ea1746
//
Packit ea1746
class SchurJacobiPreconditioner : public BlockSparseMatrixPreconditioner {
Packit ea1746
 public:
Packit ea1746
  // Initialize the symbolic structure of the preconditioner. bs is
Packit ea1746
  // the block structure of the linear system to be solved. It is used
Packit ea1746
  // to determine the sparsity structure of the preconditioner matrix.
Packit ea1746
  //
Packit ea1746
  // It has the same structural requirement as other Schur complement
Packit ea1746
  // based solvers. Please see schur_eliminator.h for more details.
Packit ea1746
  SchurJacobiPreconditioner(const CompressedRowBlockStructure& bs,
Packit ea1746
                            const Preconditioner::Options& options);
Packit ea1746
  virtual ~SchurJacobiPreconditioner();
Packit ea1746
Packit ea1746
  // Preconditioner interface.
Packit ea1746
  virtual void RightMultiply(const double* x, double* y) const;
Packit ea1746
  virtual int num_rows() const;
Packit ea1746
Packit ea1746
 private:
Packit ea1746
  void InitEliminator(const CompressedRowBlockStructure& bs);
Packit ea1746
  virtual bool UpdateImpl(const BlockSparseMatrix& A, const double* D);
Packit ea1746
Packit ea1746
  Preconditioner::Options options_;
Packit ea1746
  scoped_ptr<SchurEliminatorBase> eliminator_;
Packit ea1746
  // Preconditioner matrix.
Packit ea1746
  scoped_ptr<BlockRandomAccessDiagonalMatrix> m_;
Packit ea1746
  CERES_DISALLOW_COPY_AND_ASSIGN(SchurJacobiPreconditioner);
Packit ea1746
};
Packit ea1746
Packit ea1746
}  // namespace internal
Packit ea1746
}  // namespace ceres
Packit ea1746
Packit ea1746
#endif  // CERES_INTERNAL_SCHUR_JACOBI_PRECONDITIONER_H_