Blame internal/ceres/preprocessor.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: sameragarwal@google.com (Sameer Agarwal)
Packit ea1746
Packit ea1746
#ifndef CERES_INTERNAL_PREPROCESSOR_H_
Packit ea1746
#define CERES_INTERNAL_PREPROCESSOR_H_
Packit ea1746
Packit ea1746
#include <string>
Packit ea1746
#include <vector>
Packit ea1746
Packit ea1746
#include "ceres/coordinate_descent_minimizer.h"
Packit ea1746
#include "ceres/evaluator.h"
Packit ea1746
#include "ceres/internal/eigen.h"
Packit ea1746
#include "ceres/internal/port.h"
Packit ea1746
#include "ceres/internal/scoped_ptr.h"
Packit ea1746
#include "ceres/iteration_callback.h"
Packit ea1746
#include "ceres/linear_solver.h"
Packit ea1746
#include "ceres/minimizer.h"
Packit ea1746
#include "ceres/problem_impl.h"
Packit ea1746
#include "ceres/program.h"
Packit ea1746
#include "ceres/solver.h"
Packit ea1746
Packit ea1746
namespace ceres {
Packit ea1746
namespace internal {
Packit ea1746
Packit ea1746
struct PreprocessedProblem;
Packit ea1746
Packit ea1746
// Given a Problem object and a Solver::Options object indicating the
Packit ea1746
// configuration of the solver, the job of the Preprocessor is to
Packit ea1746
// analyze the Problem and perform the setup needed to solve it using
Packit ea1746
// the desired Minimization algorithm. The setup involves removing
Packit ea1746
// redundancies in the input problem (inactive parameter and residual
Packit ea1746
// blocks), finding fill reducing orderings as needed, configuring and
Packit ea1746
// creating various objects needed by the Minimizer to solve the
Packit ea1746
// problem such as an evaluator, a linear solver etc.
Packit ea1746
//
Packit ea1746
// Each Minimizer (LineSearchMinimizer and TrustRegionMinimizer) comes
Packit ea1746
// with a corresponding Preprocessor (LineSearchPreprocessor and
Packit ea1746
// TrustRegionPreprocessor) that knows about its needs and performs
Packit ea1746
// the preprocessing needed.
Packit ea1746
//
Packit ea1746
// The output of the Preprocessor is stored in a PreprocessedProblem
Packit ea1746
// object.
Packit ea1746
class Preprocessor {
Packit ea1746
 public:
Packit ea1746
  // Factory.
Packit ea1746
  static Preprocessor* Create(MinimizerType minimizer_type);
Packit ea1746
  virtual ~Preprocessor();
Packit ea1746
  virtual bool Preprocess(const Solver::Options& options,
Packit ea1746
                          ProblemImpl* problem,
Packit ea1746
                          PreprocessedProblem* pp) = 0;
Packit ea1746
};
Packit ea1746
Packit ea1746
// A PreprocessedProblem is the result of running the Preprocessor on
Packit ea1746
// a Problem and Solver::Options object.
Packit ea1746
struct PreprocessedProblem {
Packit ea1746
  PreprocessedProblem()
Packit ea1746
      : fixed_cost(0.0) {
Packit ea1746
  }
Packit ea1746
Packit ea1746
  std::string error;
Packit ea1746
  Solver::Options options;
Packit ea1746
  LinearSolver::Options linear_solver_options;
Packit ea1746
  Evaluator::Options evaluator_options;
Packit ea1746
  Minimizer::Options minimizer_options;
Packit ea1746
Packit ea1746
  ProblemImpl* problem;
Packit ea1746
  scoped_ptr<ProblemImpl> gradient_checking_problem;
Packit ea1746
  scoped_ptr<Program> reduced_program;
Packit ea1746
  scoped_ptr<LinearSolver> linear_solver;
Packit ea1746
  scoped_ptr<IterationCallback> logging_callback;
Packit ea1746
  scoped_ptr<IterationCallback> state_updating_callback;
Packit ea1746
Packit ea1746
  shared_ptr<Evaluator> evaluator;
Packit ea1746
  shared_ptr<CoordinateDescentMinimizer> inner_iteration_minimizer;
Packit ea1746
Packit ea1746
  std::vector<double*> removed_parameter_blocks;
Packit ea1746
  Vector reduced_parameters;
Packit ea1746
  double fixed_cost;
Packit ea1746
};
Packit ea1746
Packit ea1746
// Common functions used by various preprocessors.
Packit ea1746
Packit ea1746
// If OpenMP support is not available and user has requested more than
Packit ea1746
// one thread, then set the *_num_threads options as needed to 1.
Packit ea1746
void ChangeNumThreadsIfNeeded(Solver::Options* options);
Packit ea1746
Packit ea1746
// Extract the effective parameter vector from the preprocessed
Packit ea1746
// problem and setup bits of the Minimizer::Options object that are
Packit ea1746
// common to all Preprocessors.
Packit ea1746
void SetupCommonMinimizerOptions(PreprocessedProblem* pp);
Packit ea1746
Packit ea1746
}  // namespace internal
Packit ea1746
}  // namespace ceres
Packit ea1746
Packit ea1746
#endif  // CERES_INTERNAL_PREPROCESSOR_H_