<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" [ <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Pattern Search</title>
<meta http-equiv="Content-Type" content="text/xml; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" type="text/css" href="../../comsci/css/s011.css" />
<link rel='SHORTCUT ICON' href='../../comsci/images/FrameHome.ico' />
</head>

<body>

<div class="message_right">
  <a href="http://validator.w3.org/check/referer">
    <img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid
	XHTML 1.1!" height="31" width="88" />
  </a>
  <a href="http://jigsaw.w3.org/css-validator/">
    <img style="width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" />
  </a>
  <br />
  Created 2006-06-11 Modified 
<!--UPDATE_DATE_BEGIN-->
2009-04-11<br />
<a class="reflocal" href="../../../doc02.html">Chelton Evans</a>

<!--UPDATE_DATE_END-->
</div>

<h1> 
<a href="../calculus/calculus.xml">
<img src="../../comsci/images/atom.gif" alt="calculus" /></a>
Pattern Search
<a href="../../../index.html">
<img alt="home" src="../../comsci/images/Frame.gif" /> </a>
</h1>


<p>
<a class="reflocal2" href="#Intro">Intro</a><br />
<a class="reflocal2" href="#Exploratory_Move">Exploratory Move</a><br />
<a class="reflocal2" href="#Discussion">
 Discussion</a><br />

<a class="reflocal2" href="#Generalized_Pattern_Move">
  Generalized Pattern Move</a><br />
<a class="reflocal2" href="#Experiments">Experiments</a><br />
<a class="reflocal2" href="#Algorithm">
  Algorithm</a><br />
<a class="reflocal" href="../../misc/proj/patternsearch/doc.html">
C++ Implementation</a> <br />


<a class="reflocal2" href="#References">
References</a>

</p>

<div class="float25">

<a id="Intro"></a>
<h2>Intro</h2>

<p>The Pattern search algorith is an 
 <a class="reflocal" href="calc021.xml">Optimization</a> algorithm.</p>


<p class="alg1">

<math xmlns="&mathml;">
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
</math>
 exploratory move 
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>+</mo>
  <mo>(</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>)</mo>
  <mo>)</mo>
</math>

<br />

if &nbsp; 
<math xmlns="&mathml;">
  <mi>f</mi>
  <mo>(</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>)</mo>
  <mo>&lt;</mo>
  <mi>f</mi>
  <mo>(</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>)</mo>
</math>

<br />
  &nbsp; &nbsp; accept 
<math xmlns="&mathml;">
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
</math>

<br />
else <br />
 &nbsp; &nbsp; 
<math xmlns="&mathml;">
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
</math>
 exploratory move 

<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>)</mo>
</math>

</p>

</div>
<div class="float25">

<p>
It is said to be a derivative free
 algorithm because it optimizes with f(X).
 Though from my analysis it is not 
 derivative free but numerically approximates
 them through the algorithms structure.
</p>

<p>
There have been variations and
 improvements on
 the pattern search algorithm, so
 the pattern search algorithm description
 in one reference can be differ from
 another. For example variable h<sub>i</sub>,
 exploratory move after pattern move,
 removal of order bias in the original 
 algorithm. The pattern search algorithm
 was explosive. 
</p>

<hr />

</div>
<div class="float25">

<a id="Exploratory_Move"></a>
<h2>Exploratory Move</h2>

<p> See 
<a class="reflocal" href="calc051.xml#exploratory">
exploratory
</a>
 defined.
</p>


<p>
For the pattern search algorithm
 the exploratory move is defined
 with the magnitude_inc defined
 to do nothing - and so the algorithm
 may get stuck but is cheaper to run. 
 If the algorithms stability is important
 then define the magnitude_inc function.
</p>

<hr />

</div>
<div class="float25">

<a id="Generalized_Pattern_Move"></a>
<h2>Generalized Pattern Move</h2>

<p>
Sequential X<sub>k</sub> are derivatives
 where the change in the numerator is a
 vector and the denominator an integer 1.
</p>

<p>
 This is supported as each independent dimension
 with the exploratory move has a difference
 and an integer denominator change.
</p>

<p>
To support this view lets expand
 the Taylor series and derive
 the first order approximator.
</p>

</div>
<div class="float25">

<p>
Taylors series about a point with the difference
 operator &Delta;.
</p>

<p class="equ">

<math xmlns="&mathml;">
  <mi>&Delta;</mi>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
</math>
<br />

<math xmlns="&mathml;">
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>


</math>

<br />

<math xmlns="&mathml;">
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>+</mo>

  <mi>h</mi>
  <mo>&Delta;</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>

  <mo>+</mo>

  <mfrac>
    <mrow><mi>1</mi></mrow>
    <mrow><mi>2</mi></mrow>
  </mfrac>
  <mi>h</mi>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>
  <mo>&Delta;</mo>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>

  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>+</mo>
  <mi>...</mi>
</math>

</p>

<p>
Truncate to first order.
</p>

<p class="equ">
Let <br />
<math xmlns="&mathml;">
  <mi>h</mi>
  <mo>=</mo>
  <mi>1</mi>
</math>
<br />
<math xmlns="&mathml;">
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>+</mo>
  <mo>(</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>)</mo>
</math>

</p>

<p>
Which is the first order approximator.
</p>

</div>
<div class="float25">

<p>
This
 strategy generalized to any order approximator.
Deriving the second order approximator.
</p>

<p class="equ">

<math xmlns="&mathml;">
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
</math>

<math xmlns="&mathml;">
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>+</mo>

  <mo>&Delta;</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>

  <mo>+</mo>

  <mfrac>
    <mrow><mi>1</mi></mrow>
    <mrow><mi>2</mi></mrow>
  </mfrac>

  <mo>&Delta;</mo>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>

  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
</math>

</p>

<p>
First difference
</p>


<p class="equ">

<math xmlns="&mathml;">
  <mo>&Delta;</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>

</math>

</p>

<p>
Second difference
</p>


<p class="equ">

<math xmlns="&mathml;">
  <mo>&Delta;</mo>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>

  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
  <mo>&Delta;</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mo>&Delta;</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>

</math>

<br />

<math xmlns="&mathml;">
  <mo>=</mo>
  <mo>(</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>)</mo>
  <mo>-</mo>
  <mo>(</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>2</mi></mrow>
  </msub>
  <mo>)</mo>

</math>

<br />

<math xmlns="&mathml;">
  <mo>=</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>2</mi>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>+</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>2</mi></mrow>
  </msub>
</math>
</p>

<p>
Putting it together.
</p>

<p class="equ">

<math xmlns="&mathml;">
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>+</mo>
  <mo>(</mo>

  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>

  <mo>)</mo>
  <mo>+</mo>
  <mfrac>
    <mrow><mi>1</mi></mrow>
    <mrow><mi>2</mi></mrow>
  </mfrac>
  <mo>(</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>2</mi>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>+</mo>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>2</mi></mrow>
  </msub>
  <mo>)</mo>

</math>

</p>

<p class="equ">

<math xmlns="&mathml;">
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
</math>
<br />

<math xmlns="&mathml;">
  <mfrac>
    <mrow><mi>5</mi></mrow>
    <mrow><mi>2</mi></mrow>
  </mfrac>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>2</mi>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>+</mo>
  <mfrac>
    <mrow><mi>1</mi></mrow>
    <mrow><mi>2</mi></mrow>
  </mfrac>
  <mi>Y</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>2</mi></mrow>
  </msub>
</math>

</p>

<hr />

</div>
<div class="float25">

<h2>Generalized Pattern Search Step</h2>

<p>You will notice that the pattern search
 can overshoot. Indeed without the exploratory
 search the pattern move made no gain in the
 problem I had. If we see the pattern move
 as a taylor series then it is clearer.
</p>

 
<p class="equ">

<math xmlns="&mathml;">
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>+</mo><mi>1</mi></mrow>
  </msub>
  <mo>=</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>+</mo>
  <mi>hStep</mi>
  <mo>*</mo>
  <mo>(</mo>

  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>n</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>

  <mo>)</mo>
</math>

</p>

<p>Here is some data for the test problem.
 The exact solution is (1,2,5).
</p>

<pre>
1.00073 2 4.99689
g.fn.counter=211
hstep=1

0.999943 2 5.00013
g.fn.counter=221
hstep=0.75

0.999946 2 4.99997
g.fn.counter=215
hstep=0.68

1.00001 2 4.99991
g.fn.counter=217
hstep=0.55

0.999548 2 5.00121
g.fn.counter=225
hstep=0.4

0.995003 2 5.00475
g.fn.counter=201
hstep=0.2
</pre>


<p>When the steplength was near the golden ratio number
 the calculation was best.
</p>

<hr />

</div>
<div class="float25">

<a id="Experiments"></a>
<h2>Experiments</h2>
<p>The higher order approximations of the pattern move
 did not do much so the idea of the generalized pattern
 move seems to have failed. Generally it did worse
 than the exploratory search without the pattern move.
</p>

<p>Perhaps this was surprising but the default exploratory
 move performed the best on my parabola test problem.
</p>

<p>To give you an idea of how good the supositly worst
 case move of the pattern seach is here is comparing
 it with a higher order approximator.
</p>

<p>To compare the algorithms a counter on the number of
 function evaluations is used.
</p>

<pre>
13th order pattern move aproximator
./main prog=9 dim=13 counter=400

g.fn.counter=405
hstep=1
pat.exp.fmin=8.29927e-13

explore h approximator
g.fn.counter=403
g.fmin=2.94134e-18

Pattern Search
g.fn.counter=400
pat.exp.fmin=1.86047e-10
</pre>

<p>As you can see the simplest algorith beats
 the others hands down.  As the counter increased this
 difference became large.  I had not expected this
 result, I would have guessed that the exploratory
 algoritmm would perform the worst, but it performed
 the best and is the simplest.
</p>

<hr />

</div>
<div class="float25">

<a id="Algorithm"></a>
<h2>Algorithm</h2>

<p>
Initialize algorithm
</p>

<p class="equ">
Generate two successive approximations
 X<sub>0</sub> and X<sub>1</sub> with the 
 exploratory algorithm. 
</p>

<p>
Use the exploratory algorithm that
 iterates over 0..N-1 dimensions,
 see 
<a class="reflocal" href="calc051.xml#First_Order_Approximator">
 First Order Approximator</a>.
</p>

<p class="equ">
loop<br />
{ <br />

 &nbsp; &nbsp;  
<a class="reflocal" href="calc051.xml#exploratory">
exploratory
</a>
(
<br />
<math xmlns="&mathml;">
  <mi>X</mi>
  <msup>
    <mi></mi>
    <mrow><mi>*</mi></mrow>
  </msup>
  <mo>=</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>k</mi></mrow>
  </msub>
  <mo>+</mo>
  <mo>(</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>k</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>k</mi><mo>-</mo><mi>1</mi></mrow>
  </msub>
  <mo>)</mo>
</math>
) 
<br />
<br />
 &nbsp; &nbsp;  
if (result==false)
<br />
 &nbsp; &nbsp;  
 &nbsp; &nbsp;  
<a class="reflocal" href="calc051.xml#exploratory">
exploratory
</a>
<math xmlns="&mathml;">
  <mo>(</mo>
  <mi>X</mi>
  <msup>
    <mi></mi>
    <mrow><mi>*</mi></mrow>
  </msup>
  <mo>=</mo>
  <mi>X</mi>
  <msub>
    <mi></mi>
    <mrow><mi>k</mi></mrow>
  </msub>
  <mo>&PlusMinus;</mo>
  <mi>h</mi>
  <msub>
    <mi></mi>
    <mrow><mi>i</mi></mrow>
  </msub>
  <mi>e</mi>
  <msub>
    <mi></mi>
    <mrow><mi>i</mi></mrow>
  </msub>
  <mo>)</mo>
</math>

<br />

}

</p>

</div>
<div class="float25">

<a id="Discussion"></a>
<h2>Discussion</h2>

<p>
The pattern search algorithm has global
 convergence as its default sub algorithm
 is the exploratory algorithm which has
 global convergence.
</p>

<p>Lets define local global convergence
 to be the rate of global convergence
 and that algorithms for practical purposes
 do not get stuck.
</p>

<p>
The original algorithm had fixed h<sub>i</sub>
 which where reduced only after all N 
 dimensions were searched with the exploratory
 algorithm failing.
</p>

<p>
How this effects local global 
 convergence 
 compared with varying
 the dimensions h<sub>i</sub> I do not know.
</p>

<p>
Similarly doing an exploratory search
 after the pattern search and its effect
 on the local global convergence I have no 
 idea.
</p>

</div>
<div class="float25">


<p>TODO - compare the pattern search
 with other algorithms on some problems.
</p>


<p>
The pattern search may also be used for
 non-continuous functions and derivatives.
 Or in some hybrid.
</p>

<p>
The algorithm can be used in 
 constrained optimization.
 eg resetting a value
 if it is outside the constraint domain.
 [1]
</p>

<p>
In the original algorithm
 after a successful search in a dimension
 rather than the N dimensions the pattern
 move was done. Then the dimension counter
 was reset.  This favoured minimizing
 the 0'th, 1st, 2nd, .. dimensions.
</p>

</div>
<div class="float25">

<a id="References"></a>
<h2>References</h2>

<ol>

<li>
W. Fabrycky and J. Mize (1973). 
 Introduction to Optimization Theory. 
 ISBN 0-13-491472-4. Page 117.
</li>

</ol>

</div>

</body>
</html>


