I'm trying to apply conditional constraints on two variable with bayesopt

4 次查看(过去 30 天)
here are part the paramters i'm trying to optimize
optimVars = [optimizableVariable('numlayers',[20 25],'Type','integer')
optimizableVariable('LR',[1e-3 1e-1],'Transform','log')
optimizableVariable('MBS',[20 32],'Type','integer')
optimizableVariable('RP',[1e-3 1e-1],'Transform','log')];
function Xnew = condvariablefcn(X)
Xnew=X;
Xnew.L2Regularization(Xnew.numLayersToFreeze==24) = NaN;
end
but when i run the code, i get this message :
Error using BayesianOptimization/applyXConstraint
The XConstraintFcn must return a logical column vector the same height as
its input (10000), but it returned an object of class table with size
[10000 4].
the code runs fine before i added this constraint. so what is the problem with the function?

回答(1 个)

Alan Weiss
Alan Weiss 2022-8-2
I think that you set the wrong name-value argument for your constraint function. bayesopt thinks that you are using an XConstraint, not a conditional constraint. In your bayesopt call set the name-value argument like this:
results = bayesopt(fun,vars,'ConditionalVariableFcn',@condvariablefcn)
Alan Weiss
MATLAB mathematical toolbox documentation

类别

Help CenterFile Exchange 中查找有关 Model Building and Assessment 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by