#include <ceres/ceres.h>
#include <ceres/jet.h>
#include <Eigen/Eigen>
struct costFunc {
template <typename T>
bool operator()(const T* const x, T* residuals) const
{
residuals[0] = T(3)* x[0]*x[0] + x[0]*T(5) - T(10) + ceres::sin(x[0]);
//residuals[0] = x[0] - 10.0;
return true;
}
};
double xp2(double x) {
return x + (double)2.0;
}
template <typename T, int N> inline
ceres::Jet<T, N> xp2(const ceres::Jet<T, N>& f) {
return ceres::Jet<T, N>(xp2(f.a), f.v);
}
template<class T>
bool test2(const T* const x,T* res) {
res[0] = xp2(x[0]);
return true;
}
int main()
{
float tet_x = 1;
//std::cout << "test(x):" << xp2(tet_x) << "\n";
costFunc fun ;
using XT = ceres::Jet<float, 1>;
XT X;
X.a = 1;
X.v[0] = 1;
XT Y;
test2(&X,&Y);
std::cout << "Y:" << Y.a << "," << Y.v << "\n";
system("pause");
return 0;
}
利用ceres solver对自定义函数 自动求导
于 2021-05-10 11:12:33 首次发布