For each variable in your objective function, create a variable description object usingoptimizableVariable
. Each variable has a unique name and a range of values. The minimal syntax for variable creation is
variable = optimizableVariable(Name,Range)
This function creates a real variable that ranges from the lower boundRange(1)
to the upper boundRange(2)
.
You can specify three types of variables in theType
name-value pair:
'real'
— Continuous real values between finite bounds. GiveRange
as the two-element vector[lower upper]
,代表下限和上限。
'integer'
— Integer values between finite bounds, similar to'real'
.
'categorical'
— Cell array of names of possible values, such as{'red','green','blue'}
, that you specify in theRange
argument.
For'real'
要么'integer'
variables, you can specify thatbayesopt
通过设置来搜索日志缩放的空间Transform
name-value pair to'log'
. For this transformation, ensure that the lower bound in theRange
is strictly positive.
Include variables forbayesopt
作为第二个论点的矢量。
results = bayesopt(fun,[xvar,ivar,rvar])
To exclude a variable from an optimization, set优化
tofalse
, either in the name-value pair ofoptimizableVariable
, or by dot notation:
xvar.Optimize = false;
Tip
There are two names associated with anoptimizableVariable
:
The MATLAB®workspace variable name
The name of the variable in the optimization
例如,
xvar = optimizableVariable('spacevar',[1,100]);
xvar
is the MATLAB workspace variable, and'spacevar'
是变量的优化。
Use these names as follows:
Usexvar
作为您传递的变量矢量中的元素bayesopt
. For example,
results = bayesopt(fun,[xvar,tvar])
Use'spacevar'
as the name of the variable in the optimization. For example, in an objective function,
function objective = mysvmfun(x,cdata,grp) SVMModel = fitcsvm(cdata,grp,'KernelFunction','rbf',... 'BoxConstraint',x.spacevar,... 'KernelScale',x.tvar); objective = kfoldLoss(crossval(SVMModel));
Real variable from 0 to 1:
var1 = optimizableVariable('xvar',[0 1])
VAR1 =具有属性的优化变性:名称:'XVAR'范围:[0 1]类型:“真实”变换:'无'优化:1
Integer variable from 1 to 1000 on a log scale:
var2 =优化不变('ivar',[1 1000],'Type','integer','Transform','log')
var2 = optimizableVariable with properties: Name: 'ivar' Range: [1 1000] Type: 'integer' Transform: 'log' Optimize: 1
Categorical variable of rainbow colors:
var3 = optimizableVariable('rvar',{'r''o''y''g''b''i''v'},'Type','categorical')
var3 = optimizableVariable with properties: Name: 'rvar' Range: {'r' 'o' 'y' 'g' 'b' 'i' 'v'} Type: 'categorical' Transform: 'none' Optimize: 1