我正在尝试最小化以下示例函数:
F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1])
Run Code Online (Sandbox Code Playgroud)
最小化这种功能的常用方法可能是Levenberg-Marquardt算法.我想在c ++中执行这种最小化,并且已经使用Eigen进行了一些初步测试,从而得到了预期的解决方案.
我的问题如下:我习惯使用ie在python中进行优化scipy.optimize.fmin_powell.这里的输入函数参数是(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None, direc=None).所以我可以定义一个func(x0),给出x0向量并开始优化.如果需要,我可以更改优化参数.
现在,Eigen Lev-Marq算法以不同的方式工作.我需要定义一个函数向量(为什么?)此外我无法设置优化参数.根据:
http://eigen.tuxfamily.org/dox/unsupported/classEigen_1_1LevenbergMarquardt.html
我应该能够使用setEpsilon()和其他设置函数.
但是当我有以下代码时:
my_functor functor;
Eigen::NumericalDiff<my_functor> numDiff(functor);
Eigen::LevenbergMarquardt<Eigen::NumericalDiff<my_functor>,double> lm(numDiff);
lm.setEpsilon(); //doesn't exist!
Run Code Online (Sandbox Code Playgroud)
所以我有两个问题:
为什么需要函数向量,为什么函数标量不够?
我在哪里寻找答案的参考文献:
http://www.ultimatepp.org/reference$Eigen_demo$en-us.html
http://www.alglib.net/optimization/levenbergmarquardt.php
如何使用设置功能设置优化参数?
我一直在努力实现一个所有面向法线的网格指向外部.为了实现这一点,我从*.ctm文件加载网格,然后遍历所有三角形以使用叉积确定法线,如果法线指向负z方向,则翻转v1和v2(因此正常方向).完成此操作后,我将结果保存到*.ctm文件并使用Meshlab查看.
Meshlab中的结果仍然显示法线指向正z方向和负z方向(可以从黑色三角形看到).此外,当在Meshlab中查看法线时,它们实际上是指向后方.
谁能给我一些如何解决这个问题的建议?
规范化部分的源代码是:
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZRGBA> ());
pcl::fromROSMsg (meshFixed.cloud,*cloud1);for(std::vector<pcl::Vertices>::iterator it = meshFixed.polygons.begin(); it != meshFixed.polygons.end(); ++it)
{
alglib::real_2d_array v0;
double _v0[] = {cloud1->points[it->vertices[0]].x,cloud1->points[it->vertices[0]].y,cloud1->points[it->vertices[0]].z};
v0.setcontent(3,1,_v0); //3 rows, 1col
alglib::real_2d_array v1;
double _v1[] = {cloud1->points[it->vertices[1]].x,cloud1->points[it->vertices[1]].y,cloud1->points[it->vertices[1]].z};
v1.setcontent(3,1,_v1); //3 rows, 1col
alglib::real_2d_array v2;
double _v2[] = {cloud1->points[it->vertices[2]].x,cloud1->points[it->vertices[2]].y,cloud1->points[it->vertices[2]].z};
v2.setcontent(1,3,_v2); //3 rows, 1col
alglib::real_2d_array normal;
normal = cross(v1-v0,v2-v0);
//if z<0 change indices order v1->v2 and v2->v1
alglib::real_2d_array normalizedNormal;
if(normal[2][0]<0)
{
int index1,index2;
index1 = it->vertices[1];
index2 = it->vertices[2];
it->vertices[1] = index2;
it->vertices[2] = index1; …Run Code Online (Sandbox Code Playgroud)