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 CenterFile Exchange에서 Classification에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by