Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

optimizableVariable

Variable description for bayesopt or other optimizers

Descripción

Create variables for optimizers.

Creación

Sintaxis

variable = optimizableVariable(Name,Range)
variable = optimizableVariable(Name,Range,Name,Value)

Description

ejemplo

variable = optimizableVariable(Name,Range) creates a variable with the specified name and range of values.

ejemplo

variable = optimizableVariable(Name,Range,Name,Value) sets properties using name-value pair arguments. For example, optimizableVariable('xvar',[1 1000],'Type','integer') creates an integer variable from 1 to 1000. You can specify multiple name-value pair arguments. Enclose each property name in quotes.

Propiedades

expandir todo

Variable name, specified as a character vector or string scalar. The name must be unique, meaning different from those of other variables in the optimization.

Nota

  • There are two names associated with an optimizableVariable:

    • The MATLAB® workspace variable name

    • The name of the variable in the optimization

    For example,

    xvar = optimizableVariable('spacevar',[1,100]);

    xvar is the MATLAB workspace variable, and 'spacevar' is the variable in the optimization.

    Use these names as follows:

    • Use xvar as an element in the vector of variables you pass to 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));

Ejemplo: 'X1'

Tipos de datos: char | string

Variable range, specified as a 2-element finite increasing real vector, or as a string array or cell array of names of categorical variables:

  • For real or integer variables, Range gives the lower bound and upper bound of that variable.

  • For categorical variables, Range gives the possible values.

Ejemplo: [-10,1]

Ejemplo: {'red','blue','black'}

Tipos de datos: double | string | cell

Variable type, specified as 'real' (real variable), 'integer' (integer variable), or 'categorical' (categorical variable).

Nota

The MATLAB data type of both 'real' and 'integer' variables is the standard double-precision floating point number. The data type of 'categorical' variables is categorical. So, for example, to read a value of a categorical variable named 'colorv' in a table of variables named x, use the command char(x.colorv). For an example, see the objective function in Custom Output Functions.

Ejemplo: 'Type','categorical'

Transform applied to variable, specified as 'none' (no transform) or 'log' (logarithmic transform).

For 'log', the variable must be 'real' or 'integer' and positive. The variable is searched and modeled on a log scale.

Ejemplo: 'Transform','log'

Indication to use variable in optimization, specified as true (use the variable) or false (do not use the variable).

Ejemplo: 'Optimize',false

Tipos de datos: logical

Nota

You can use dot notation to change the following properties after creation.

  • Range of real or integer variables. For example,

    xvar = optimizableVariable('x',[-10,10]);
    % Modify the range:
    xvar.Range = [1,5];
  • Type between 'integer' and 'real'. For example,

    xvar.Type = 'integer';
  • Transform of real or integer variables between 'log' and 'none'. For example,

    xvar.Transform = 'log';

You can use this flexibility, for example, to tweak an optimization that you want to continue. Update the range or transform using dot notation and then call resume.

Funciones del objeto

bayesoptSelect optimal machine learning hyperparameters using Bayesian optimization

Ejemplos

contraer todo

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 1 to 1000 on a log scale:

var2 = optimizableVariable('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

Introducido en R2016b