MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

Not enough input arguments for 'bayesopt'?

Luka Znidaric さんによって質問されました 2019 年 3 月 13 日
最新アクティビティ Luka Znidaric さんによって コメントされました 2019 年 3 月 13 日
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 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!

サインイン to comment.

製品


リリース

R2018b

1 件の回答

回答者: 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

  1 件のコメント

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!

サインイン to comment.



Translated by