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"
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.
MATLAB mathematical toolbox documentation