首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ceres求解器来解决高维非线性问题?

如何使用ceres求解器来解决高维非线性问题?
EN

Stack Overflow用户
提问于 2022-03-28 05:42:57
回答 1查看 192关注 0票数 0

我需要解决优化问题:

Ab是已知的。我使用Zero来表示Ab,以便在下面的代码中为表达式提供方便。错误是由problem.AddResidualBlock(cost_function, nullptr, &X);引起的,因为第三个参数需要双类型,X是一个包含50个元素的向量。你能给我一些建议吗?

代码语言:javascript
复制
#include <cmath>
#include <ceres/ceres.h>
#include <Eigen/Core>
#include <Eigen/Eigen>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <Eigen/StdVector>


#define PhaseNums 25

using namespace std;
using namespace ceres;
using namespace Eigen;

struct GammaResidual
{
    GammaResidual(const MatrixXf A, const VectorXf b) : A_(A), b_(b) {}

    template <typename T>
    bool operator()(const T* const x, T* residual) const {
        residual[0] = (A_ * x[0] - b_).transpose() * (A_ * x[0] - b_);
        return true;
    }

private:
    const MatrixXf A_;
    const VectorXf b_;
};

int main()
{
    MatrixXf A = MatrixXf::Zero(2 * PhaseNums, 2 * PhaseNums);
    VectorXf b = VectorXf::Zero(2 * PhaseNums);
    VectorXf X = VectorXf::Zero(2 * PhaseNums);

    Problem problem;
    CostFunction* cost_function = new AutoDiffCostFunction<GammaResidual, 1, 1>(
            new GammaResidual(A, b));
    problem.AddResidualBlock(cost_function, nullptr, &X);

    ceres::Solver::Options options; 
    options.minimizer_progress_to_stdout = true; 

    ceres::Solver::Summary summary;  
    ceres::Solve(options, &problem, &summary); 
    cout << summary.BriefReport() << endl;
}
EN

回答 1

Stack Overflow用户

发布于 2022-04-20 19:07:58

我想,如果你的x是一个向量,你需要循环它,并为每一个x添加一个剩余的块。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71642861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档