26 #include "WCovarianceSolver.h"
46 if( dataSet.size() == 0 )
48 size_t dimensions = dataSet[0].size();
49 for(
size_t dimension = 0; dimension < dimensions; dimension++ )
51 for(
size_t index = 0; index < dataSet.size(); index++ )
52 for(
size_t dimension = 0; dimension < dataSet[index].size(); dimension++ )
53 m_mean[dimension] += dataSet[index][dimension];
54 for(
size_t dimension = 0; dimension < dimensions; dimension++ )
55 m_mean[dimension] /=
static_cast<double>( dataSet.size() );
59 size_t width =
m_mean.size();
60 MatrixXd newCovariance( width, width );
62 for(
size_t row = 0; row < width; row++ )
63 for(
size_t col = 0; col < width; col++ )
65 for(
size_t index = 0; index < dataSet.size(); index++ )
67 for(
size_t row = 0; row < width; row++ )
68 for(
size_t col = 0; col < width; col++ )
69 m_covariance( row, col ) /=
static_cast<double>( dataSet.size() ) - 1.0;
73 size_t width =
m_mean.size();
74 for(
size_t row = 0; row < width; row++ )
76 double rowValue = point[row] -
m_mean[row];
77 for(
size_t col = 0; col < width; col++ )
79 double colValue = point[col] -
m_mean[col];
WPosition getMean()
Returns the mean coordinate of the input point data set.
virtual ~WCovarianceSolver()
Destroys the instance of the Covariance solver.
void calculateCovariance(const vector< WPosition > &dataSet)
Calculates the covariance of the input point data.
void addPointToCovariance(const WPosition &point)
Adds a point to the covariance matrix.
WPosition m_mean
The mean of all input points.
MatrixXd m_covariance
The calculated covariance matrix.
MatrixXd getCovariance()
Returns the covariance matrix corresponding to the input point data set.
void analyzeData(const vector< WPosition > &dataSet)
Analyzes the dimension covariances of a point data set.
void calculateMean(const vector< WPosition > &dataSet)
Calculates the mean of the input point data coordinates.
WCovarianceSolver()
Creates an instance of the Covariance solver.
This only is a 3d double vector.