本文整理汇总了C++中eigen::MatrixXf::bottomRows方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixXf::bottomRows方法的具体用法?C++ MatrixXf::bottomRows怎么用?C++ MatrixXf::bottomRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::MatrixXf
的用法示例。
在下文中一共展示了MatrixXf::bottomRows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
int Shell::split(QVariantList points)
{
QPointF point;
//omit last value, because it is always zero
int dataSize = points.size()-1;
Eigen::MatrixXf x; x.resize(dataSize,2);
Eigen::VectorXf y(dataSize);
//create the linear eq system in the form of y = beta1*x + beta2*1
for( int i = 0; i < dataSize; i++)
{
point = points[i].toPointF();
x(i, 0) = 1.0f; //beta for y-intercept
x(i, 1) = point.x(); //beta for slope (dependent on x)
y(i) = point.y();
}
//Error function (least squares of ax+b)
auto error = [](Regression reg, int b, int a)->float
{
float result = 0;
for(int i=0 ; i< reg.y.size(); i++)
{
float functionValue = a*reg.x(i, 1)+ b;
float squarederror = std::pow(reg.y(i) - functionValue, 2);
result+=squarederror;
}
return result;
};
//Perform all pairs of regressions
float lowestError = std::numeric_limits<float>::max();
float r1a, r1b;
float r2a, r2b;
int splitIndex = 0;
for( int i = 2; i < dataSize; i++)
{
Regression reg1; reg1.x = x.topRows(i); reg1.y = y.head(i);
Regression reg2; reg2.x = x.bottomRows(dataSize-i); reg2.y = y.tail(dataSize-i);
Eigen::MatrixXf reg1Result = ((reg1.x.transpose() * reg1.x).inverse() * reg1.x.transpose()) * reg1.y;
Eigen::MatrixXf reg2Result = ((reg2.x.transpose() * reg2.x).inverse() * reg2.x.transpose()) * reg2.y;
float currentError = error(reg1,reg1Result(0),reg1Result(1)) + error(reg2,reg2Result(0),reg2Result(1));
if (currentError < lowestError)
{
r1a = reg1Result(1); r1b = reg1Result(0);
r2a = reg2Result(1); r2b = reg2Result(0);
lowestError = currentError;
splitIndex = i;
}
}
std::cout << "r1:" << r1a << "x + " << r1b << std::endl;
std::cout << "r2:" << r2a << "x + " << r2b << std::endl;
std::cout << "(smallest error:" << lowestError << ")" << std::endl;
return splitIndex;
}