I'm trying to optimize 3 parameters using genetic algorithim (or simulated annealing, the fit is not complicated both algorithims can reach the min.). The problem can be summarized as follows:
- run an external software to get the data (this data is dependent on the parameters i want to optimize)
- extract the data from the run in part 1 and comapre it with the exp. data by calculating a cost function
- do an iteration to optimize the parameters and use the new parameters to run the software as in part 1
- compare the data again as in part 2 and repeat until the cost function reaches a minimum
I've done most of the code, to extract the data and run the software from matlab. I also programmed the function containing the 'cost function' and the file containing the optimization scheme. However, I cannot connect all the 3 files. For clarification i show here the optimizer and the cost function codes.
The code below takes md_e and E_best_vals_from_md_r and these are sets of data from step 2 to calculate the cost function
E_diff_sq(m,1) = (md_e(m,1)-E_best_vals_from_md_r(m,1))^2;
E_down_sq(m,1) = (E_best_vals_from_md_r(m,1))^2;
The code below is the optimizer code, and it is incomplete as this is my problem.
opt_opts.FunctionTolerance = 1E-9;
opt_opts.MaxGenerations = 50000000;
opt_opts.MaxStallGenerations = 50000000;
opt_opts.PlotFcn = "@gaplotbestf";
opt_opts.HybridFcn = "patternsearch";
opt_opts.MigrationDirection = 'both';
opt_opts.MigrationInterval = 100000;
opt_opts.PopulationSize = 1000;
opt_opts.FitnessLimit = -inf;
ub = [ Inf ; Inf ; Inf ];
[best_fit_param,fval] = ga(f,3,,,,,lb,ub,,opt_opts)
The issue is that I'm not able to connect the optimizer code to the cost function and consquently to the parameters that I want to fit. The parameters that I want to fit are in another long code which i did not attach. In short, my question is how to connect these two codes with the code that gets the data to optimize the parameters which I send to the external software to get the data which i use to calculate the cost function.
Sorry for the lengthy question and I hope you will assist me.