How to stop the display of objective function model calculation and the graphs when using GP

6 views (last 30 days)
I am computing a GP at every iteration using a for-loop. The objective function graphs and calculations in the command wind is taking a lot of space. I have about 201 figures. How can I stop the display of objective function calculation in the command window and the graphs.
N = 100;
x1 = linspace(0, 10, N);
x2 = linspace(0, 5, N);
X = [x1; x2];
X = X';
Y = sin(X(:, 1).^2 + X(:, 2).^2);
gpr = fitrgp(X,Y,'KernelFunction','squaredexponential',...
'OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',...
struct('AcquisitionFunctionName','expected-improvement-plus'));
|=====================================================================================================| | Iter | Eval | Objective: | Objective | BestSoFar | BestSoFar | Sigma | Standardize | | | result | log(1+loss) | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 1 | Best | 0.34951 | 1.3498 | 0.34951 | 0.34951 | 0.00019035 | true | | 2 | Accept | 0.39379 | 0.23818 | 0.34951 | 0.35264 | 1.4136 | false | | 3 | Best | 0.34824 | 0.26209 | 0.34824 | 0.34829 | 0.00055134 | false | | 4 | Accept | 0.39379 | 0.1279 | 0.34824 | 0.34826 | 1.0587 | true | | 5 | Accept | 0.34824 | 0.41387 | 0.34824 | 0.34824 | 0.00024395 | false | | 6 | Accept | 0.34951 | 0.15481 | 0.34824 | 0.34824 | 0.001418 | true | | 7 | Accept | 0.34951 | 0.14522 | 0.34824 | 0.34824 | 0.00053162 | true | | 8 | Accept | 0.34824 | 0.14395 | 0.34824 | 0.3482 | 0.00010015 | false | | 9 | Accept | 0.34824 | 0.12495 | 0.34824 | 0.34821 | 0.0027851 | false | | 10 | Accept | 0.34824 | 0.13997 | 0.34824 | 0.34818 | 0.001432 | false | | 11 | Accept | 0.34824 | 0.11798 | 0.34824 | 0.3482 | 0.0016966 | false | | 12 | Accept | 0.34824 | 0.15227 | 0.34824 | 0.3482 | 0.00016355 | false | | 13 | Accept | 0.34824 | 0.12321 | 0.34824 | 0.3482 | 0.00010024 | false | | 14 | Accept | 0.34824 | 0.15397 | 0.34824 | 0.34821 | 0.0018175 | false | | 15 | Accept | 0.34824 | 0.11096 | 0.34824 | 0.34821 | 0.00034393 | false | | 16 | Accept | 0.34824 | 0.11801 | 0.34824 | 0.34822 | 0.00091657 | false | | 17 | Accept | 0.34824 | 0.12112 | 0.34824 | 0.34822 | 0.00016423 | false | | 18 | Accept | 0.34824 | 0.10819 | 0.34824 | 0.34822 | 0.001893 | false | | 19 | Accept | 0.34824 | 0.14795 | 0.34824 | 0.34822 | 0.0001 | false | | 20 | Accept | 0.39379 | 0.085699 | 0.34824 | 0.34822 | 6.8859 | true | |=====================================================================================================| | Iter | Eval | Objective: | Objective | BestSoFar | BestSoFar | Sigma | Standardize | | | result | log(1+loss) | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 21 | Accept | 0.34824 | 0.171 | 0.34824 | 0.34824 | 0.0056218 | false | | 22 | Accept | 0.34824 | 0.10411 | 0.34824 | 0.34825 | 0.0037831 | false | | 23 | Accept | 0.34824 | 0.10866 | 0.34824 | 0.34821 | 0.0037717 | false | | 24 | Accept | 0.34951 | 0.17323 | 0.34824 | 0.34821 | 0.00010003 | true | | 25 | Accept | 0.34824 | 0.20197 | 0.34824 | 0.34822 | 0.0037079 | false | | 26 | Accept | 0.34824 | 0.11987 | 0.34824 | 0.34822 | 0.00064846 | false | | 27 | Accept | 0.39379 | 0.13155 | 0.34824 | 0.34821 | 6.8888 | false | | 28 | Best | 0.3436 | 0.1614 | 0.3436 | 0.34361 | 0.036807 | true | | 29 | Best | 0.3353 | 0.18172 | 0.3353 | 0.33532 | 0.014568 | true | | 30 | Accept | 0.33807 | 0.10861 | 0.3353 | 0.33541 | 0.011318 | true | __________________________________________________________ Optimization completed. MaxObjectiveEvaluations of 30 reached. Total function evaluations: 30 Total elapsed time: 21.1394 seconds Total objective function evaluation time: 5.8023 Best observed feasible point: Sigma Standardize ________ ___________ 0.014568 true Observed objective function value = 0.3353 Estimated objective function value = 0.33541 Function evaluation time = 0.18172 Best estimated feasible point (according to models): Sigma Standardize ________ ___________ 0.014568 true Estimated objective function value = 0.33541 Estimated function evaluation time = 0.15636
  1 Comment
Telema Harry
Telema Harry on 23 Nov 2023
@MathWorks Support Team please any solution to my question? My code takes a long time to run and displaying all the results means that I can't use my system effectively when the code is running. I.e. My current window closes when every new iteration.

Sign in to comment.

Accepted Answer

Ayush Aniket
Ayush Aniket on 27 Nov 2023
Hi Telema,
As per my understanding you would like to stop the display of objective function model calculation and the graphs. You can use the ShowPlots’ and ‘Verbose’ options available in the HyperparameterOptimizationOptions’ name-value argument of the function “fitgrp”. These options give you the ability to suppress the display of plots and iterative calculation information. You can modify your code as follows:
% Set the options for hyperparameter optimization to suppress display and plots
opts = struct('AcquisitionFunctionName', 'expected-improvement-plus', ...
'ShowPlots', false, ... % This stops the display of plots
'Verbose', 0); % This stops the display in the command window
gpr = fitrgp(X, Y, 'KernelFunction', 'squaredexponential', ...
'OptimizeHyperparameters', 'auto', ...
'HyperparameterOptimizationOptions', opts);
To read more about the options and their functionality please refer to the following documentation page:
Hope it helps!

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!