Closed Programmer-Magnus closed 3 years ago
Try with this 1ca62fa83ee9a41a10c82b4ea55cd22b485008cd from the https://github.com/optimatika/ojAlgo/tree/ConvexLagrangeMultipliers branch.
Can you verify that it works? Perhaps contribute a couple of unit tests.
It's best if you first fork ojAlgo to your own account. Then you clone that to a local copy on your development machine, and import that project/module to your IDE.
I might have made my first git and github pull request to contribute a test for multipliers. My experiments say multipliers have the wrong sign. I look forward to your comments.
I see that you forked ojAlgo and created a branch test1
, but I do not see any commits nor a pull request.
If you're new to git (GitHub) it takes a while to get used to. Perhaps try the GitHub Desktop GUI. It hides a bit of the complexity.
Are the multipliers the wrong sign, are you sure? With or without inequality constraints different solvers are used. Are the multipliers the wrong sign in both cases?
I made a second attempt. There should now be some actual code in the pull request.
About the sign of the multipliers, I am not 100% sure. But I added a calculation in the end of the test that convinced me they have a minus to much. Please check the expressions and tell me if my assumptions are wrong.
I assume this is what is solved:
| [Q] -[A]^T| |x| = |-c|
| [A] [0] | |L| |b|
And check result of [L] using:
[Q]*[x] - [A]^T*[L] = -c
also check
[A]*[x] = b
Looking at the code this is what is solved:
| [Q] [A]^T| |x| = |c|
| [A] [0] | |L| |b|
In the ConstrainedSolver
class look at the getIterationKKT()
and getIterationRHS()
methods.
Remember the solver is designed to have c
negated (so that negating it doesn't have to be part of the algorithm).
Are the Lagrange multipliers given in that text book example?
Yes multipliers are given in the book at p453. The matrix equation I wrote (16.4) is on p451. In the test I wrote Q and C are the Hessian and Gradient of the function at x=[0.0, 0.0, 0.0]'
If we leave the ojAlgo solvers out for a while, and just take the numbers from that Nocedal and Wright example and form the KKT equation system
| [Q] [A]^T| |x| = |-c|
| [A] [0] | |L| |b|
Here's a small pdf using the same example that outlines how to solve using KKT: http://www.lendek.net/teaching/opt_en/qp.pdf
I do that and get the same solution as ojAlgo does.
I believe its the minus sign in front of [A]^T
in the KKT equation system. It affect the sign of |L|
, and thereby the interpretation of a negative/positive value and nothing else as I understand it.
I am fine with any choice. And believe its your call. I update the test to make them pass with the present implementation.
In the text book by Nocedal and Wright there is a minus in-front of the [A]^T
, i do not find their reason for it.
I've been reading up on the subject this morning (it's been a while). I believe for equality constraints you have a choice on how to define the augmented Lagrangian, is that true? With inequalities it's well defined...
If there's a problem I want to fix it, but if it's a matter of choice/definition then it stays the way it is.
I think it would be confusing if multiplier sign had different meaning for equality vs inequality constraints. I would like to avoid that for ojAlgo users. Lagrangian function L(x, lambda) = F(x) - lambdaG(x) could as well be written L(x, lambda) = F(x) + (-lambda)G(x). Convincing me that the sign is not important, but I would expect the same for inequality constraints. What is the reasoning there?
I constructed another test based on an example found here: https://people.duke.edu/~hpgavin/cee201/LagrangeMultipliers.pdf
I pushed to your PR. Please verify that I didn't make any mistake.
The ojAlgo solvers mimic the results of that example using unconstrained, equality constrained and inequality constrained problem formulations (which results in different solvers being used). The results are consistent.
Haven't done this (now) but something like this:
I checked both test codes in LagrangeTest.java and the only mistake I found was a '-' that should be a '+' in a comment. I made a commit for that, do i also need to make push request for that, or can you already see it? Have a nice week end!
I need the Lagrangian multipliers for a Quadratic Programming solution but they are not returned by result.getMultipliers() in this example using version 48.2.0 of ojAlgo: