Registered Member
|
Hello,
In the context of ridge regression I need to compute:
where lambda is a scalar. In order to compute the "lambda * Identity" I did:
but this turns out to be slow (and unnecessary) i.e. multiplying by a bunch of zeros. I then tried:
but apparently I can't combine DiagonalMatrix and MatrixXd in the main expression? I get a compilation error for this:
Then the question is how can I do this elegantly and efficiently in Eigen and by elegantly I mean simply not compromising on the code readability and end up writing a loop over the diagonal elements of X*X^T and adding lambda. TIA, Best regards, Giovanni
Last edited by bravegag on Thu Sep 05, 2013 8:16 am, edited 1 time in total.
|
Moderator
|
First compute X2 = X*X^T and then do:
This is what X*X^T - reg_I should do for you in the future. |
Registered Member
|
hi ggael,
Always excellent support, Thank you I will miss having the visible ridge formula but the performance improvement really does justify it. Cheers, Giovanni |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]