How can I apply bayesopt to my Simulink model?

3 次查看(过去 30 天)
Dear all,
I'm doing a thesis about semi-active suspension, systems that can only change the viscous damping coefficient of the shock absorber. The case that I'm studying is with magneterheological damper, which is a damper filled with magneterheological fluid. This kind of fluid can change viscosity changing the magnetic field.
I did in Simulink the quarter car model, now my purpose is to find the best value of my control variable "u_MR" (constant value), that maximize the passenger comfort. The comfort is evaluated with the index of performance "J", calculated as the RMS of the (vertical) acceleration, which is the final output of my model.
Thus, the problem is to find the optimal value of uMR that minimize the index "J" using the Bayesian Optimization and in Matlab the function bayesopt().
I'm finding problems writing the objective function, input of the bayesopt function...
The other input of bayesopt() is the variable:
uMR_opt = optimizableVariable('uMR',[0,f_max]);
I have the acceleration, which is a vector, result of the simulation that I can extract in Matlab and than I can calculate the index "J" (which is a single value, e.g. J = 1.6 m/s^2), but than I don't know how to write the objective function, related to this.
out = sim("quarter_car_model.slx");
%extracting the acceleration from simulink
output_xs2punti = getElement(out.yout, 'xs_2punti');
xs_2punti = output_xs2punti.Values.Data(:);
J_sim = rms(xs_2punti); %index of performance
Any suggestion on how to do the objective function?
Thanks to all

采纳的回答

Alan Weiss
Alan Weiss 2021-11-2
As the documentation states, the objective function accepts a 1-by-D table of values, where D is the number of variables. So you need to write your objective function like this:
function J_sim = fun(x)
xval = x.uMR; % x is a table, xval is a scalar represending the uMR value
% Call your simulation with xval as the uMR value. Then
output_xs2punti = getElement(out.yout, 'xs_2punti');
xs_2punti = output_xs2punti.Values.Data(:);
J_sim = rms(xs_2punti); %index of performance
end
Alan Weiss
MATLAB mathematical toolbox documentation
  3 个评论
Alan Weiss
Alan Weiss 2021-11-2
As the documentation states, fun should be a function handle to your objective function. If you write your objective function the way I just showed, your bayesopt call would be
results = bayesopt(@fun,uMR_opt,'AcquisitionFunctionName','expected-improvement');
If you need to pass extra parameters or data to your objective function, such as a workspace variable or structure params, then your function would be
function J_sim = fun(x,params)
% code goes here
end
and you call it like this:
results = bayesopt(@(x)fun(x,params),uMR_opt,'AcquisitionFunctionName','expected-improvement');
Alan Weiss
MATLAB mathematical toolbox documentation

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model Building and Assessment 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by