Optimize the more than one variable in bayesopt

12 views (last 30 days)
I am using 2d(input) and want to find the expected value of the predictive function of the surrogate model(GPR)
I am not sure either I am treating my optimizableVariable correctly or not because its not working properly.
Any help could be a huge favor.
X1 = optimizableVariable('X1',[0,1]); % variable to optimize on interval [0,1]
X2 = optimizableVariable('X2',[0,1]); %variable to optimize on interval[0,1]
opt_v = [X1,X2];
% function handle to optimize x on
objective_function = @(x)expectedvalue(x,model); %define objective function to be optimize
rng(1); %for reproducibility
BO_expectedvalue = bayesopt(objective_function,opt_v,...
'NumSeedPoints',10); % Bayesian optimization loop of expected value % Important: this is a sub-optimization problem, which is solved here again, with Bayesian Optimization
x_maximum = bestPoint(BO_expectedvalue,'Criterion','min-observed').X1; % argmax of the expectedvalue function
y_maximum = predict(model,x_maximum);
%objective function is:
function objective = expectedvalue(x,model)
%this function serves as the objective function in an optimization routine
[y_pred,~] = predict(model,x.opt_v);%generates expected value of predictive function of the surrogate model
objective = -y_pred; % must be negative since objective is minimized in MATLAB routine "bayesopt"
  1 Comment
xu supeng
xu supeng on 21 Feb 2022
Not sure whether this can help, but I finally change my previous program in a more clean way like this, then you don't need to use predict, and I don't understand your question clearly(from email), if you want to use more variables, just set it, if you want to optimize multi-objective function, then you may need to combine them into one objective function.
xrange = optimizableVariable('v1',[-2,2],'Type','real');
yrange = optimizableVariable('v2',[-5,5],'Type','real');
var=[xrange yrange];
bayesObject = bayesopt(@(tbl)mdlfun(tbl),var,...
'MaxObjectiveEvaluations',50); % iteration numbers
function rel = mdlfun(tbl)
function output=f(x,y)

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 15 Feb 2022
I believe that the error is in this line:
[y_pred,~] = predict(model,x.opt_v);
The software passes a table of values in x, with the two values x.X1 and x.X2. I am not sure what predict accepts as an argument, but x.opt_v is not passed and is not available, only x is passed. So you might need a line or two of code to convert the passed value x to whatever form predict accepts.
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by