1

残差の平方和をコスト関数として計算する ceres のデフォルトの動作を変更しようとしています。合計のみを計算したい (残差は、正の値しか得られない方法で既に計算されています)

ドキュメントによると、ConditionedCostFunctionを使用する必要があります

これが私がやったことです: 1つの残差と1つのパラメーターを取るコンディショナーを定義します

struct Conditioners : ceres::CostFunction
{
public:
    Conditioners()
    {
        set_num_residuals(1);
        mutable_parameter_block_sizes()->push_back(1);
    }

    ~Conditioners()
    {}

    template<typename T>
    T operator() (T x)
    {
        return T(x * x);
    }

    bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const
    {
        return true;
    }
};

ベクトルの中にコンディショナーを入れます

std::vector<ceres::CostFunction*> conditioners;

for(int i = 0; i < 1; i++)
    conditioners.push_back(new Conditioners());

ceres::ConditionedCostFunction* ccf =
              new ceres::ConditionedCostFunction(cost_function, conditioners, ceres::TAKE_OWNERSHIP);

problem.AddResidualBlock(ccf, NULL, &x);

それはコンパイルされ、すべて。しかし、それは問題を解決しません。開始さえしません。それは言う:

Ceres Solver Report: Iterations: 0, Initial cost: 4.512500e+01, Final cost: 4.512500e+01, Termination: CONVERGENCE
x : 0.5 -> 0.5

それ以外の :

iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  4.512500e+01    0.00e+00    9.50e+00   0.00e+00   0.00e+00  1.00e+04       0    2.99e-04    1.04e-03
   1  4.511598e-07    4.51e+01    9.50e-04   9.50e+00   1.00e+00  3.00e+04       1    3.84e-04    9.72e-03
   2  5.012552e-16    4.51e-07    3.17e-08   9.50e-04   1.00e+00  9.00e+04       1    2.98e-05    9.92e-03
Ceres Solver Report: Iterations: 2, Initial cost: 4.512500e+01, Final cost: 5.012552e-16, Termination: CONVERGENCE
x : 0.5 -> 10

(自分で試してみたい場合は、この例でhellowordの例を変更します) (ceres のレポートはより具体的ではありませんでした)

4

1 に答える 1