How to use bayesian optimization?

조회 수: 8 (최근 30일)
Tessa Kol
Tessa Kol 2020년 10월 7일
댓글: Tessa Kol 2020년 10월 19일
Dear all,
I am trying to find a good way to use bayesian optimization that will give me the optimal simulation parameters that can approximate the experimental output closely. Below I wrote a code that first train the simuation data with gaussian process regression. Then I define a custom distance metric (i.e. relative error) which needs to be minimized in order to optimize the simulation input parameters.
%% Parameters
X = [0.1 0.5; 0.2 0.6; 0.4 0.2; 0.8 0.9]; %Simulation input parameters
Y = [3.6;3.7;3.3;4.1]; %Simulation output
%% Surogate modeling of the data set
% Train regression model
Model = fitrgp(X,Y,'KernelFunction','squaredexponential');
%% Optimization
Yr = 3.2; %Experimental reference output value
options = optimset('Display','iter','PlotFcns',@optimplotfval);
[x,fval,exitflag,output] = fminsearch(@(x)abs((predict(Model,x)-Yr)/Yr),[0.1 0.5],options)
I know that Bayesian optimisation is the use of Gaussian processes for global optimisation.
How can I define the custom distance metric as objective function for bayesian optimization?

답변 (1개)

Shashank Gupta
Shashank Gupta 2020년 10월 12일
Hi Tessa,
Try checking out bayesopt function. You have to write your own objective function for bayeopt to perform. while constructing the function you can use any distance matric. Please refer to small piece of placeholder code below and do check the documentation of bayesopt for more details.
function fval = myObjFunc(data)
x(1) = data.x;
x(2) = data.y;
% define function which return a measure of loss (such as a misclassification error)
% for a machine learning model that has tunable hyperparameters to control its training.
% you can define your distance metric here appropriately.
fval = .....
end
% Call bayesopt with the above function handle.
results = bayesopt(@myObjFunc,vars)
I hope this helps you or atleast give you headstart.
  댓글 수: 1
Tessa Kol
Tessa Kol 2020년 10월 19일
Dear Shashank,
My objective function is the distance metric. I checked the documentation, but as it seems to me this documentation only talks about cross-validation. Where the training set is split into one which is actually used for training, and the other, the validation set, which is used to monitor the performance. I try to optimize X so that it minimizes the objective function (i.e. distance metric).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Model Building and Assessment에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by