Ceres Solver 中文文档
  • 😜Ceres Solver 中文文档
  • Why Ceres ?
  • Installation
  • Tutorial
    • Non-linear Least Squares
      • Introduction
      • Hello World
      • Derivatives
        • Numeric Derivatives
        • Analytic Derivatives
        • More About Derivatives
      • Powell’s Function
      • Curve Fitting
      • Robust Curve Fitting
      • Bundle Adjustment
      • Other Examples
    • General Unconstrained Minimization
      • General Unconstrained Minimization
  • On Derivatives
    • Spivak Notation
    • Analytic Derivatives
    • Numeric Derivatives
    • Automatic Derivatives
    • Interfacing with Automatic Differentiation
    • Using Inverse & Implicit Function Theorems
  • Modeling Non-linear Least Squares
    • Introduction
    • Main Class Interface
      • CostFunction
      • SizeCostFunction
      • AutoDiffCostFunction
      • DynamicAutoDiffCostFunction
      • NumericDiffCostFunction
      • DynamicNumericDifferCostFunction
      • CostFunctionToFunctor
      • DynamicCostFunctionToFunctor
      • ConditionedCostFunction
      • GradientChecker
      • NormalPrior
      • LossFunction
      • Manifold
      • AutoDIffManifold
      • Problem
      • EvaluatationCallback
      • Rotation
      • Cubic Interpolation
        • CubicInterpolator
        • BiCubicInterpolator
  • Solveing Non-linear Least Squares
    • Introduction
    • Trust Region Methodd
    • Line Search Methods
    • Linear Solvers
    • Mixed Precision Solves
    • Preconditioners
    • Ordering
    • Main Class Interfaces
      • Solver::Options
      • ParameterBlockOrdering
      • IterationSummary
      • IterationCallback
      • CRSMatrix
      • Solver::Summary
  • Covariance Estimation
    • Introduction
    • Gauge Invariance
    • Covariance
    • Rank of the Jacobian
      • Options
      • Covariance
      • GetCovarianceBlock
      • GetCovarianceBlockInTangentSpace
    • Example Usage
Powered by GitBook
On this page
  1. Modeling Non-linear Least Squares
  2. Main Class Interface

GradientChecker

class GradientChecker

该类将代价函数返回的雅各比与使用有限差分估算的导数进行比较。它是用于单元测试的工具,比求解器选项中的 check_gradients 选项提供更精细的控制。强制执行的条件是

∀i,j:Jij−Jij′max⁡ij(Jij−Jij′)<r\forall i, j: \frac{J_{i j}-J_{i j}^{\prime}}{\max _{i j}\left(J_{i j}-J_{i j}^{\prime}\right)}<r∀i,j:maxij​(Jij​−Jij′​)Jij​−Jij′​​<r

其中,JijJ_{i j}Jij​ 是通过提供的成本函数乘以 Manifold::PlusJacobian 计算得出的 jacobian,Jij′J_{i j}^{\prime}Jij′​ 是通过有限差分计算得出的 jacobian,同样乘以 Manifold::PlusJacobian,r 是相对精度。

使用方法如下

// my_cost_function takes two parameter blocks. The first has a
// manifold associated with it.

CostFunction* my_cost_function = ...
Manifold* my_manifold = ...
NumericDiffOptions numeric_diff_options;

std::vector<Manifold*> manifolds;
manifolds.push_back(my_manifold);
manifolds.push_back(nullptr);

std::vector parameter1;
std::vector parameter2;
// Fill parameter 1 & 2 with test data...

std::vector<double*> parameter_blocks;
parameter_blocks.push_back(parameter1.data());
parameter_blocks.push_back(parameter2.data());

GradientChecker gradient_checker(my_cost_function,
                                 manifolds,
                                 numeric_diff_options);
GradientCheckResults results;
if (!gradient_checker.Probe(parameter_blocks.data(), 1e-9, &results) {
  LOG(ERROR) << "An error has occurred:\n" << results.error_log;
}
PreviousConditionedCostFunctionNextNormalPrior

Last updated 1 year ago