> For the complete documentation index, see [llms.txt](https://ceres-solver-tutorial-cn.gitbook.io/ceres/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ceres-solver-tutorial-cn.gitbook.io/ceres/modeling-non-linear-least-squares/main-class-interface/conditionedcostfunction.md).

# ConditionedCostFunction

<pre class="language-cpp"><code class="lang-cpp"><strong>class ConditionedCostFunction
</strong></code></pre>

通过该类，您可以对成本函数的残差值进行不同的调节。例如，现有的代价函数会产生 $$N$$ 个值，但您希望总代价不只是这些值的平方和，也许您想对某些值应用不同的缩放比例，以改变它们对代价的贡献。

```cpp
//  my_cost_function produces N residuals
CostFunction* my_cost_function = ...
CHECK_EQ(N, my_cost_function->num_residuals());
std::vector<CostFunction*> conditioners;

//  Make N 1x1 cost functions (1 parameter, 1 residual)
CostFunction* f_1 = ...
conditioners.push_back(f_1);

CostFunction* f_N = ...
conditioners.push_back(f_N);
ConditionedCostFunction* ccf =
  new ConditionedCostFunction(my_cost_function, conditioners);
```

现在，ccf's 的 residual\[i]（i=0...N-1）将通过第 i 个调节器传递。 Jacobian 将受到相应的影响。

```cpp
ccf_residual[i] = f_i(my_cost_function_residual[i])
```
