[Optimization] Optimization of complex models

3 Ansichten (letzte 30 Tage)
Emanuel Crespo
Emanuel Crespo am 19 Okt. 2018
Bearbeitet: Stephan am 22 Okt. 2018
Dear all,
First of all sorry for the long post
I have a fairly complex model coded in MATLAB that allows the calculation of different fluid properties at given conditions. To make it simpler imagine that all resumes to a routine for instance [Surface_Tension]=surf_ten_calc(z,T,P) that for a given fluid composition z, temperature T and pressure P calculates the surface_tension.
The function surf_ten_calc calls (several times) the model for instance because this function requires the values of surface_things obtained through [Surface_things]=modelmodel(x1,x2,x3,x4,x5,z,T,P) to obtain the surface_tension.
The model is quite complex and with some subroutines on the way but the parameters x1,x2,x3,x4 and x5 must be obtained by minimizing the difference to experimental values of Surface_Tension for instance at different z values.
My question is that the code works fine when the optimization can be carried using a relatively small amount of experimental data but if the fitting needs to be carried using large amounts of data it can easily become too much time consuming. I've been using different optimization routines such as fminsearch, fmincon and patternsearch (best results seem to be obtained with fminsearch) when small amount of Surface_Tension values need to be calculated per iteration but now a recent expansion of the model requires the fitting to consider larger amounts of experimental data and consequently a larger number of calculations need to be performed per iteration.
I tried to use fmincon with use parallel option to speedup the process and/or use parfor cycles in the objective function routine for the calculation of surface tension at different z values but saw no impact on decreasing the computational cost.
What else can I try? Is it worth to try to use GAMS to do the optimization part and GAMS calling the [Surface_Tension]=surf_ten_calc(z,T,P) routine? (actually I don't even know if this is possible but I am willing to try almost anything).
Best regards and thanks for any help you can provide
Emanuel
  2 Kommentare
Stephan
Stephan am 19 Okt. 2018
Hi,
maybe your code can be optimized - but we do not know, since we do not know your code. You have given us a lot of information, but the informations we would need to make advices are not given. The informations we got so far are too less to really help. If possible provide your code or the relevant parts of it. Else it is hard to help.
Emanuel Crespo
Emanuel Crespo am 22 Okt. 2018
Hi, I can't provide details on the inner code as the model itself is proprietary but it consists mainly on for cycles carrying many different kinds of summations and while loops for assuring convergence of inner variables.
On the "outside" I call the objective function through a file main_optimization.m which reads experimental data, which parameters to be fitted, and calls a certain solver (see below):
%options=optimset('Display','iter','TolFun',1E-6,'MaxIter',10); options2=optimset('Display','iter','TolFun',1E-6,'MaxIter',10,'UseParallel',true); lb=[1.4 3.2 290 2600 2000]; ub=[2.3 3.9 370 4800 4000]; fun=@(x)optimiza_UATh_2B(x,xoriginal,saftparam,resposta,PesoRHO,CRITICAL,Tpvap,pvap_exp,NPrho,NTrho,Trho_exp,Prho_exp,rho_exp);
nciclo=1; %[X,fval,exitflag,~]=fminsearch(fun,x0,options); %[X,fval,exitflag,~]=fmincon(fun,x0,[],[],[],[],lb,ub,[],options2); [X,fval,exitflag,output]=patternsearch(fun,x0,[],[],[],[],lb,ub,[],options2);
The objective function is nothing more than the difference between experimental and model data so it needs to repeatedly call for example bubble_point routine who calls the model several times.
As I said the code does the job when I don't need to fit the parameters to many different sets of experimental data but once I increase the number of calls to bubble_point in the objective function it can easily get too time-consuming.
I tried to use parfor loops in the objective function for the different calls to the bubble_point routine and/or use parallel on the fmincon options but no speed improvement was observed. Is there anything else I can try? perhaps parfor loops in the model instead of objective function?
Thank you! Emanuel

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephan
Stephan am 22 Okt. 2018
Bearbeitet: Stephan am 22 Okt. 2018
Hi,
since you can not provide any details, only general information can be given. Read the following links and have also a look to the section Related Topics / Related Examples of all the sites:
  1. Vectorization
  2. Technics to improve Performance
  3. Measure Performance of Your Program
  4. Profile to Improve Performance
  5. Preallocation
  6. Usage of Matlab Coder
Maybe that your code can be improved by one or more of these advices - i dont see that i can do much more for you under the given circumstances.
Best regards
Stephan
  2 Kommentare
Emanuel Crespo
Emanuel Crespo am 22 Okt. 2018
Thank you, I will take a look at the links provided. Just one question, do you think any speed improvement can be achieved by compiling the code? Vectorization probably I can still improve something else. I will try it. Regards, Emanuel
Stephan
Stephan am 22 Okt. 2018
I have no own experiences with compiled code, due to this is not offered for home licenses :-(
But you are right, this is also a possible way for improving performance, like the documentation says:
You can also use the generated code within the MATLAB environment to accelerate computationally intensive portions of your MATLAB code
I will add this link to my answer, in order to complete it.
I wish you success!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by