⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psoptionsdemo.html

📁 遗传算法工具包
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">   <head>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">         <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document.      -->      <title>Pattern Search options</title>      <meta name="generator" content="MATLAB 7.0.0.4032 (R14) Prerelease">      <meta name="date" content="2004-03-29">      <meta name="m-file" content="psoptionsdemo">      <meta name="title" content="Pattern Search options">      <meta name="description" content="This is a demonstration of how to create and manage options for pattern search using the PSOPTIMSET function in the Genetic Algorithm and Direct Search Toolbox."><style>body {  background-color: white;}h1 {  color: #990000;   font-size: x-large;}h2 {  color: #990000;  font-size: medium;}p.footer {  text-align: right;  font-size: xx-small;  font-weight: lighter;  font-style: italic;  color: gray;}pre.codeinput {  margin-left: 30px;}span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.showbuttons {  margin-left: 30px;  border: solid black 2px;  padding: 4px;  background: #EBEFF3;}pre.codeoutput {  color: gray;  font-style: italic;}pre.error {  color: red;}    </style></head>   <body>      <h1>Pattern Search options</h1>      <p>This is a demonstration of how to create and manage options for pattern search using the PSOPTIMSET function in the Genetic         Algorithm and Direct Search Toolbox.      </p>      <h2>Contents</h2>      <ul>         <li><a href="#1">Setting up a problem for pattern search</a></li>         <li><a href="#5">Adding visualization</a></li>         <li><a href="#7">Mesh parameters</a></li>         <li><a href="#16">Stopping criteria and tolerances</a></li>         <li><a href="#22">Using the Cache option</a></li>         <li><a href="#25">Search methods in pattern search</a></li>      </ul>      <h2>Setting up a problem for pattern search<a name="1"></a></h2>      <p>PATTERNSEARCH finds a linearly constrained minimum of a function. PATTERNSEARCH solves problems of the form:</p><pre>   min F(x)    subject to:     A*x &lt;= B    x                         Aeq*x = Beq                             LB &lt;= x &lt;= UB</pre><p>In this demo, the PATTERNSEARCH solver is used to optimize an objective function subject to some linear equality and inequality         constraints.      </p>      <p>The pattern search solver takes at least two input arguments, namely the objective function and a start point. We will use         the objective function LINCONTEST7 which is in the M-file 'lincontest7.m'. We pass a function handle to LINCONTEST7 as the         first argument. The second argument is a starting point. Since LINCONTEST7 is a function of six variables, our start point         must be of length six.      </p><pre class="codeinput">X0 = [2 1 0 9 1 0];objectiveFcn = @lincontest7;</pre><p>We also create the constraint matrices for the problem.</p><pre class="codeinput">Aineq = [-8 7 3 -4 9 0 ];Bineq = [7];Aeq = [7 1 8 3 3 3; 5 0 5 1 5 8; 2 6 7 1 1 8; 1 0 0 0 0 0];Beq = [84 62 65 1];</pre><p>Next we run the PATTERNSEARCH solver.</p><pre class="codeinput">[X1,Fval,Exitflag,Output] = patternsearch(objectiveFcn,X0,Aineq,Bineq,Aeq,Beq);fprintf(<span class="string">'The number of iterations was : %d\n'</span>, Output.iterations);fprintf(<span class="string">'The number of function evaluations was : %d\n'</span>, Output.funccount);fprintf(<span class="string">'The best function value found was : %g\n'</span>, Fval);</pre><pre class="codeoutput">Optimization terminated: current mesh size 9.5367e-007 is less than 'TolMesh'.The number of iterations was : 256The number of function evaluations was : 1852The best function value found was : 2189.03</pre><h2>Adding visualization<a name="5"></a></h2>      <p>If you are interested in visualizing the performance of the solver at run time you can use the provided plot functions or         create your own. PATTERNSEARCH can accept one or more plot functions. Plot functions can be selected using the function PSOPTIMSET.         The default is that no plot functions are called while PATTERNSEARCH is running. Here we create an options structure using         PSOPTIMSET that selects two plot functions. The first plot function PSPLOTBESTF plots the best objective function value at         every iterations, and the second plot function PSPLOTFUNCOUNT plots the number of times the objective function is evaluated         at each iteration.      </p><pre class="codeinput">opts = psoptimset(<span class="string">'PlotFcns'</span>,{@psplotbestf,@psplotfuncount});</pre><p>We run the PATTERNSEARCH solver.  Since we do not have upper or lower bound constraints, we pass empty arrays ([]) for the         seventh and eighth arguments.      </p><pre class="codeinput">[X1,Fval,ExitFlag,Output] = patternsearch(objectiveFcn,X0,Aineq,Bineq, <span class="keyword">...</span>    Aeq,Beq,[],[],opts);</pre><pre class="codeoutput">Optimization terminated: current mesh size 9.5367e-007 is less than 'TolMesh'.</pre><img vspace="5" hspace="5" src="psoptionsdemo_01.png"><h2>Mesh parameters<a name="7"></a></h2>      <p><b>Initial mesh size</b></p>      <p>The pattern search algorithm uses a set of rational basis vectors to generate search directions. It performs a search along         the search directions using the current mesh size. The solver starts with an initial mesh size of one by default. To start         the initial mesh size at 10, we can use PSOPTIMSET:      </p><pre class="codeinput">options = psoptimset(<span class="string">'InitialMeshSize'</span>,10);</pre><p><b>Mesh scaling</b></p>      <p>A mesh can be scaled to improve the minimization of a badly scaled optimization problem. Scale is used to rotate the pattern         by some degree and scale along the search directions. The scale option is 'on' by default but can be turned off if the problem         is well scaled. In general, if the problem is badly scaled, setting this option to 'on' may help in reducing the number of         function evaluations. For our objective function, we can set scale to 'off' because it is known to be a well scaled problem.      </p><pre class="codeinput">opts = psoptimset(<span class="string">'ScaleMesh'</span>,<span class="string">'off'</span>);</pre><p><b>Mesh accelerator</b></p>      <p>Direct search methods require many function evaluations as compared to derivative-based optimization methods. The pattern         search algorithm can quickly find the neighborhood of an optimum point, but may be slow in detecting the minimum itself. This         is the cost of not using derivatives. The PATTERNSEARCH solver can reduce the number of function evaluations using an accelerator.         When the accelerator is 'on' the mesh size is contracted rapidly after some minimum mesh size is reached. This option is recommended         only for smooth problems, otherwise you may lose some accuracy. The accelerator is 'off' by default. Here we set the accelerator         'on' because we know that our objective function is smooth.      </p>      <p>Set mesh accelerator to 'on' and set mesh scale to 'off'.</p><pre class="codeinput">opts = psoptimset(<span class="string">'MeshAccelerator'</span>,<span class="string">'on'</span>,<span class="string">'ScaleMesh'</span>,<span class="string">'off'</span>);</pre><p>Run the PATTERNSEARCH solver.</p><pre class="codeinput">[X2,Fval,ExitFlag,Output] = patternsearch(objectiveFcn,X0,Aineq,Bineq, <span class="keyword">...</span>    Aeq,Beq,[],[],opts);fprintf(<span class="string">'The number of iterations was : %d\n'</span>, Output.iterations);fprintf(<span class="string">'The number of function evaluations was : %d\n'</span>, Output.funccount);fprintf(<span class="string">'The best function value found was : %g\n'</span>, Fval);</pre><pre class="codeoutput">Optimization terminated: current mesh size 3.0518e-007 is less than 'TolMesh'.The number of iterations was : 222The number of function evaluations was : 1380The best function value found was : 2189.03</pre><p>Setting the accelerator to 'on' reduced the number of function evaluations.</p>      <h2>Stopping criteria and tolerances<a name="16"></a></h2>      <p><b>What is TolMesh, TolX and TolFun</b></p>      <p>'TolMesh' is a tolerance on the mesh size. If the mesh size is less than 'TolMesh', the solver will stop. 'TolX' is used as         the minimum tolerance on the change in the current point to the next point. 'TolFun' is used as the minimum tolerance on the         change in the function value from the current point to the next point.      </p>      <p>We can create an options structure that sets 'TolX' to 1e-7 using PSOPTIMSET. We can update our previously created options         structure 'opts' by passing 'opts' to PSOPTIMSET.      </p><pre class="codeinput">opts = psoptimset(opts,<span class="string">'TolX'</span>,1e-7);</pre><p><b>What is TolBind</b></p>      <p>When the current point is near enough to a constraint, the search directions must include the constraint boundary, that is,         one of the search directions must be the constraint boundary. If the distance from the current point to a constraint is less         than 'TolBind', the constraint is said to be active with respect to the current point; the the active constraint's boundary,         or tangent, is included in the search directions. A larger tolerance value for 'TolBind' say equal to one, will possibly include         more constraint boundaries, which may slow down the solver. On the other hand, a tight tolerance could reduce the number of         search directions, and then speed up the solver.      </p>      <p>The recommended value of 'TolBind' is a value greater than or equal to the maximum of 'TolMesh', 'TolX', and 'TolFun'. The         default value of 'TolBind' is 1e-3. A tighter value, still greater than or equal to 'TolMesh', 'TolX', and 'TolFun', can be         used for our example. We can update our options structure 'opts' to set the 'TolBind' to be 1e-6.      </p><pre class="codeinput">opts = psoptimset(opts,<span class="string">'TolBind'</span>,1e-6);</pre><p>Run the PATTERNSEARCH solver.</p><pre class="codeinput">[X3,Fval,ExitFlag,Output] = patternsearch(objectiveFcn,X0,Aineq,Bineq, <span class="keyword">...</span>    Aeq,Beq,[],[],opts);fprintf(<span class="string">'The number of iterations was : %d\n'</span>, Output.iterations);fprintf(<span class="string">'The number of function evaluations was : %d\n'</span>, Output.funccount);fprintf(<span class="string">'The best function value found was : %g\n'</span>, Fval);</pre><pre class="codeoutput">Optimization terminated: current mesh size 7.6294e-008 is less than 'TolMesh'.The number of iterations was : 142The number of function evaluations was : 806The best function value found was : 2189.18</pre><p>Decreasing 'TolBind' reduced the number of function evaluations.</p>      <h2>Using the Cache option<a name="22"></a></h2>      <p>Because the pattern search algorithm uses a pattern it is likely that a point is included in the pattern on more than one         iteration. When the objective function is very expensive to evaluate, it can be more efficient to use the 'Cache' option,         which is 'off' by default. If a new point is found in the cache, its objective function value does not need to be computed.         This option should only be used with deterministic, not stochastic, objective functions.      </p>      <p>The 'CacheTol' option is used to compare the current point with all the points in the cache. A recommended strategy is to         use the default value for 'CacheTol' (which is eps). If the problem is smooth then we may increase 'CacheTol' to the order         of 1e-10. 'CacheSize' is used to specify how many points will be stored before clearing half the cache. We can update our         options structure to use the cache with a 'CacheTol' of 1e-10.      </p><pre class="codeinput">opts = psoptimset(opts,<span class="string">'Cache'</span>,<span class="string">'on'</span>,<span class="string">'CacheTol'</span>,1e-10);</pre><p>Run the PATTERNSEARCH solver.</p><pre class="codeinput">[X5,Fval,ExitFlag,Output] = patternsearch(objectiveFcn,X0,Aineq,Bineq,Aeq,Beq,[],[],opts);fprintf(<span class="string">'The number of iterations was : %d\n'</span>, Output.iterations);fprintf(<span class="string">'The number of function evaluations was : %d\n'</span>, Output.funccount);fprintf(<span class="string">'The best function value found was : %g\n'</span>, Fval);</pre><pre class="codeoutput">Optimization terminated: current mesh size 1.5259e-007 is less than 'TolMesh'.The number of iterations was : 73The number of function evaluations was : 480The best function value found was : 2189.18</pre><p>Setting the cache to 'on' reduced the number of function evaluations.</p>      <h2>Search methods in pattern search<a name="25"></a></h2>      <p>The pattern search algorithm can use an additional search at every iteration. This option is called the 'SearchMethod'. When         a 'SearchMethod' is provided, that search is done first before the mesh search. If the 'SearchMethod' is successful, the mesh         search, commonly called the 'PollMethod' is skipped. If the search method is unsuccessful in improving the current point,         the poll method is performed.      </p>      <p>The toolbox provides five different search methods. These search methods include SEARCHGA and SEARCHNELDERMEAD, which are         two different optimization algorithms. It is recommended to use these methods only for the first iteration, which is the default.         Using these methods repeatedly at every iteration might not improve the results and could be computationally expensive. One         the other hand, the SEARCHLHS, which generates latin hypercube points, can be used in every iteration or possibly every 10         iterations. Other choices for search methods include Poll methods such as positive basis N+1 or positive basis 2N.      </p>      <p>A recommended strategy is to use the positive basis N+1 (which requires at most N+1 points to create a pattern) as a search         method and positive basis 2N (which requires 2N points to create a pattern) as a poll method. We update our options structure         to use @positivebasisnp1 as the search method. Since the positive basis 2N is the default 'PollMethod', we do not need to         set that option. Additionally we can select the plot functions we used in first part of this demo to compare the performance         of the solver.      </p><pre class="codeinput">opts = psoptimset(opts,<span class="string">'SearchMethod'</span>,@positivebasisnp1, <span class="keyword">...</span>    <span class="string">'PlotFcns'</span>,{@psplotbestf, @psplotfuncount});</pre><p>Run the PATTERNSEARCH solver.</p><pre class="codeinput">[X5,Fval,ExitFlag,Output] = patternsearch(objectiveFcn,X0,Aineq,Bineq,Aeq,Beq,[],[],opts);fprintf(<span class="string">'The number of iterations was : %d\n'</span>, Output.iterations);fprintf(<span class="string">'The number of function evaluations was : %d\n'</span>, Output.funccount);fprintf(<span class="string">'The best function value found was : %g\n'</span>, Fval);</pre><pre class="codeoutput">Optimization terminated: current mesh size 1.9073e-008 is less than 'TolMesh'.The number of iterations was : 82The number of function evaluations was : 388The best function value found was : 2189.18</pre><img vspace="5" hspace="5" src="psoptionsdemo_02.png"><p>With the above settings of options, the total number of function evaluations decreased.</p>      <p class="footer">Copyright 2004 The MathWorks, Inc.<br></p>      <!--##### SOURCE BEGIN #####%% Pattern Search options% This is a demonstration of how to create and manage options for% pattern search using the PSOPTIMSET function in the Genetic Algorithm

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -