-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve max volume ellipsoid computation #309
Merged
TolisChal
merged 5 commits into
GeomScale:develop
from
TolisChal:improve_max_volume_ellipsoid_computations
Jun 20, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5cd638
improve the implementation of maximum ellipsoid computation
f30407e
minor fix in rounding unit-test
80c0b1d
fix file copyrights
f238039
apply termination criterion after transformation in max ellipsoid rou…
a5f18aa
resolve PR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -22,14 +22,16 @@ template | |
typename Point | ||
> | ||
std::tuple<MT, VT, NT> max_inscribed_ellipsoid_rounding(Polytope &P, | ||
Point const& InnerPoint) | ||
Point const& InnerPoint, | ||
unsigned int const max_iterations = 5, | ||
NT const max_eig_ratio = NT(6)) | ||
{ | ||
std::pair<std::pair<MT, VT>, bool> iter_res; | ||
iter_res.second = false; | ||
|
||
VT x0 = InnerPoint.getCoefficients(); | ||
MT E, L; | ||
unsigned int maxiter = 150, iter = 1, d = P.dimension(); | ||
unsigned int maxiter = 500, iter = 1, d = P.dimension(); | ||
|
||
NT R = 100.0, r = 1.0, tol = std::pow(10, -6.0), reg = std::pow(10, -4.0), round_val = 1.0; | ||
|
||
|
@@ -44,18 +46,28 @@ std::tuple<MT, VT, NT> max_inscribed_ellipsoid_rounding(Polytope &P, | |
E = (E + E.transpose()) / 2.0; | ||
E = E + MT::Identity(d, d)*std::pow(10, -8.0); //normalize E | ||
|
||
Eigen::LLT<MT> lltOfA(E); // compute the Cholesky decomposition of E | ||
Eigen::LLT<MT> lltOfA(E.llt().solve(MT::Identity(E.cols(), E.cols()))); // compute the Cholesky decomposition of E^{-1} | ||
L = lltOfA.matrixL(); | ||
|
||
Eigen::SelfAdjointEigenSolver <MT> eigensolver(L); | ||
r = eigensolver.eigenvalues().minCoeff(); | ||
R = eigensolver.eigenvalues().maxCoeff(); | ||
|
||
// check the roundness of the polytope | ||
if(((std::abs(R / r) <= 2.3 && iter_res.second) || iter >= 20) && iter>2){ | ||
break; | ||
// computing eigenvalues of E | ||
Spectra::DenseSymMatProd<NT> op(E); | ||
// The value of ncv is chosen empirically | ||
Spectra::SymEigsSolver<NT, Spectra::SELECT_EIGENVALUE::BOTH_ENDS, | ||
Spectra::DenseSymMatProd<NT>> eigs(&op, 2, std::min(std::max(10, int(d)/5), int(d))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add a comment on the numeric values here and how we select them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The values is chosen empirically. I added a comment. |
||
eigs.init(); | ||
int nconv = eigs.compute(); | ||
if (eigs.info() == Spectra::COMPUTATION_INFO::SUCCESSFUL) { | ||
R = 1.0 / eigs.eigenvalues().coeff(1); | ||
r = 1.0 / eigs.eigenvalues().coeff(0); | ||
} else { | ||
Eigen::SelfAdjointEigenSolver<MT> eigensolver(E); | ||
if (eigensolver.info() == Eigen::ComputationInfo::Success) { | ||
R = 1.0 / eigensolver.eigenvalues().coeff(0); | ||
r = 1.0 / eigensolver.eigenvalues().template tail<1>().value(); | ||
} else { | ||
std::runtime_error("Computations failed."); | ||
} | ||
} | ||
|
||
// shift polytope and apply the linear transformation on P | ||
P.shift(iter_res.first.second); | ||
shift += T * iter_res.first.second; | ||
|
@@ -67,6 +79,11 @@ std::tuple<MT, VT, NT> max_inscribed_ellipsoid_rounding(Polytope &P, | |
P.normalize(); | ||
x0 = VT::Zero(d); | ||
|
||
// check the roundness of the polytope | ||
if(((std::abs(R / r) <= max_eig_ratio && iter_res.second) || iter >= max_iterations)){ | ||
break; | ||
} | ||
|
||
iter++; | ||
} | ||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a todo here to change this to std::tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I added a comment in
max_inscribed_ellipsoid.hpp