Functions | |
template<typename T, int Size> | |
void | computeFittingHyperplane (int numPoints, const Vector< T, Size > *points, Vector< T, Size+1 > *retCoefficients) |
template<typename T> | |
void | computeFittingHyperplaneX (int numPoints, const VectorX< T > *points, VectorX< T > *retCoefficients) |
template<typename T, int Size> | |
void | linearRegression (int numPoints, const Vector< T, Size > *points, Vector< T, Size > *retCoefficients, int funcOfOthers) |
template<typename T> | |
void | linearRegressionX (int numPoints, const VectorX< T > *points, VectorX< T > *retCoefficients, int funcOfOthers) |
void Eigen::computeFittingHyperplane | ( | int | numPoints, | |
const Vector< T, Size > * | points, | |||
Vector< T, Size+1 > * | retCoefficients | |||
) | [inline] |
This function is quite similar to linearRegression(), so we refer to the documentation of this function and only list here the differences.
The main difference from linearRegression() is that this function doesn't take a funcOfOthers argument. Instead, it finds a general equation of the form
where ,
, and we denote by
the n coordinates in the n-dimensional space.
Thus, the vector retCoefficients has size , which is another difference from linearRegression().
void Eigen::computeFittingHyperplaneX | ( | int | numPoints, | |
const VectorX< T > * | points, | |||
VectorX< T > * | retCoefficients | |||
) | [inline] |
This function is the dynamic-size counterpart to computeFittingHyperplane() and, aside from working with VectorX instead of Vector, is exactly the same thing.
void Eigen::linearRegression | ( | int | numPoints, | |
const Vector< T, Size > * | points, | |||
Vector< T, Size > * | retCoefficients, | |||
int | funcOfOthers | |||
) | [inline] |
Performs a multiple linear regression on a set of points, as explained here:
http://en.wikipedia.org/wiki/Linear_regression#Multiple_linear_regression
In other words, for a set of points, this function tries to express one of the coords as a linear (affine) function of the other coords.
This is best explained by an example. This function works in full generality, for points in a space of arbitrary dimension, and also over the complex numbers, but for this example we will work in dimension 3 over the real numbers (doubles).
So let us work with the following set of 5 points given by their coordinates:
Vector3d points[5]; points[0] = Vector3d( 3.02, 6.89, -4.32 ); points[1] = Vector3d( 2.01, 5.39, -3.79 ); points[2] = Vector3d( 2.41, 6.01, -4.01 ); points[3] = Vector3d( 2.09, 5.55, -3.86 ); points[4] = Vector3d( 2.58, 6.32, -4.10 );
for some constants . Thus, we want to find the best possible constants
so that the plane of equation
fits best the five above points. To do that, call this function as follows:
Vector3d coeffs; // will store the coefficients a, b, c linearRegression< double, 3 >( 5, points, & coeffs, 1 // the coord to express as a function of // the other ones. 0 means x, 1 means y, 2 means z. );
On the other hand, we have . We see that the values
and
are near, so points[0] is very near the plane of equation
.
Let's now describe precisely the parameters:
numPoints | the number of points to read from the array | |
points | the array of points on which to perform the linear regression | |
retCoefficients | pointer to the vector in which to store the result. This vector must be of the same type and size as the data points. The meaning of its coords is as follows. For brevity, let ![]() ![]() ![]() ![]()
| |
funcOfOthers | Determines which coord to express as a function of the others. Coords are numbered starting from 0, so that a value of 0 means ![]() ![]() ![]() |
void Eigen::linearRegressionX | ( | int | numPoints, | |
const VectorX< T > * | points, | |||
VectorX< T > * | retCoefficients, | |||
int | funcOfOthers | |||
) | [inline] |
This function is the dynamic-size counterpart to linearRegression() and, aside from working with VectorX instead of Vector, is exactly the same thing.