toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] TooN/optimization downhill_simplex.h


From: Edward Rosten
Subject: [Toon-members] TooN/optimization downhill_simplex.h
Date: Wed, 27 May 2009 10:09:12 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Edward Rosten <edrosten>        09/05/27 10:09:12

Modified files:
        optimization   : downhill_simplex.h 

Log message:
        Added a reset function.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/optimization/downhill_simplex.h?cvsroot=toon&r1=1.2&r2=1.3

Patches:
Index: downhill_simplex.h
===================================================================
RCS file: /cvsroot/toon/TooN/optimization/downhill_simplex.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- downhill_simplex.h  26 May 2009 18:06:01 -0000      1.2
+++ downhill_simplex.h  27 May 2009 10:09:12 -0000      1.3
@@ -100,21 +100,43 @@
                template<class Function> DownhillSimplex(const Function& func, 
const Vector<N>& c, double spread=1)
                :simplex(c.size()+1, c.size()),values(c.size())
                {
+                       alpha = 1.0;
+                       rho = 2.0;
+                       gamma = 0.5;
+                       sigma = 0.5;
+
+                       restart(func, c, spread);
+
+               }
+               
+               /// This function sets up the simplex around, with one point at 
\e c and the remaining
+               /// points are made by moving by \e spread along each axis 
aligned unit vector.
+               ///
+               ///@param func       Functor to minimize.
+               ///@param c          \e c corner point of the simplex
+               ///@param spread     \e spread simplex size
+               template<class Function> restart(const Function& func, const 
Vector<N>& c, double spread)
+               {
                        for(int i=0; i < simplex.num_rows(); i++)
                                simplex[i] = c;
 
                        for(int i=0; i < simplex.num_cols(); i++)
                                simplex[i][i] += spread;
 
-                       alpha = 1.0;
-                       rho = 2.0;
-                       gamma = 0.5;
-                       sigma = 0.5;
-
                        for(int i=0; i < values.size(); i++)
                                values[i] = func(simplex[i]);
                }
 
+               
+               /// This function resets the simplex around the best current 
point.
+               ///
+               ///@param func       Functor to minimize.
+               ///@param spread     simplex size
+               template<class Function> restart(const Function& func, double 
spread)
+               {
+                       restart(func, simplex[get_best()], spread);
+               }
+
                ///Return the simplex
                const Simplex& get_simplex() const
                {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]