Not enough input arguments for 'bayesopt'?

13 visualizaciones (últimos 30 días)
Luka Znidaric
Luka Znidaric el 13 de Mzo. de 2019
Comentada: Aden Lee el 18 de Mayo de 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 comentario
Luka Znidaric
Luka Znidaric el 13 de Mzo. de 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!

Iniciar sesión para comentar.

Respuestas (1)

Alan Weiss
Alan Weiss el 13 de Mzo. de 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 comentarios
Luka Znidaric
Luka Znidaric el 13 de Mzo. de 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 el 18 de Mayo de 2020
Mind to share what changes you have made to your code ? I'm interested.

Iniciar sesión para comentar.

Categorías

Más información sobre Classification en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by