More Nelder-Mead algorithm code.
authorIsaac Dooley <isaacdooley@hope.cs.uiuc.edu>
Mon, 15 Mar 2010 23:14:46 +0000 (18:14 -0500)
committerIsaac Dooley <isaacdooley@hope.cs.uiuc.edu>
Mon, 15 Mar 2010 23:27:51 +0000 (18:27 -0500)
Fixing compiler errors from previous commit.

src/ck-cp/controlPoints.C
src/ck-cp/controlPoints.h

index 26d453b12d834556d061a9efdda6b14adbe35e24..7f1c5dc46c05bc3e9c2bdaeda1d69f485fd43bf1 100644 (file)
@@ -1685,7 +1685,12 @@ int controlPoint(const char *name, int lb, int ub){
 
 
 void simplexScheme::adapt(std::map<std::string, std::pair<int,int> > & controlPointSpace, std::map<std::string,int> &newControlPoints, const int phase_id, instrumentedData &allData){
-       textcolor(BRIGHT, RED, WHITE);
+
+       if(useBestKnown){
+               CkPrintf("Simplex Tuning: Simplex algorithm is done, using best known phase:\n");
+               return;
+       }
+
 
        if(firstSimplexPhase< 0){
                firstSimplexPhase = allData.phases.size()-1;
@@ -1854,10 +1859,6 @@ void simplexScheme::adapt(std::map<std::string, std::pair<int,int> > & controlPo
                CkAbort("Unknown simplexState");
        }
 
-
-       textcolor(RESET, BLACK, WHITE);
-
-
 }
 
 
@@ -1935,6 +1936,34 @@ void simplexScheme::doReflection(std::map<std::string, std::pair<int,int> > & co
 
        computeCentroidBestWorst(controlPointSpace, newControlPoints, phase_id, allData);
 
+
+       // Quit if the diameter of our simplex is small
+       double maxr = 0.0;
+       for(int i=0; i<n+1; i++){
+               //              Compute r^2 of this simplex point from the centroid
+               double r2 = 0.0;
+               std::vector<double> p = pointCoords(allData, i);
+               for(int d=0; d<p.size(); d++){
+                       double r1 = (p[d] * centroid[d]);
+                       r2 += r1*r1;
+               }
+               if(r2 > maxr)
+                       maxr = r2;
+       }
+
+       if(maxr < 20){
+               useBestKnown = true;
+               instrumentedPhase *best = allData.findBest();
+               CkPrintf("Simplex Tuning: Simplex diameter is small, so switching over to best known phase:\n");
+
+               std::map<std::string, std::pair<int,int> >::const_iterator cpsIter;
+               for(cpsIter=controlPointSpace.begin(); cpsIter != controlPointSpace.end(); ++cpsIter) {
+                       const std::string &name = cpsIter->first;
+                       newControlPoints[name] =  best->controlPoints[name];
+               }
+       }
+
+
        // Compute new point P* =(1+alpha)*centroid - alpha(worstPoint)
 
        pPhase = allData.phases.size()-1;
@@ -1944,7 +1973,7 @@ void simplexScheme::doReflection(std::map<std::string, std::pair<int,int> > & co
        }
 
        for(int i=0; i<P.size(); i++){
-               CkPrintf("P dimension %d is %f\n", i, P[i]);
+               CkPrintf("Simplex Tuning: P dimension %d is %f\n", i, P[i]);
        }
 
 
index 99379c89cab9986d3a4c19fcea89d315b8ac21aa..dcf1876305c36fa6a1a38842a2168876f46ac8ca 100644 (file)
 #include "pathHistory.h" 
 
 
-
-
-#define RESET          0
-#define BRIGHT                 1
-#define DIM            2
-#define UNDERLINE      3
-#define BLINK          4
-#define REVERSE                7
-#define HIDDEN         8
-
-#define BLACK          0
-#define RED            1
-#define GREEN          2
-#define YELLOW         3
-#define BLUE           4
-#define MAGENTA                5
-#define CYAN           6
-#define        WHITE           7
-
-
-
-
-
-
-
 #include <cp_effects.h>
 
 /**
@@ -647,6 +622,7 @@ private:
        // A set of phases for which (P_i+P_l)/2 ought to be evaluated
        std::set<int> stillMustContractList;
 
+       bool useBestKnown;
 
        void computeCentroidBestWorst(std::map<std::string, std::pair<int,int> > & controlPointSpace, std::map<std::string,int> &newControlPoints, const int phase_id, instrumentedData &allData);
 
@@ -680,23 +656,13 @@ private:
                        CkPrintf("Current simplex is:\n%s\n", s);
                }
 
-
-               /// A helper routine to color my terminal output
-               void textcolor(int attr, int fg, int bg)
-               {       char command[13];
-
-                       /* Command is the control command to the terminal */
-                       sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
-                       CkPrintf("%s", command);
-               }
-
-
 public:
 
        simplexScheme() :
                simplexState(beginning),
                alpha(1.0), beta(0.5), gamma(2.0),
-               firstSimplexPhase(-1)
+               firstSimplexPhase(-1),
+               useBestKnown(false)
        {
                // Make sure the coefficients are reasonable
                CkAssert(alpha >= 0);