Not enough input arguments for 'bayesopt'?

13 ビュー (過去 30 日間)
Luka Znidaric
Luka Znidaric 2019 年 3 月 13 日
コメント済み: Aden Lee 2020 年 5 月 18 日
Hello,
I just started with MATLAB today and was doing most of my work in Python so far. I need to use MATLAB for some specific project and im lost. I wanted to use BayesianOptimization tool 'bayesopt', but i can't seem to get it to work even for simple tasks.
My code:
x=optimizableVariable('x1',[-1 1]);
BayesObject=bayesopt(fun1,[x]);
fun1(0);
function y=fun(x)
y=x^2;
end
function [objective] = fun1(x)
objective=x^2
end
Which returns errors:
>> PythonTest
Not enough input arguments.
Error in PythonTest>fun1 (line 13)
objective=x.^2
Error in PythonTest (line 3)
BayesObject=bayesopt(fun1,[x]);
I hope someone can help me. Thank you very much.
  1 件のコメント
Luka Znidaric
Luka Znidaric 2019 年 3 月 13 日
I managed to get it working with:
var=optimizableVariable('x1',[-1 1]);
BayesObject=bayesopt(objfun,[var]);
objfun=@(x) fun(x)
function y=fun(x)
y=x^2;
end
But now i get errors:
Undefined operator '^' for input arguments of type 'table'.
Error in PythonTest>fun (line 8)
y=x^2;
Error in PythonTest>@(x)fun(x)
Error in BayesianOptimization/callObjNormally (line 2553)
Objective = this.ObjectiveFcn(conditionalizeX(this, X));
Error in BayesianOptimization/callObjFcn (line 481)
= callObjNormally(this, X);
Error in BayesianOptimization/runSerial (line 1989)
ObjectiveFcnObjectiveEvaluationTime, ObjectiveNargout] = callObjFcn(this, this.XNext);
Error in BayesianOptimization/run (line 1941)
this = runSerial(this);
Error in BayesianOptimization (line 457)
this = run(this);
Error in bayesopt (line 323)
Results = BayesianOptimization(Options);
Error in PythonTest (line 3)
BayesObject=bayesopt(objfun,[var]);
Can somebody maybe help me with this?
Thanks in advance, have a nice day!

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

回答 (1 件)

Alan Weiss
Alan Weiss 2019 年 3 月 13 日
Please look at the documentation on Bayesian objective functions. The bayesopt solver passes a table to the objective function. To access variables in the table, use dot notation.
function y = fun(t)
y = t.x1^2;
end
Alan Weiss
MATLAB mathematical toolbox documentation
  2 件のコメント
Luka Znidaric
Luka Znidaric 2019 年 3 月 13 日
Thanks Alan! With your help and some more tinkering of my own I managed to get it working for now.
Be well!
Aden Lee
Aden Lee 2020 年 5 月 18 日
Mind to share what changes you have made to your code ? I'm interested.

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

カテゴリ

Help Center および File ExchangeClassification についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by