Variables for a Bayesian Optimization - MATLAB & Simulink (original) (raw)

Main Content

Syntax for Creating Optimization Variables

For each variable in your objective function, create a variable description object using optimizableVariable. 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 bound Range(1) to the upper bound Range(2).

You can specify three types of variables in the Type name-value argument:

For 'real' or 'integer' variables, you can specify thatbayesopt searches in a log-scaled space by setting theTransform name-value argument to 'log'. For this transformation, ensure that the lower bound in the Range is strictly positive for 'real' and nonnegative for'integer'.

Include variables for bayesopt as a vector in the second argument.

results = bayesopt(fun,[xvar,ivar,rvar])

To exclude a variable from an optimization, set Optimize tofalse, either in the name-value argument of optimizableVariable, or by dot notation:

Tip

Variables for Optimization Examples

Real variable from 0 to 1:

var1 = optimizableVariable('xvar',[0 1])

var1 = optimizableVariable with properties:

     Name: 'xvar'
    Range: [0 1]
     Type: 'real'
Transform: 'none'
 Optimize: 1

Integer variable from 0 to 1000 on a log scale:

var2 = optimizableVariable('ivar',[0 1000],'Type','integer','Transform','log')

var2 = optimizableVariable with properties:

     Name: 'ivar'
    Range: [0 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

See Also

Topics