How do I use genetic algorithm from Global Optimization Toolbox to optimize parameters in a simulink model?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I have a simulink model of a real-world device that contains roughly 40 different parameters. I want to optimize values of some parameters using the genetic algorithm provided in Global Optimization Toolbox. I tried to use the problem based approach by defining my own fitness function, injecting values of target parameters to the simulink components that depend on them for each individual in a generation, running the simulation and evaluating the value of the fitness function based on the executed simulation output array.
The thing is... I have no idea what I'm doing wrong.
I pass every parameter I want to optimize to my objective function and run the simulation inside it, but for some reason I get the error:
"Error using optim.internal.problemdef.ProblemImpl/solveImpl
solve failed because the problem has non variables. A problem objective or constraint must contain at least one variable. [...]"
Here's a piece of code after which the error occurs:
% Solve problem
[solution2,objectiveValue,reasonSolverStopped] = solve(problem,initialPoint8,...
"Solver","ga","Options",options3);
And here's my objective function:
function objective = sum_of_square_diff(alfa_r_ga, E0_ga, ...
mi_ga, mi2_ga, mi_s2_ga, V_s_ga, ro_ga, ku_ga, V_n_ga, trace_y, x)
alfa_r = alfa_r_ga;
E0 = E0_ga;
mi = mi_ga;
mi_2 = mi2_ga;
mi_s2 = mi_s2_ga;
V_s = V_s_ga;
ro = ro_ga;
ku = ku_ga;
V_n = V_n_ga;
%run the simulation
sim('Model/Copy_of_msim');
adjusted_measured_piston_position = trace_y(2, :);
diff = adjusted_measured_piston_position - 1000 * x'; % 'x' is the output array of the model
objective = sum(diff.^2);
end
Thank you in advance for the help.
댓글 수: 4
Paul
2024년 3월 18일
If hasn't been done already, I recommend verifying that the function sum_of_square_diff works the way it's intended. Just call it from the command line with appropriate input arguments and see if the result makes sense. I see at least two problems:
1. When calling sim from inside a fucntion, Simulink does not pull in parameters, like E0, mi, etc, from the function workspace. Check into using Simulink.SimulationInput
2. Similarly, the outputs from the simulation don't show up in the function workspace. Check into calling sim with an output argument.
I'm not sure about simulating a model named 'Model/Copy_of_msim'. I've never seen a model with a / in its name.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!