-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add more general linear operator constraint to sdp #350
Closed
SuvarshaChennareddy
wants to merge
4
commits into
mlpack:master
from
SuvarshaChennareddy:add-more-general-linear-operator-constraint-sdp
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0a10a51
add more general linear operator constraint to sdp
SuvarshaChennareddy 312f447
modify GetInitialPoints(...) method
SuvarshaChennareddy cf9ddab
update sdp_primal_dual_test.cpp
SuvarshaChennareddy 0ae9bb2
Update include/ensmallen_bits/sdp/lrsdp_function.hpp
SuvarshaChennareddy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,38 @@ | |
namespace ens { | ||
namespace math { | ||
|
||
/** | ||
* Matrix representation of a general Linear operator representated | ||
* by a function/method. | ||
* | ||
* @param input Input function. | ||
* @param output The matrix representation. | ||
*/ | ||
template<typename ElemType, typename MatBType> | ||
inline void convertToMatrix(std::function<ElemType(arma::Mat<ElemType>)> input, | ||
MatBType& output) | ||
{ | ||
const size_t n = output.n_rows; | ||
|
||
arma::Mat<ElemType> tempInputCoordinates; | ||
tempInputCoordinates.zeros(n, n); | ||
|
||
size_t idx = 0; | ||
for (size_t i = 0; i < n; i++) | ||
{ | ||
if (i > 0) tempInputCoordinates(i - 1, n - 1) = 0; | ||
for (size_t j = i; j < n; j++) | ||
{ | ||
if (j > i) tempInputCoordinates(i, j - 1) = 0; | ||
tempInputCoordinates(i, j) = 1; | ||
if (i == j) | ||
output(i, j) = input(tempInputCoordinates); | ||
else | ||
output(i, j) = output(j, i) = 0.5 * arma::datum::sqrt2 * input(tempInputCoordinates); | ||
} | ||
} | ||
} | ||
|
||
inline size_t SvecIndex(size_t i, size_t j, size_t n) | ||
{ | ||
if (i > j) | ||
|
@@ -109,6 +141,8 @@ inline void Smat(const MatAType& input, MatBType& output) | |
} | ||
} | ||
|
||
|
||
|
||
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. No need to add this whitespace :) |
||
/** | ||
* If A is a symmetric matrix, then SymKronId returns an operator Op such that | ||
* | ||
|
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
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.
It looks like the approach you are taking is to turn a
std::function
that the user gives into a matrix, and then use that as a constraint. But this is the opposite of what we are looking for in #72: take the given example of the constraint that the sum of elements is a constant. You can express this very tediously as the constrainttrace(1 1^T X) = b
, but the much easier way to represent this issum(X) = b
. So, instead of extracting the matrix1 1^T
, it would be better to just store thestd::function
s in the SDP objects and evaluate them directly to get the value.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.
First of all, thank you for taking the time to look into this. I'm glad you asked this. I honestly didn't know if this would be alright.
However, (from what I understand) in the interior point method, the constraints need to be expressed as matrices (as matrix multiplication and transposing is involved).
Although, in the LRSDP implementation, I have used these
std::function
s wherever the matrix conversion isn't necessary (again like in the case of matrix multiplication or transposing).I had given it some thought but using these
std::function
s directly would be extremely tedious as a lot of factors must be accounted for. For example, how would I calculate M=A(E^-1)F(A^T) where A is the matrix of vector forms of the constraints.Nevertheless, I will think about this a bit more and try to come with a more appropriate solution.