/** * @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" #include "LinRegression.h" using namespace OBJREC; using namespace std; using namespace NICE; LinRegression::LinRegression() { dim = 0; } LinRegression::LinRegression(uint dimension) { dim = dimension; } LinRegression::LinRegression ( const LinRegression & src ) : RegressionAlgorithm ( src ) { dim = src.dim; } LinRegression::~LinRegression() { } LinRegression* LinRegression::clone ( void ) const { return new LinRegression(*this); } 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 modelParams; } double LinRegression::predict ( const NICE::Vector & x ){ double y; if ( dim == 2 ) //two-dimensional least squares { y = modelParams[0] + modelParams[1] * x[0]; } else { // y = x * modelParams NICE::Vector nModel(modelParams); NICE:: Vector xTmp(1,1.0); xTmp.append(x); y = xTmp.scalarProduct(nModel); } return y; }