Clear Filters
Clear Filters

Optmization with fmincon using an external software

2 views (last 30 days)
AM on 29 Nov 2018
Commented: dpb on 30 Nov 2018
I have a problem and I do not know how to solve it. I’ll try my best in explaining.
I am optimizing an objective function to fit my data to experimental values by using fmincon. I have boundaries and equality constraints. My objective function (sum of squares of the differences) calls a function that calculates the data to compare to the experimental points.
At first I wanted to learn how fmincon worked so I coded a function “pts_model” that calculates the data. I used fmincon with this function and it fits the data to the experimental points perfectly. But now I am using an external software that does the same thing that “pts_model” (which I will have to use for more complex problems that “pts_model” cannot solve).
Before trying the optimization using the external software I tested the results given by “pts_model” and the ones given by the external software when matlab calls it and the results are the same (difference less than 1E-01 for each point).
However, when I launch fmincon with the external software it does not give the same results than with “pts_model”. Fmincon + external software does an optimization but it is not near as good as the one from fmincon + “pts_model”. The more variables there are the less similar the results are.
To try to understand what the problem is I checked the gradient and search direction during the optimization of both cases but I do not know how to interpret them.
I have attached a file with the results from an optimization with 24 decision variables. I didn't put the results from all iterations but just the first and last.
I am lost at to what to do, I do not understand why I have different results. Both start at the same point and give the same results at that point but somehow the search direction is not the same for both cases on some variables.
I do not know if the information I've given here is enough to understand my problem or get an idea of where the problem might come from but I can provide further information.
If anyone would be kind enough to help I would really appreciate it.
Thank you
AM on 30 Nov 2018
I tried central differences with 'Honorbounds','false' with the interior-point algorithm and this time I get satisfactory results, thank you!
The only problem is that the computational cost is really high (one call to my external software takes around 2-3 seconds) so something that I can solve with my code in seconds can take up to one hour with matlab+external software (I know it could be sped up if I provided the gradient but in my case finding an expression for it is rather difficult). But anyways, at least now I get the desired results.
Thank you for your help!
dpb on 30 Nov 2018
Yes, that's an expected (albeit unfortunate) side effect.
You could try other permutations; the obvious one is to leave 'Honorbounds','false' but revert to default for the differences and see if it was, indeed, just the bounding limits causing the difficulties.
Alternatively, it's likely you would have to find another way to estimate the derivatives besides the numerical calculation and for many models that is very difficult to do in general, granted.

Sign in to comment.

Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!