Skip to content

Commit

Permalink
Using an Eigen::DiagonalMatrix to add the regulariser. Can speed up t…
Browse files Browse the repository at this point in the history
…hings if the feature dimensions are high.
  • Loading branch information
patrikhuber committed Feb 27, 2015
1 parent a035aa6 commit 499dcad
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/superviseddescent/regressors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ class LinearRegressor : public Regressor
Mat regularisationMatrix = regulariser.getMatrix(AtA_Map, data.rows);
Eigen::Map<RowMajorMatrixXf> reg_Eigen(regularisationMatrix.ptr<float>(), regularisationMatrix.rows, regularisationMatrix.cols);

AtA_Eigen = AtA_Eigen + reg_Eigen;
Eigen::DiagonalMatrix<float, Eigen::Dynamic> reg_Eigen_diag(regularisationMatrix.rows);
Eigen::VectorXf diagVec(regularisationMatrix.rows);
for (int i = 0; i < diagVec.size(); ++i) {
diagVec(i) = regularisationMatrix.at<float>(i, i);
}
reg_Eigen_diag.diagonal() = diagVec;
AtA_Eigen = AtA_Eigen + reg_Eigen_diag.toDenseMatrix();

// Perform a ColPivHouseholderQR (faster than FullPivLU) that allows to check for invertibility:
Eigen::ColPivHouseholderQR<RowMajorMatrixXf> qrOfAtA(AtA_Eigen);
Expand Down

0 comments on commit 499dcad

Please sign in to comment.