How to use bayesian optimization?

9 views (last 30 days)
Tessa Kol
Tessa Kol on 7 Oct 2020
Commented: Tessa Kol on 19 Oct 2020
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?

Answers (1)

Shashank Gupta
Shashank Gupta on 12 Oct 2020
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 Comment
Tessa Kol
Tessa Kol on 19 Oct 2020
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).

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!