How to use bayesian optimization?
10 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!