Optimization of Stochastic Objective Function
Open in MATLAB OnlineCopy Code Copy Command
This example shows how to find a minimum of a stochastic objective function
using patternsearch. It also shows how Optimization Toolbox™ solvers are not suitable for this
type of problem. The example uses a simple 2-dimensional objective function that is then
perturbed by noise.
Initialization
Get
X0 = [2.5 -2.5]; % Starting point.
LB = [-5 -5]; % Lower bound
UB = [5 5]; % Upper bound
range = [LB(1) UB(1); LB(2) UB(2)];
Objfcn = @smoothFcn; % Handle to the objective function.
% Plot the smooth objective function
fig = figure('Color','w');
showSmoothFcn(Objfcn,range);
hold on;
title('Smooth objective function');
ph = [];
ph(1) = plot3(X0(1),X0(2),Objfcn(X0)+30,'or','MarkerSize',10,'MarkerFaceColor','r');
hold off;
ax = gca;
ax.CameraPosition = [-31.0391 -85.2792 -281.4265];
ax.CameraTarget = [0 0 -50];
ax.CameraViewAngle = 6.7937;
% Add legend information
legendLabels = {'Start point'};
lh = legend(ph,legendLabels,'Location','SouthEast');
lp = lh.Position;
lh.Position = [1-lp(3)-0.005 0.005 lp(3) lp(4)];