fmincon doesn't give me the same results as in the previous version !!
Mostra commenti meno recenti
Hi, please I need your help! In fact, I have just started using the version R2013a of Matlab. To my surprise fmincon doesn't give me the same results as in the previous version (that run without any problem on another Matlab version R2007b and I have had a good results). Thanks Best Regards
17 Commenti
Matt J
il 25 Ott 2013
There have been changes since R2007b, so it doesn't seem crazy that there might be differences in output.
But what makes you so sure the new solution isn't equivalent to the old one?
Mary Ben
il 25 Ott 2013
John D'Errico
il 25 Ott 2013
It is virtually impossible to answer this as asked. Did something change? Of course it probably did in a 6 year span of time. Is any change assuredly what has caused your problem? Not necessarily, because all too often there are other issues. How did you transfer things to the new release? Too often one sees numerical issues, because the user simply copied some numbers from the command window, losing a great deal of precision. Did you use the new version properly? There is simply not enough accurate information provided here to make an answer.
Mary Ben
il 25 Ott 2013
Walter Roberson
il 25 Ott 2013
Code and example of "correct" output would help us understand.
Mary Ben
il 25 Ott 2013
Walter Roberson
il 25 Ott 2013
There doesn't seem to be an attached file at the moment.
Mary Ben
il 25 Ott 2013
Walter Roberson
il 25 Ott 2013
You did not include the code for "func", and for the run you showed, you did not indicate whether it was the R2007b or R2013a execution; which-ever it was, you did not show the other one.
Mary Ben
il 26 Ott 2013
Walter Roberson
il 26 Ott 2013
Well I was going to run the code against multiple versions of MATLAB to study the behaviour. But it turns out I don't have the necessary toolbox anyhow.
I think is not interresting to show you the code of "func.m", my problem is no there! because it works well with R2007b.
We just can't take your word for it that the mistake is in MATLAB and not in your own code, and certainly not without an example that we can run that reproduces the problem. The odds are against the issue being in fmincon. If there were a systematic problem in fmincon R2013, more people would be seeing it.
In any case, there is no simple switch that tells fmincon to behave as in R2007b.
If your func.m is too long, create a simpler example for us. If you cannot create a simple example that reproduces the differences, it's all the more likely that it is some weakness in func.m specifically that R2007 doesn't expose. Sometimes code seems to be behaving well when it isn't. A person might like how warm their house is in the winter time and think everything's great, until they discover that it's on fire!
Walter Roberson
il 26 Ott 2013
I did not find anything as I do not have the func.m to look at.
Walter Roberson
il 26 Ott 2013
Nothing seems to be attached ?
Walter Roberson
il 27 Ott 2013
The source you emailed me is not long, and could easily be posted here. However, it relies upon loading a number of data files that we do not have access to.
Also, it requires the Statistics toolbox for normcdf, as well as the Optimization toolbox for fmincon
Risposta accettata
Più risposte (4)
Mary Ben
il 27 Ott 2013
0 voti
29 Commenti
Matt J
il 29 Ott 2013
ExampleFunc.zip contains data used by func.m, but I cannot see where it contains the solution you obtained from R2007 and R2013.
Mary Ben
il 29 Ott 2013
Your function main() will not work because you haven't defined A, inB, Ab1 and others. Please give complete code that can be run start to finish.
for the solution of R2007b I can't get it back
What do you mean you can't get it back? You created this example just a few days ago and you verified at that time that it produces a significantly different answer from R2007b.
Mary Ben
il 29 Ott 2013
Myriam, I am confused about what you're saying you can provide. If I have both R2007 and R2013 installed on my computer, do you have a small example that I can run that you think will give me significantly different results on each? And, can you give me a .mat file with the final result of fmincon that you expect me to obtain in each case?
Mary Ben
il 29 Ott 2013
Matt J
il 29 Ott 2013
Yes. That's what I asked you. Do you have a small example? Yes or No.
Mary Ben
il 29 Ott 2013
no I don't have because the Image Iuse it's very large, with R20013a I obtain:
If we can't run it, there's no use in sending us part of it. My suggestion would be this:
- Re-install R2007b, but do not uninstall R2013a.
- Re-run your code on both R2007b and R2013a.
- Save the fmincon results from both versions to .mat files. By "results", I mean not only xl but also [fval, exitflag,outputStruct]
- Load both solutions xl from the .mat files into R2007b. Compute the objective function values of both solutions and similarly the results of constraint functions. Save those. Do the same in R2013a.
- Report/post all of the above to us.
My best guess for now is that your function might have multiple global minima. Problems with a continuum of non-unique global solutions are unstable and small changes in implementation can give drastically different results. In any case, the above data will give us a hint whether this is what's occuring.
Matt J
il 31 Ott 2013
please See attached file my results with R2008b and R2013a.
Were these run on the same data? From the plots, it doesn't look like it.
Both in the first .zip file and the second one that you posted, the data scatter plots in R2008 and R2013 look different. Also, the initial f(x) values printed out by fmincon are definitely different. In R2008, I see f(x0)=41.1541 whereas in R2013, I see f(x0)=41.1526.
Therefore, your function implementation, your data, your initial guess or a combination of these have changed.
Mary Ben
il 31 Ott 2013
Mary Ben
il 1 Nov 2013
Matt J
il 1 Nov 2013
Because the function and initial point may be totally different.
Mary Ben
il 1 Nov 2013
In the Word doc you sent, the R2008 fmincon output printed the following initial iteration data to the screen

whereas the R2013 fmincon output was

Do you understand what the entries f(x)=41.1541 and f(x)=41.1526 mean? Do you understand why it is significant that they are different? They are the initial values f(x0) of your objective function before fmincon has started to do any work. If you are minimizing the same f(x) starting from the same initial point x0 in both R2008 and R2013, these values should be very much the same.
Since they are not the same then, to repeat, you have a difference either in f() or in x0. It is not an fmincon issue. You should put those things under a microscope and see why f(x0) is not the same in both versions.
Matt J
il 1 Nov 2013
it's normal to obtain a different f(x0) because f() is related to the points of the plot
If f() depends partly on the scattered point data and you are using a different set of points in each test then why do you expect the tests to be comparable!?!?!
Matt J
il 1 Nov 2013
Well, you need to verify that. Before you blame a difference between R2008 and R2013, you need to run the exact same experiment in both.
Mary Ben
il 1 Nov 2013
12 Commenti
Matt J
il 5 Nov 2013
Something like the following
>> x=rand(1,5); x(6)
Index exceeds matrix dimensions.
happened at line 68 in your objective function. DBSTOP should have put you on that line, where you can check the sizes of evec3 and xl.
but when I start using fmincon I have xl=[]
You may have verified fun(x0) when x0 is the input, but the error is being generated by a different input x1 (which you don't know). The whole point of using DBSTOP is to trap the event where fmincon sends x1 to fun() and to freeze program execution at that moment. You can then see what x1 is and investigate why it leads to xl=[].
it is me who chooses xl = []
Why would you choose this if you are going to index into xl?
If xl=[], then the expression xl(1:m) is obviously illegal for m>=1. You cannot index something that is empty,
>> xl=[]; m=3; xl(1:m)
Index exceeds matrix dimensions
Mary Ben
il 5 Nov 2013
Matt J
il 5 Nov 2013
You may have forgotten that we haven't see the code, don't know what it's doing, and don't know what lines come before and after line 68. We therefore can't know what line 68 is trying to accomplish and how it should be changed.
If N is the number of unknown variables, you must pass fmincon an initial guess vector x0 of length N. Among other things, this is how fmincon knows how many unknowns to try to solve for.
Incidentally, it is bad practice to load fixed data to your fun.m from .mat files. See here for better ways to pass fixed known parameters to functions,
Mary Ben
il 5 Nov 2013
4 Commenti
Matt J
il 7 Nov 2013
Use mex -setup to specify a compiler. You would have had to do this in any new installation of MATLAB.
Mary Ben
il 7 Nov 2013
Matt J
il 7 Nov 2013
Hmmm. What about what it says about SDK? Are you sure it's installed? To be certain, it might be worthwhile just reinstalling both MS Visual C++ and SDK.
In any case, if you continue to have problems, I would post it as a new question/topic. It will have better visibility to the community that way.
Mary Ben
il 8 Nov 2013
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
