/** * @file LinRegression.cpp * @brief Algorithm for linear regression * @author Frank Prüfer * @date 08/13/2013 */ #include "vislearning/regression/linregression/LinRegression.h" #include "core/vector/Algorithms.h" using namespace OBJREC; using namespace std; using namespace NICE; LinRegression::LinRegression(){ dim = 0; } LinRegression::LinRegression(uint dimension){ dim = dimension; } LinRegression::~LinRegression() { } void LinRegression::teach ( const NICE::VVector & x, const NICE::Vector & y ){ if (dim == 0){ //dimension not specified via constructor dim = x[0].size()+1; //use full dimension of data } cerr<<"dim: "< LinRegression::getModelParams(){ return alpha; } double LinRegression::predict ( const NICE::Vector & x ){ double y; if ( dim == 2 ){ //two-dimensional least squares y = alpha[0] + alpha[1] * x[0]; } else { // y = x * alpha NICE::Vector nAlpha(alpha); NICE:: Vector xTmp(1,1.0); xTmp.append(x); y = xTmp.scalarProduct(nAlpha); } return y; }