I keep getting "Error using / Arguments must be numeric, char, or logical. " in bayesopt.

2 ビュー (過去 30 日間)
DODO
DODO 2023 年 2 月 7 日
コメント済み: Jan 2023 年 2 月 8 日
Hi, I'm trying to use "bayesopt", but I keep getting this error.
What did I do wrong?
%% BayesOpt
fxc = @(x) cos(2*pi*(x/4))+exp(x/5);
xvar = optimizableVariable('x',[0,10],'Type','real');
res = bayesopt(fxc,xvar,'MaxObjectiveEvaluations',10,'PlotFcn',[],'AcquisitionFunctionName','lower-confidence-bound','ExplorationRatio',.1);
figure;
plot(res, @plotAcquisitionFunction);
figure;
plot(res,@plotObjectiveModel);
res=resume(res,'MaxObjectiveEvaluation',1);

回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 2 月 7 日
doc bayesopt
fun accepts x, a 1-by-D table of variable values, and returns objective, a real scalar representing the objective function value fun(x).

Jan
Jan 2023 年 2 月 7 日
Anonymous functions are compact, but less useful for debugging. Use a normal function instead:
fxc = @yourFcn;
xvar = optimizableVariable('x',[0,10],'Type','real');
res = bayesopt(fxc, xvar, 'MaxObjectiveEvaluations', 10, ...
'PlotFcn', [], 'AcquisitionFunctionName', 'lower-confidence-bound', ...
'ExplorationRatio', 0.1);
...
function y = yourFcn(x)
y = cos(2 * pi * x / 4) + exp(x / 5);
end
Run the code again. Now I'd expect it to fail inside yourFcn. Use the debugger to check the details:
dbstop if error
This let Matlab stop, when an error occurs. Run the code again, and when it stops, examine the class of x in the command window:
class(x)
What do you see?
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 7 日
I had to use dbstop if caught error
Jan
Jan 2023 年 2 月 8 日
@DODO, @Walter Roberson: Yes, if the failing code is included in a TRY/CATCH block, "caught error" is the correct trigger to find the line causing the error.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by