我在将 Eigen::VectorXd
类型与 Boost 累加器库结合使用时遇到了一些问题:
#include <iostream>
#include <Eigen/Core>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/mean.hpp>
using namespace boost::accumulators;
using namespace Eigen;
int main()
{
Vector2f a(1.0, 2.0), b(3.0, 10.0);
accumulator_set<Vector2f, stats<tag::mean> > acc(Vector2f::Zero());
acc(a);
acc(b);
std::cout << mean(acc) << std::endl;
std::cout << ((a+b)/2.0) << std::endl;
return 0;
}
在我的系统上这会产生:
4.41629e-39
0
2
6
因此,虽然直接计算很好(特征向量支持所有常用的数值运算符),但 Boost 累加器在运行时会失败而不会出现错误。
最佳答案
用户定义类型需要特化 std::numeric_limits。 见https://svn.boost.org/trac/boost/ticket/5491
关于c++ - 将 Boost 累加器与 Eigen::Vector 类型一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7908982/