Optimize the more than one variable in bayesopt
9 ビュー (過去 30 日間)
古いコメントを表示
Hi;
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,...
'IsObjectiveDeterministic',true,...
'PlotFcn',[],'verbose',1,'MaxObjectiveEvaluations',30,...
'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"
end
1 件のコメント
xu supeng
2022 年 2 月 21 日
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)
x=tbl.v1;
y=tbl.v2;
rel=f(x,y);
end
function output=f(x,y)
output=x^2+(y-2)^2;
end
採用された回答
Alan Weiss
2022 年 2 月 15 日
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
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!