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.

BayesianOptimization

Bayesian optimization results

Descripción

A BayesianOptimization object contains the results of a Bayesian optimization. It is the output of bayesopt or a fit function that accepts the OptimizeHyperparameters name-value pair such as fitcdiscr. In addition, a BayesianOptimization object contains data for each iteration of bayesopt that can be accessed by a plot function or an output function.

Creación

Create a BayesianOptimization object using the bayesopt function or a fit function with the OptimizeHyperparameters name-value pair.

Propiedades

expandir todo

Problem Definition Properties

Esta propiedad es de solo lectura.

ObjectiveFcn argument used by bayesopt, returned as a function handle.

  • If you call bayesopt directly, ObjectiveFcn is the bayesopt objective function argument.

  • If you call a fit function containing the 'OptimizeHyperparameters' name-value pair argument, ObjectiveFcn is a function handle that returns the misclassification rate for classification or returns the logarithm of one plus the cross-validation loss for regression, measured by five-fold cross-validation.

Tipos de datos: function_handle

Esta propiedad es de solo lectura.

VariableDescriptions argument that bayesopt used, returned as a vector of optimizableVariable objects.

  • If you called bayesopt directly, VariableDescriptions is the bayesopt variable description argument.

  • If you called a fit function with the OptimizeHyperparameters name-value pair, VariableDescriptions is the vector of hyperparameters.

Esta propiedad es de solo lectura.

Options that bayesopt used, returned as a structure.

  • If you called bayesopt directly, Options is the options used in bayesopt, which are the name-value pairs See bayesopt Input Arguments.

  • If you called a fit function with the OptimizeHyperparameters name-value pair, Options are the default bayesopt options, modified by the HyperparameterOptimizationOptions name-value pair.

Options is a read-only structure containing the following fields.

Option NameMeaning
AcquisitionFunctionNameAcquisition function name. See Acquisition Function Types.
IsObjectiveDeterministictrue means the objective function is deterministic, false otherwise.
ExplorationRatioUsed only when AcquisitionFunctionName is 'expected-improvement-plus' or 'expected-improvement-per-second-plus'. See Plus.
  
MaxObjectiveEvaluationsObjective function evaluation limit.
MaxTimeTime limit.
  
XConstraintFcnDeterministic constraints on variables. See Deterministic Constraints — XConstraintFcn.
ConditionalVariableFcnConditional variable constraints. See Conditional Constraints — ConditionalVariableFcn.
NumCoupledConstraintsNumber of coupled constraints. See Coupled Constraints.
CoupledConstraintTolerancesCoupled constraint tolerances. See Coupled Constraints.
AreCoupledConstraintsDeterministicLogical vector specifying whether each coupled constraint is deterministic.
  
VerboseCommand-line display level.
OutputFcnFunction called after each iteration. See Bayesian Optimization Output Functions.
SaveVariableNameVariable name for the @assignInBase output function.
SaveFileNameFile name for the @saveToFile output function.
PlotFcnPlot function called after each iteration. See Bayesian Optimization Plot Functions
  
InitialXPoints where bayesopt evaluated the objective function.
InitialObjectiveObjective function values at InitialX.
InitialConstraintViolationsCoupled constraint function values at InitialX.
InitialErrorValuesError values at InitialX.
InitialObjectiveEvaluationTimesObjective function evaluation times at InitialX.
InitialIterationTimesTime for each iteration, including objective function evaluation and other computations.

Tipos de datos: struct

Solution Properties

Esta propiedad es de solo lectura.

Minimum observed value of objective function, returned as a real scalar. When there are coupled constraints or evaluation errors, this value is the minimum over all observed points that are feasible according to the final constraint and Error models.

Tipos de datos: double

Esta propiedad es de solo lectura.

Observed point with minimum objective function value, returned as a 1-by-D table, where D is the number of variables.

Tipos de datos: table

Esta propiedad es de solo lectura.

Minimum estimated value of objective function, returned as a real scalar. MinEstimatedObjective uses the final objective model.

MinEstimatedObjective is the same as the CriterionValue result of bestPoint with default criterion.

Tipos de datos: double

Esta propiedad es de solo lectura.

Point with minimum estimated objective function value, returned as a 1-by-D table, where D is the number of variables. XAtMinEstimatedObjective uses the final objective model.

Tipos de datos: table

Esta propiedad es de solo lectura.

Number of objective function evaluations, returned as a positive integer. This includes the initial evaluations to form a posterior model as well as evaluation during the optimization iterations.

Tipos de datos: double

Esta propiedad es de solo lectura.

Total elapsed time of optimization in seconds, returned as a positive scalar.

Tipos de datos: double

Esta propiedad es de solo lectura.

Next point to evaluate if optimization continues, returned as a 1-by-D table, where D is the number of variables.

Tipos de datos: table

Trace Properties

Esta propiedad es de solo lectura.

Points where the objective function was evaluated, returned as a T-by-D table, where T is the number of evaluation points and D is the number of variables.

Tipos de datos: table

Esta propiedad es de solo lectura.

Objective function values, returned as a column vector of length T, where T is the number of evaluation points. ObjectiveTrace contains the history of objective function evaluations.

Tipos de datos: double

Esta propiedad es de solo lectura.

Objective function evaluation times, returned as a column vector of length T, where T is the number of evaluation points. ObjectiveEvaluationTimeTrace includes the time in evaluating coupled constraints, because the objective function computes these constraints.

Tipos de datos: double

Esta propiedad es de solo lectura.

Iteration times, returned as a column vector of length T, where T is the number of evaluation points. IterationTimeTrace includes both objective function evaluation time and other overhead.

Tipos de datos: double

Esta propiedad es de solo lectura.

Coupled constraint values, returned as a T-by-K array, where T is the number of evaluation points and K is the number of coupled constraints.

Tipos de datos: double

Esta propiedad es de solo lectura.

Error indications, returned as a column vector of length T of -1 or 1 entries, where T is the number of evaluation points. Each 1 entry indicates that the objective function errored or returned NaN on the corresponding point in XTrace. Each -1 entry indicates that the objective function value was computed.

Tipos de datos: double

Esta propiedad es de solo lectura.

Feasibility indications, returned as a logical column vector of length T, where T is the number of evaluation points. Each 1 entry indicates that the final constraint model predicts feasibility at the corresponding point in XTrace.

Tipos de datos: logical

Esta propiedad es de solo lectura.

Probability that evaluation point is feasible, returned as a column vector of length T, where T is the number of evaluation points. The probabilities come from the final constraint model, including the error constraint model, on the corresponding points in XTrace.

Tipos de datos: double

Esta propiedad es de solo lectura.

Which evaluation gave minimum feasible objective, returned as a column vector of integer indices of length T, where T is the number of evaluation points. Feasibility is determined with respect to the constraint models that existed at each iteration, including the error constraint model.

Tipos de datos: double

Esta propiedad es de solo lectura.

Minimum observed objective, returned as a column vector of integer indices of length T, where T is the number of evaluation points.

Tipos de datos: double

Esta propiedad es de solo lectura.

Minimum estimated objective, returned as a column vector of integer indices of length T, where T is the number of evaluation points. The estimated objective at each iteration is determined with respect to the objective model that existed at that iteration.

Tipos de datos: double

Esta propiedad es de solo lectura.

Auxiliary data from the objective function, returned as a cell array of length T, where T is the number of evaluation points. Each entry in the cell array is the UserData returned in the third output of the objective function.

Tipos de datos: cell

Funciones del objeto

bestPointBest point in a Bayesian optimization according to a criterion
plotPlot Bayesian optimization results
predictConstraintsPredict coupled constraint violations at a set of points
predictErrorPredict error value at a set of points
predictObjectivePredict objective function at a set of points
predictObjectiveEvaluationTimePredict objective function run times at a set of points
resumeResume a Bayesian optimization

Ejemplos

contraer todo

This example shows how to create a BayesianOptimization object by using bayesopt to minimize cross-validation loss.

Optimize hyperparameters of a KNN classifier for the ionosphere data, that is, find KNN hyperparameters that minimize the cross-validation loss. Have bayesopt minimize over the following hyperparameters:

  • Nearest-neighborhood sizes from 1 to 30

  • Distance functions 'chebychev', 'euclidean', and 'minkowski'.

For reproducibility, set the random seed, set the partition, and set the AcquisitionFunctionName option to 'expected-improvement-plus'. Set options give no iterative display.

load ionosphere
rng default
num = optimizableVariable('n',[1,30],'Type','integer');
dst = optimizableVariable('dst',{'chebychev','euclidean','minkowski'},'Type','categorical');
c = cvpartition(351,'Kfold',5);
fun = @(x)kfoldLoss(fitcknn(X,Y,'CVPartition',c,'NumNeighbors',x.n,...
    'Distance',char(x.dst),'NSMethod','exhaustive'));
results = bayesopt(fun,[num,dst],'Verbose',0,...
    'AcquisitionFunctionName','expected-improvement-plus')

results = 
  BayesianOptimization with properties:

                      ObjectiveFcn: [function_handle]
              VariableDescriptions: [1x2 optimizableVariable]
                           Options: [1x1 struct]
                      MinObjective: 0.1197
                   XAtMinObjective: [1x2 table]
             MinEstimatedObjective: 0.1213
          XAtMinEstimatedObjective: [1x2 table]
           NumObjectiveEvaluations: 30
                  TotalElapsedTime: 61.7076
                         NextPoint: [1x2 table]
                            XTrace: [30x2 table]
                    ObjectiveTrace: [30x1 double]
                  ConstraintsTrace: []
                     UserDataTrace: {30x1 cell}
      ObjectiveEvaluationTimeTrace: [30x1 double]
                IterationTimeTrace: [30x1 double]
                        ErrorTrace: [30x1 double]
                  FeasibilityTrace: [30x1 logical]
       FeasibilityProbabilityTrace: [30x1 double]
               IndexOfMinimumTrace: [30x1 double]
             ObjectiveMinimumTrace: [30x1 double]
    EstimatedObjectiveMinimumTrace: [30x1 double]

This example shows how to minimize the cross-validation loss in the ionosphere data using Bayesian optimization of an SVM classifier.

Load the data.

load ionosphere

Optimize the classification using the 'auto' parameters.

rng default % For reproducibility
Mdl = fitcsvm(X,Y,'OptimizeHyperparameters','auto')

|=====================================================================================================|
| Iter | Eval   | Objective   | Objective   | BestSoFar   | BestSoFar   | BoxConstraint|  KernelScale |
|      | result |             | runtime     | (observed)  | (estim.)    |              |              |
|=====================================================================================================|
|    1 | Best   |     0.21937 |      56.177 |     0.21937 |     0.21937 |       64.836 |    0.0015729 |
|    2 | Accept |     0.35897 |      1.2543 |     0.21937 |     0.22807 |     0.036335 |       5.5755 |
|    3 | Best   |     0.13105 |      16.393 |     0.13105 |     0.14149 |    0.0022147 |    0.0023957 |
|    4 | Accept |     0.35897 |     0.28086 |     0.13105 |     0.13108 |       5.1259 |        98.62 |
|    5 | Best   |     0.12536 |     0.54788 |     0.12536 |     0.12538 |    0.0010127 |     0.015575 |
|    6 | Accept |     0.13675 |      5.1099 |     0.12536 |     0.12914 |    0.0010151 |    0.0059137 |
|    7 | Accept |     0.13105 |      2.4215 |     0.12536 |     0.12853 |     0.014767 |    0.0096217 |
|    8 | Best   |     0.12251 |     0.22413 |     0.12251 |     0.12253 |    0.0010036 |     0.041712 |
|    9 | Accept |     0.12821 |     0.32705 |     0.12251 |     0.12255 |    0.0082502 |     0.035908 |
|   10 | Accept |     0.12251 |     0.38873 |     0.12251 |      0.1221 |    0.0011855 |     0.029178 |
|   11 | Accept |     0.22792 |      45.983 |     0.12251 |     0.12215 |        909.3 |     0.099475 |
|   12 | Accept |     0.12821 |       1.261 |     0.12251 |     0.12404 |     0.001031 |      0.03003 |
|   13 | Accept |     0.12251 |     0.27708 |     0.12251 |     0.12314 |    0.0010544 |     0.057552 |
|   14 | Accept |     0.12251 |     0.90473 |     0.12251 |     0.12292 |    0.0010188 |     0.054959 |
|   15 | Accept |     0.12251 |     0.46279 |     0.12251 |     0.12282 |    0.0010336 |     0.053712 |
|   16 | Accept |      0.1339 |     0.82524 |     0.12251 |     0.12294 |    0.0010118 |     0.071732 |
|   17 | Accept |      0.1339 |     0.61222 |     0.12251 |     0.12475 |    0.0010223 |     0.032979 |
|   18 | Accept |     0.12251 |     0.51923 |     0.12251 |     0.12454 |    0.0026782 |     0.037915 |
|   19 | Accept |     0.12536 |     0.46683 |     0.12251 |     0.12455 |    0.0031425 |     0.038491 |
|   20 | Accept |     0.35897 |     0.39767 |     0.12251 |     0.12457 |      0.13155 |       487.94 |
|=====================================================================================================|
| Iter | Eval   | Objective   | Objective   | BestSoFar   | BestSoFar   | BoxConstraint|  KernelScale |
|      | result |             | runtime     | (observed)  | (estim.)    |              |              |
|=====================================================================================================|
|   21 | Accept |     0.35897 |     0.38133 |     0.12251 |     0.12451 |       313.57 |       685.39 |
|   22 | Accept |     0.35897 |     0.31988 |     0.12251 |     0.12448 |    0.0010005 |       82.864 |
|   23 | Accept |     0.12251 |     0.44341 |     0.12251 |     0.12476 |       994.15 |       41.407 |
|   24 | Accept |     0.12821 |     0.44109 |     0.12251 |     0.12473 |       998.66 |       14.421 |
|   25 | Best   |     0.11681 |     0.35751 |     0.11681 |     0.11763 |       987.41 |       25.189 |
|   26 | Accept |     0.12536 |     0.21579 |     0.11681 |     0.12039 |        993.4 |       28.179 |
|   27 | Accept |     0.11681 |     0.22229 |     0.11681 |     0.11928 |       998.76 |       26.162 |
|   28 | Accept |     0.11681 |     0.41518 |     0.11681 |     0.11867 |       984.22 |       25.965 |
|   29 | Accept |     0.35897 |      1.2149 |     0.11681 |     0.11871 |     0.001013 |       773.11 |
|   30 | Accept |     0.35897 |     0.69988 |     0.11681 |     0.11875 |     0.083636 |       64.996 |

__________________________________________________________
Optimization completed.
MaxObjectiveEvaluations of 30 reached.
Total function evaluations: 30
Total elapsed time: 243.9618 seconds.
Total objective function evaluation time: 139.5449

Best observed feasible point:
    BoxConstraint    KernelScale
    _____________    ___________

       987.41          25.189   

Observed objective function value = 0.11681
Estimated objective function value = 0.11875
Function evaluation time = 0.35751

Best estimated feasible point (according to models):
    BoxConstraint    KernelScale
    _____________    ___________

       998.76          26.162   

Estimated objective function value = 0.11875
Estimated function evaluation time = 0.33141
Mdl = 
  ClassificationSVM
                         ResponseName: 'Y'
                CategoricalPredictors: []
                           ClassNames: {'b'  'g'}
                       ScoreTransform: 'none'
                      NumObservations: 351
    HyperparameterOptimizationResults: [1x1 BayesianOptimization]
                                Alpha: [100x1 double]
                                 Bias: -4.5428
                     KernelParameters: [1x1 struct]
                       BoxConstraints: [351x1 double]
                      ConvergenceInfo: [1x1 struct]
                      IsSupportVector: [351x1 logical]
                               Solver: 'SMO'


  Properties, Methods

The fit achieved about 12% loss for the default 5-fold cross validation.

Examine the BayesianOptimization object that is returned in the HyperparameterOptimizationResults property of the returned model.

disp(Mdl.HyperparameterOptimizationResults)
  BayesianOptimization with properties:

                      ObjectiveFcn: @createObjFcn/inMemoryObjFcn
              VariableDescriptions: [5x1 optimizableVariable]
                           Options: [1x1 struct]
                      MinObjective: 0.1168
                   XAtMinObjective: [1x2 table]
             MinEstimatedObjective: 0.1187
          XAtMinEstimatedObjective: [1x2 table]
           NumObjectiveEvaluations: 30
                  TotalElapsedTime: 243.9618
                         NextPoint: [1x2 table]
                            XTrace: [30x2 table]
                    ObjectiveTrace: [30x1 double]
                  ConstraintsTrace: []
                     UserDataTrace: {30x1 cell}
      ObjectiveEvaluationTimeTrace: [30x1 double]
                IterationTimeTrace: [30x1 double]
                        ErrorTrace: [30x1 double]
                  FeasibilityTrace: [30x1 logical]
       FeasibilityProbabilityTrace: [30x1 double]
               IndexOfMinimumTrace: [30x1 double]
             ObjectiveMinimumTrace: [30x1 double]
    EstimatedObjectiveMinimumTrace: [30x1 double]

Introducido en R2016b