33 #ifndef GRT_LINEAR_LEAST_SQUARES_HEADER
34 #define GRT_LINEAR_LEAST_SQUARES_HEADER
36 #include "../../CoreModules/MLBase.h"
43 classType =
"LinearLeastSquares";
44 infoLog.setProceedingText(
"[LinearLeastSquares]");
45 debugLog.setProceedingText(
"[DEBUG LinearLeastSquares]");
46 errorLog.setProceedingText(
"[ERROR LinearLeastSquares]");
47 trainingLog.setProceedingText(
"[TRAINING LinearLeastSquares]");
48 warningLog.setProceedingText(
"[WARNING LinearLeastSquares]");
61 if( x.size() == 0 && y.size() == 0 ){
62 warningLog <<
"solve( const VectorFloat &x, const VectorFloat &y ) - Failed to compute solution, input vectors are empty!" << endl;
66 if( x.size() != y.size() ){
67 warningLog <<
"solve( const VectorFloat &x, const VectorFloat &y ) - Failed to compute solution, input vectors do not have the same size!" << endl;
71 const unsigned int N = (
unsigned int)x.size();
83 for(
unsigned int i=0; i<N; i++){
91 denom = (n * sumx2 - sqr(sumx));
94 warningLog <<
"solve( const VectorFloat &x, const VectorFloat &y ) - Failed to compute solution, singular matrix detected!" << endl;
98 m = (n * sumxy - sumx * sumy) / denom;
99 b = (sumy * sumx2 - sumx * sumxy) / denom;
102 r = (sumxy - sumx * sumy / n) / sqrt( (sumx2 - sqr(sumx)/n) * (sumy2 - sqr(sumy)/n) );
117 #endif //GRT_MEAN_SHIFT_HEADER