Not enough input arguments for 'bayesopt'?

13 Ansichten (letzte 30 Tage)
Luka Znidaric
Luka Znidaric am 13 Mär. 2019
Kommentiert: Aden Lee am 18 Mai 2020
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 Kommentar
Luka Znidaric
Luka Znidaric am 13 Mär. 2019
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!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Alan Weiss
Alan Weiss am 13 Mär. 2019
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 Kommentare
Luka Znidaric
Luka Znidaric am 13 Mär. 2019
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 am 18 Mai 2020
Mind to share what changes you have made to your code ? I'm interested.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by