<?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>C++ Monte Carlo Code</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="../documentation/s011.css" />
<link rel='SHORTCUT ICON' href='../documentation/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 2003-01-01 &nbsp; Modified 
<!--UPDATE_DATE_BEGIN-->
2009-04-11<br />
<a class="reflocal" href="../../../../doc02.html">Chelton Evans</a>

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

<h1> 
<a href="../doc.html">
<img alt="proj" src="../../../comsci/images/code.png" /> </a>
minmonte
<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="#Issues"> Issues </a> <br />
<a class="reflocal2" href="#Source"> Source </a> <br />
<a class="reflocal2" href="#Adding_Point_Rejection">  Adding Point Rejection </a> <br />
<a class="reflocal2" href="#Example">  Example </a> <br />
<a class="reflocal2" href="#TODO">TODO</a><br />
</p>

<div class="float25">

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

<p>
An adaptive monte carlo algorithm to minimize a function.
 A space or volume is randomly sampled. From the best
 samples another bounding box/volume is constructed.
 Repeating the process defines the algorithm.
</p>

<p>
The algorithm implemented assumes a local minimum.
 This is in line with say mimimizing on the line
 with the fibonacci search where a minimum is assumed.
 So this algorithm is implemented when the solution is
 within the bounding volume.
</p>

</div>

<!--UPDATE_SOURCE_TABLE-->
<!--UPDATE_SOURCE_TABLE_BEGIN-->
<div class="float25">
<a id="Source"> </a>
<h2> <a class="reflocal" href="../../download.html">Source</a> </h2>
<h3> Files </h3>
<a class="reflocal" href="Makefile">Makefile</a> <br/>
<a class="reflocal" href="main.cpp">main.cpp</a> <br/>
<a class="reflocal" href="minmonte.h">minmonte.h</a> <br/>
<br/>
<a class="reflocal" href="projcompile.txt">projcompile.txt</a> <br/>
<a class="reflocal" href="unittestsreport.txt">unittestsreport.txt</a> <br/>
<br/>
</div>
<div class="float25">
<h3> Doxygen </h3>
<a class="reflocal" href="../html/minmonte_2main_8cpp.html">main.cpp</a> <br/>
<a class="reflocal" href="Makefile.html"> Makefile </a> <br/>
<a class="reflocal" href="../html/classminmonte.html">minmonte</a> <br/>
<a class="reflocal" href="../html/classvalueindex.html">valueindex</a> <br/>
</div>
<!--UPDATE_SOURCE_TABLE_END-->

<div class="float25">

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

<p>
As the algorithm is addaptive there are
 essentially two variable paramters, the
 number of sample point <code>ns</code> and
 the sample size <code>s</code> to form the
 next bounding box. Actually the third 
 would by the number of iterations.  
</p>

<p class="equ">
Let 
<math xmlns="&mathml;">
  <mi>w</mi>
  <msup>
    <mi></mi>
    <mrow><mo>[</mo><mi>k</mi><mo>]</mo></mrow>
  </msup>
  <mo>(</mo>
  <mi>s</mi>
  <msub>
    <mi></mi>
    <mrow><mi>i</mi></mrow>
  </msub>
  <mo>,</mo>
  <mi>ns</mi>
  <msub>
    <mi></mi>
    <mrow><mi>i</mi></mrow>
  </msub>
  <mo>)</mo>
</math>

 be notation for the algorithm iterated 

<math xmlns="&mathml;">
  <mi>k</mi>
</math>
 times.
</p>

<p class="equ">

Let 

<math xmlns="&mathml;">
  <mi>m</mi>
  <mo>=</mo>
  <munderover>
    <mo>&Sum;</mo>
    <mrow>
      <mi>i</mi>
      <mo>=</mo>
      <mi>0</mi>
    </mrow>
    <mrow><mi>k</mi><mo>-</mo><mi>1</mi></mrow>
  </munderover>
  <mi>ns</mi>
  <msub>
    <mi></mi>
    <mrow><mi>i</mi></mrow>
  </msub>
</math>

 be a measure of the number of function evaluations.

<br />

How are 

<math xmlns="&mathml;">
  <mi>k</mi> 
</math>
, 

<math xmlns="&mathml;">
  <mi>ns</mi>
  <msub>
    <mi></mi>
    <mrow><mi>i</mi></mrow>
  </msub> 
</math>

 and 

<math xmlns="&mathml;">
  <mi>s</mi>
  <msub>
    <mi></mi>
    <mrow><mi>i</mi></mrow>
  </msub>
</math>

 choosen to mimimize 

<math xmlns="&mathml;">
  <mi>m</mi>
</math>
?

</p>

</div>

<div class="float25">

<p>
TODO
 Remember the best solution and put it into the next
 sample space.

</p>

<p>
TODO
<b>Overshoot</b> - often variables approach the true solution 
 in a limiting sense.
 It is quite real that by taking the best results the true solution
 bound is cut away. A way to address this problem may be to
 take the best s results and form a bounding box
 and increase the box's size by say 5%(in truth it would be
 made into another variable supplied by the user as there are
 always situations where this approach wouldn't make sense - say
 when your bounding volume isn't going to zero), 
 thereby always capturing
 the minimum. Convergence is a little slower but the algorithm
 would be more adaptive - much less likely to deteriorate with overshoot.

</p>

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

<a id="Adding_Point_Rejection"> </a>
<h2> Adding Point Rejection </h2>

<p> TODO;
Two classes, one to start the algorithm when the
 bounding box is greater than the problems space.
 Reject points outside the space and accept others.
 Iterate until the bounding box is within the problems
 space.
</p>

<p>
To test if the bounding box is in the problem space, 
 possibilities include testing all combinations with
 the bounding box points(for
 small dim). Alternatively when all samples land in the correct space
 accept that the box is within the problems bounds.
</p>

<p>
Derive <code> minmonteinit </code> which adds a conditional
 template argument that tests if a point is within the problem
 region, accepting or rejecting the point. s good points are sampled.
</p>

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

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

<p class="equ">
<math xmlns="&mathml;">
  <mi>f</mi>
  <mo>(</mo>
  <mi>x</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>,</mo>
  <mi>x</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
  <mo>)</mo>
  <mo>=</mo>
  <mo>(</mo>
  <mi>x</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>3</mi>
  <mo>)</mo>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>
  <mo>+</mo>
  <mi>9</mi>
  <mo>(</mo>
  <mi>x</mi>
  <msub>
    <mi></mi>
    <mrow><mi>1</mi></mrow>
  </msub>
  <mo>-</mo>
  <mi>5</mi>
  <mo>)</mo>
  <msup>
    <mi></mi>
    <mrow><mi>2</mi></mrow>
  </msup>
</math>

 has a minimum at 

<math xmlns="&mathml;">
  <mo>[</mo>
  <mi>3</mi>
  <mo>,</mo>
  <mi>5</mi>
  <mo>]</mo>
  
</math>

</p>

<p>
80 function evaluations per iteration with the best 5 forming 
 a new bounding volume.
</p>

<pre>
ns=80; s=5;
a=[1,1]  b=[8,8]  lenab=[7,7]
a=[1.99122,4.59381]  b=[4.34178,5.4021]  lenab=[2.35056,0.80829]
a=[2.64947,5.03522]  b=[3.16214,5.07755]  lenab=[0.512662,0.0423337]
a=[2.93421,5.03547]  b=[3.06427,5.04618]  lenab=[0.130061,0.0107063]
a=[2.99541,5.03583]  b=[3.01512,5.03752]  lenab=[0.0197176,0.00169228]
a=[2.99627,5.03585]  b=[3.00706,5.03596]  lenab=[0.0107894,0.000104257]
</pre>

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

<a id="TODO"></a>
<h2>TODO</h2>
<ul>
<li>I believe this is an adaptive random search algorithm.  </li>
<li>The monte carlo boxing is subseptible to convergence problem
 where points converge to outer level curves.  This keeps a large
 region open. Rework and clear this theory up. Find a solution.
</li>

<li>
Direct search on random interval hybrid. <br />
Implement the pattern searches exploritory move with instead a random
 interval.  If no better position is found reduce the interval about
 the optimal point. Let each exploration step have k random point tests.
 Implement this in Pattern Search as it is a variation of that algorithm.
</li>

<li>Rewrite the class so that the dimension is not a templated parameter.
 Rewite the whole class with a formal review.  Document with Doxygen comments.
</li>

<li>Test with the Rosenbrock function.</li>

</ul>

</div>

</body>
</html>


