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:13:18 +0000

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

Modified files:
        optimization   : downhill_simplex.h 

Log message:
        Add Precision.

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

Patches:
Index: downhill_simplex.h
===================================================================
RCS file: /cvsroot/toon/TooN/optimization/downhill_simplex.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- downhill_simplex.h  27 May 2009 10:11:26 -0000      1.4
+++ downhill_simplex.h  27 May 2009 10:13:18 -0000      1.5
@@ -82,11 +82,11 @@
 
 
 **/
-template<int N=-1> class DownhillSimplex
+template<int N=-1, typename Precision=double> class DownhillSimplex
 {
        static const int Vertices = (N==-1?-1:N+1);
-       typedef Matrix<Vertices, N> Simplex;
-       typedef Vector<Vertices> Values;
+       typedef Matrix<Vertices, N, Precision> Simplex;
+       typedef Vector<Vertices, Precision> Values;
 
        public:
                /// Initialize the DownhillSimplex class. The simplex is 
automatically
@@ -97,7 +97,7 @@
                ///@param c          Origin of the initial simplex. The 
dimension of this vector
                ///                  is used to determine the dimension of the 
run-time sized version.
                ///@param spread     Size of the initial simplex.
-               template<class Function> DownhillSimplex(const Function& func, 
const Vector<N>& c, double spread=1)
+               template<class Function> DownhillSimplex(const Function& func, 
const Vector<N>& c, Precision spread=1)
                :simplex(c.size()+1, c.size()),values(c.size())
                {
                        alpha = 1.0;
@@ -115,7 +115,7 @@
                ///@param func       Functor to minimize.
                ///@param c          \e c corner point of the simplex
                ///@param spread     \e spread simplex size
-               template<class Function> void restart(const Function& func, 
const Vector<N>& c, double spread)
+               template<class Function> void restart(const Function& func, 
const Vector<N>& c, Precision spread)
                {
                        for(int i=0; i < simplex.num_rows(); i++)
                                simplex[i] = c;
@@ -132,7 +132,7 @@
                ///
                ///@param func       Functor to minimize.
                ///@param spread     simplex size
-               template<class Function> void restart(const Function& func, 
double spread)
+               template<class Function> void restart(const Function& func, 
Precision spread)
                {
                        restart(func, simplex[get_best()], spread);
                }
@@ -171,7 +171,7 @@
                        // - The best point
                        // - The centroid of all the points but the worst
                        int worst = get_worst();
-                       double second_worst_val=-HUGE_VAL, bestval = HUGE_VAL, 
worst_val = values[worst];
+                       Precision second_worst_val=-HUGE_VAL, bestval = 
HUGE_VAL, worst_val = values[worst];
                        int best=0;
                        Vector<N> x0 = Zeros(simplex.num_cols());
 
@@ -198,13 +198,13 @@
 
                        //Reflect the worst point about the centroid.
                        Vector<N> xr = (1 + alpha) * x0 - alpha * 
simplex[worst];
-                       double fr = func(xr);
+                       Precision fr = func(xr);
 
                        if(fr < bestval)
                        {
                                //If the new point is better than the smallest, 
then try expanding the simplex.
                                Vector<N> xe = rho * xr + (1-rho) * x0;
-                               double fe = func(xe);
+                               Precision fe = func(xe);
 
                                //Keep whichever is best
                                if(fe < fr)
@@ -237,7 +237,7 @@
                        if(fr < worst_val)
                        {
                                Vector<N> xc = (1 + gamma) * x0 - gamma * 
simplex[worst];
-                               double fc = func(xc);
+                               Precision fc = func(xc);
 
                                //If this helped, use it
                                if(fc <= fr)
@@ -262,8 +262,9 @@
 
 
 
+               Precision alpha, rho, gamma, sigma;
+
        private:
-               float alpha, rho, gamma, sigma;
 
                //Each row is a simplex vertex
                Simplex simplex;




reply via email to

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