[Rcpp-commits] r2327 - in pkg/RcppDE: . R src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Oct 17 00:54:34 CEST 2010


Author: edd
Date: 2010-10-17 00:54:33 +0200 (Sun, 17 Oct 2010)
New Revision: 2327

Modified:
   pkg/RcppDE/R/DEoptim.R
   pkg/RcppDE/benchmark.txt
   pkg/RcppDE/src/de4_0.cpp
Log:
now the initialpop is a matrix on entry
and we also make sure we pass at least a dummy matrix in from R so all is good


Modified: pkg/RcppDE/R/DEoptim.R
===================================================================
--- pkg/RcppDE/R/DEoptim.R	2010-10-16 22:24:59 UTC (rev 2326)
+++ pkg/RcppDE/R/DEoptim.R	2010-10-16 22:54:33 UTC (rev 2327)
@@ -87,12 +87,11 @@
   }
   else {
     ctrl$specinitialpop <- FALSE
-    ctrl$initialpop <- 0.0
+    ctrl$initialpop <- matrix(0,1,1)    # dummy matrix
   }
   ##
   ctrl$trace <- as.numeric(ctrl$trace)
   ctrl$specinitialpop <- as.numeric(ctrl$specinitialpop)
-  #ctrl$initialpop <- as.numeric(ctrl$initialpop)
 
   outC <- .Call("DEoptimC", lower, upper, fn1, ctrl, new.env(), PACKAGE = "RcppDE")
   ##

Modified: pkg/RcppDE/benchmark.txt
===================================================================
--- pkg/RcppDE/benchmark.txt	2010-10-16 22:24:59 UTC (rev 2326)
+++ pkg/RcppDE/benchmark.txt	2010-10-16 22:54:33 UTC (rev 2327)
@@ -240,3 +240,17 @@
 MEANS       0.568667 0.584861           1.0285       -2.8478
 
 
+# At  2010-10-16 17:32:19.869673
+# SVN  2322:2326
+             DEoptim   RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin2  0.040333 0.041556           1.0303      -3.03030
+Rastrigin5  0.106278 0.109167           1.0272      -2.71824
+Rastrigin20 0.538444 0.552167           1.0255      -2.54849
+Wild2       0.066111 0.066833           1.0109      -1.09244
+Wild5       0.180333 0.182500           1.0120      -1.20148
+Wild20      1.038944 1.049222           1.0099      -0.98925
+Genrose2    0.070278 0.071500           1.0174      -1.73913
+Genrose5    0.184611 0.186500           1.0102      -1.02317
+Genrose20   0.898667 0.909056           1.0116      -1.15603
+Genrose50   2.523167 2.603778           1.0319      -3.19484
+MEANS       0.564717 0.577228           1.0222      -2.21547

Modified: pkg/RcppDE/src/de4_0.cpp
===================================================================
--- pkg/RcppDE/src/de4_0.cpp	2010-10-16 22:24:59 UTC (rev 2326)
+++ pkg/RcppDE/src/de4_0.cpp	2010-10-16 22:54:33 UTC (rev 2327)
@@ -114,7 +114,7 @@
 
     int i_nstorepop = ceil((i_itermax - i_storepopfrom) / i_storepopfreq);
     int i_xav, popcnt, bestacnt, same; 		// lazy cnters 
-    double f_jitter, f_dither, t_bestitC, t_tmpC, tmp_best, tempC; 
+    double f_jitter, f_dither, t_bestitC, t_tmpC, tmp_best; 
     
     arma::mat initialpop(i_NP, i_D); 
 
@@ -125,11 +125,13 @@
     for(i = 0; i < i_NP; i++) sortIndex[i] = i;
 
     int i_len, done, step, bound;    		// vars for when i_bs_flag == 1 */
+    double tempC;
 
     GetRNGstate();
 
     ta_popP.at(0,0) = 0;
     
+    initialpop.zeros();		 		// initialize initial popuplation 
     d_bestmemit.zeros();    			// initialize best members
     d_bestvalit.zeros();			// initialize best values 
     d_pop.zeros();				// initialize best population
@@ -137,9 +139,14 @@
     i_nstorepop = (i_nstorepop < 0) ? 0 : i_nstorepop;
       
     if (i_specinitialpop > 0) {    		// if initial population provided, initialize with values 
-	initialpop = initialpopm;
+	k = 0;
+	for (j = 0; j < i_D; j++) { 		// FIXME: should really have a matrix passed in ! 
+	    for (i = 0; i < i_NP; i++) {
+		initialpop.at(i,j) = initialpopm[k];
+		k += 1;
+	    }
+	}
     }
-
     l_nfeval = 0;    				// number of function evaluations (this is an input via DEoptim.control, but we over-write it?) 
 
     for (i = 0; i < i_NP; i++) {		// ------Initialization-----------------------------
@@ -147,7 +154,7 @@
 	    for (j = 0; j < i_D; j++) {
 		ta_popP.at(i,j) = fa_minbound[j] + unif_rand() * (fa_maxbound[j] - fa_minbound[j]);
 	    }
-	} else { 				// or user-specified initial member */
+	} else { /* or user-specified initial member */
 	    ta_popP.row(i) = initialpop.row(i);
 	} 
 	ta_popC[i] = evaluate(l_nfeval, ta_popP.row(i), par, fcall, rho);
@@ -173,7 +180,7 @@
 		    popcnt++;
 		}
 	    }
-	} // end store pop 
+	} /* end store pop */
       
 	d_bestmemit.row(i_iter) = t_bestP;	// store the best member
 	d_bestvalit[i_iter] = t_bestC;		// store the best value 
@@ -205,7 +212,7 @@
 		j = (int)(unif_rand() * i_D); 	// random parameter 
 		k = 0;
 		do {
-		    // add fluctuation to random target 
+		    /* add fluctuation to random target */
 		    t_tmpP[j] = ta_oldP.at(i_r1,j) + f_weight * (ta_oldP.at(i_r2,j) - ta_oldP.at(i_r3,j));
 		    j = (j + 1) % i_D;
 		    k++;
@@ -216,7 +223,7 @@
 		j = (int)(unif_rand() * i_D); 	// random parameter 
 		k = 0;
 		do {
-		    // add fluctuation to random target 
+		    /* add fluctuation to random target */
 		    t_tmpP[j] = t_tmpP[j] + f_weight * (t_bestitP[j] - t_tmpP[j]) + f_weight * (ta_oldP.at(i_r2,j) - ta_oldP.at(i_r3,j));
 		    j = (j + 1) % i_D;
 		    k++;
@@ -274,7 +281,7 @@
 		k = 0;
 		if (unif_rand() < 0.5) { 	// differential mutation, Pmu = 0.5 
 		    do {
-			// add fluctuation to random target 
+			// add fluctuation to random target */
 			t_tmpP[j] = ta_oldP.at(i_r1,j) + f_weight * (ta_oldP.at(i_r2,j) - ta_oldP.at(i_r3,j));
 			j = (j + 1) % i_D;
 			k++;
@@ -282,7 +289,7 @@
 
 		} else { 			// recombination with K = 0.5*(F+1) -. F-K-Rule 
 		    do {
-			// add fluctuation to random target 
+			// add fluctuation to random target */
 			t_tmpP[j] = ta_oldP.at(i_r1,j) + 0.5 * (f_weight + 1.0) * (ta_oldP.at(i_r2,j) + ta_oldP.at(i_r3,j) - 2 * ta_oldP.at(i_r1,j));
 			j = (j + 1) % i_D;
 			k++;
@@ -321,6 +328,7 @@
 	    
 	    ta_popP.rows(0, i_NP-1) = ta_oldP;
 	    ta_popC.rows(0, i_NP-1) = ta_oldC;
+
 	    ta_popP.rows(i_NP, 2*i_NP-1) = ta_newP;
 	    ta_popC.rows(i_NP, 2*i_NP-1) = ta_newC;
 
@@ -341,19 +349,18 @@
 			    ta_popP.row(j) = tempP;
 			    ta_popC[j] = tempC;
 			    done = 0; 
-			    // if a swap has been made we are not finished yet 
 			}  // if 
 		    }  // for 
 		} while (!done);   // do .. while 
 	    } // while (step > 1) 
-	    ta_newP = ta_popP;		// now the best NP are in first NP places in gta_pop, use them 
+	    ta_newP = ta_popP;			// now the best NP are in first NP places in gta_pop, use them
 	    ta_newC = ta_popC;
 	} // i_bs_flag
 
-	ta_oldP = ta_newP;		// have selected NP mutants move on to next generation 
+	ta_oldP = ta_newP;			// have selected NP mutants move on to next generation 
 	ta_oldC = ta_newC;
 
-	if (i_check_winner)  {		// check if the best stayed the same, if necessary 
+	if (i_check_winner)  {			// check if the best stayed the same, if necessary 
 	    same = 1;
 	    for (j = 0; j < i_D; j++)
 		if (t_bestitP[j] != t_bestP[j]) {
@@ -363,7 +370,7 @@
 		i_xav++;
 		tmp_best = evaluate(l_nfeval, t_bestP, par, fcall, rho);			// if re-evaluation of winner 
 		
-		if (i_av_winner)			//  possibly letting the winner be the average of all past generations 
+		if (i_av_winner)		//  possibly letting the winner be the average of all past generations 
 		    t_bestC = ((1/(double)i_xav) * t_bestC) + ((1/(double)i_xav) * tmp_best) + (d_bestvalit[i_iter-1] * ((double)(i_xav - 2))/(double)i_xav);
 		else
 		    t_bestC = tmp_best;
@@ -421,7 +428,7 @@
 	ia_urn1[i] = i; /* initialize urn1 */
 
     i_urn1 = i_avoid;                      /* get rid of the index to be avoided and place it in position 0. */
-    while (k > i_NP - i_urn2_depth) {       /* i_urn2_depth is the amount of indices wanted (must be <= NP) */
+    while (k > i_NP - i_urn2_depth) {      /* i_urn2_depth is the amount of indices wanted (must be <= NP) */
 	ia_urn2[i_urn2] = ia_urn1[i_urn1]; /* move it into urn2 */
 	ia_urn1[i_urn1] = ia_urn1[k-1];    /* move highest index to fill gap */
 	k = k - 1;                         /* reduce number of accessible indices */



More information about the Rcpp-commits mailing list