Connect the optimizer function to data extracted from another software
古いコメントを表示
Hi
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
function cost_func=e_and_r_vals(md_e,E_best_vals_from_md_r)
E_diff_sq = zeros(23,1);
E_down_sq = zeros(23,1);
for m = 1:23
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;
end
E_down = sum(E_down_sq);
E_up = sum(E_diff_sq);
cost_func = E_up/E_down;
end
The code below is the optimizer code, and it is incomplete as this is my problem.
%% Fit options
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;
%% Optimizer
% Do a ro
lb = [ 0 ; 0 ; 0 ];
ub = [ Inf ; Inf ; Inf ];
get_data;
f=@(~) e_and_r_vals(md_e,E_best_vals_from_md_r)
[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.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Solver Outputs and Iterative Display についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!