forked from cvxr/TFOCS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using safe_eig() code to prevent rare eigenvalue decomp. bug
- Loading branch information
1 parent
614dea7
commit 1945a77
Showing
11 changed files
with
52 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function [V,D] = eig_backup( X ) | ||
% [V,D] = eig_backup(X) | ||
% computes the eigenvalue decomposition of a symmetric matri | ||
% using the SVD. This is designed for cases when the main eig() | ||
% routine doesn't work due to the bug described at | ||
% http://ask.cvxr.com/t/eig-did-not-converge-in-prox-trace/996/4 | ||
% | ||
% This uses the SVD, so a bit slower sometimes... | ||
% July 13 2015 | ||
|
||
[V,D,W] = svd(X); | ||
|
||
|
||
d = diag(D).' .* sign(real(dot(V,W,1))); | ||
% and sort it to conform to Matlab's order... | ||
[d,ind] = sort(d); | ||
D = diag(d); | ||
V = V(:,ind); | ||
|
||
% Another option, but typically slow... | ||
% (calls generalized eigenvalue decomp.)/ | ||
% [V,D] = eig(X,eye(size(X))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function [V,D] = safe_eig(X) | ||
% [V,D] = safe_eig(X) | ||
% calls [V,D] = eig(X) and tests for a common error | ||
% (http://ask.cvxr.com/t/eig-did-not-converge-in-prox-trace/996/4) | ||
% and if it finds it, runs a replacement algorithm | ||
try | ||
[V,D] = eig(X); | ||
catch ME | ||
if (strcmpi(ME.identifier,'MATLAB:eig:NoConvergence')) | ||
[V,D] = eig_backup(X); | ||
else | ||
rethrow(ME); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters