-
Notifications
You must be signed in to change notification settings - Fork 29
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
Stopping criteria confusing/Python code doesn't match Matlab #23
Comments
Hi, When you mean the output of Matlab and python is not identical, you mean the actual inverted x is different or the output on screen? |
Hi, I am not at my work computer where I can run my scripts, but I recall that the residual rnorm and the number of iterations did not match. Since A, b, sigma, opt_tol, and the maximum number of iterations are all set the same, I would expect the algorithm to generate the same output. |
Hi,
Note the last print. Basically despite theory says that BPDN finds x such that the residual is smaller of equal than sigma this is not exactly the case in the code (in the original MATLAB code and so we kept the same for the python code) as you check that rnorm - sigma <= opt_tol (or rnorm <= sigma + opt_tol), this is why you sometimes see that your final condition is False: the algorithm has exited as the condition is satisfied but this is not the case if you take away opt_tol. The new condition I have put is always satisfied Here is the condition in python code:
and MATLAB:
|
Ok no problem. Now that i know what is different I can try and monitor various parameters through iterations, will let you know. |
Finally you say
I totally agree and had the same problem in the past before digging into the code further and understand why ( What do you think about this description of
|
The docstring modification you suggested makes sense to me. I had dug into the source code and saw opt_tol was involved in some of the exit condition checks, but I hadn't figured out how. Your explanation makes a lot of sense to me. When I was looking at the source code, I thought I saw opt_tol was involved in some other checks. I am asking because from what you said, it seems that I could set opt_tol = 0, in which case sigma for the BPDN problem would act as intended. However, could it be that setting opt_tol = 0 would mess up something else in the code? By the way, I started a parallel inquiry into this with the original authors of the method and the Matlab code. I will let you know if I hear anything back from them. I understand the desire to keep the Python and Matlab libraries consistent. |
Hi, And yes, |
Just done some comparison with matlab. I noticed that the number of I also checked iterations with Provided the problem is not just due to different ways of rounding off in Matlab and python, we would need to check every small function one-by-one to nail down what makes this difference appear. I would probably do that but it may take some time before I have the time to commit to this. Happy if you want to go ahead and try to discover where discrepancies occur, otherwise we can just keep this Issue open until we solve this. |
Regarding opt_tol, I understand about having this tolerance for computations where we are driving a residual down to zero. I didn't expect this for the BPDN problem, but maybe it was easier for the authors to not have a special case for this. In any case, I think you are right that it makes sense to update the documentation, and hopefully that will help most people. I suppose in the future one could set opt_tol = 0 for the BPDN problem always, or something like that. As far as matching Matlab, I'm not really that familiar with the SPGL1 algorithm, so I won't be of much help in hunting down the discrepancy. It is interesting that it is a slow divergence. I wonder what could be the source. But I agree that for practical purposes it probably doesn't matter that much at this point, as the sparse solutions are generally "good" sparse approximations of x either way. |
I am trying to use SPGL1 to solve the Basis Pursuit Denoise problem:
minimize ||x||_1 subject to ||Ax - b||_2 <= sigma.
When I run spgl1 with the sigma keyword argument, it sometimes stops with exit status 1 (root found), but the sigma criterion is not met. I am confused why this is. It seems to depend on the opt_tol keyword argument, but the effect of this parameter is not clear from the BPDN equation nor from the spgl1 documentation.
I have attached a dataset and sample script to show the behavior I am talking about.
Furthermore, I noticed while preparing this script that the output of the Python and Matlab libraries is not identical. Is this to be expected?
spgl1_bug.zip
The text was updated successfully, but these errors were encountered: