[Rcpp-commits] r2318 - in pkg/RcppDE: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Oct 16 23:22:25 CEST 2010
Author: edd
Date: 2010-10-16 23:22:25 +0200 (Sat, 16 Oct 2010)
New Revision: 2318
Modified:
pkg/RcppDE/benchmark.txt
pkg/RcppDE/src/de4_0.cpp
Log:
mostly re-indenting
Modified: pkg/RcppDE/benchmark.txt
===================================================================
--- pkg/RcppDE/benchmark.txt 2010-10-16 21:05:18 UTC (rev 2317)
+++ pkg/RcppDE/benchmark.txt 2010-10-16 21:22:25 UTC (rev 2318)
@@ -127,3 +127,50 @@
Genrose20 0.884500 0.896111 1.0131 -1.31273
Genrose50 2.503333 2.542278 1.0156 -1.55570
MEANS 0.560250 0.567533 1.0130 -1.3000
+
+# At 2010-10-16 15:49:18.185113
+# SVN 2313:2315
+ DEoptim RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin2 0.040056 0.041611 1.0388 -3.88350
+Rastrigin5 0.104778 0.110389 1.0536 -5.35525
+Rastrigin20 0.540667 0.545778 1.0095 -0.94533
+Wild2 0.065833 0.067556 1.0262 -2.61603
+Wild5 0.179167 0.183111 1.0220 -2.20155
+Wild20 1.034500 1.046389 1.0115 -1.14924
+Genrose2 0.069889 0.071833 1.0278 -2.78219
+Genrose5 0.184944 0.188500 1.0192 -1.92250
+Genrose20 0.890722 0.900833 1.0114 -1.13516
+Genrose50 2.563278 2.576667 1.0052 -0.52233
+MEANS 0.567383 0.573267 1.0104 -1.03692
+
+
+# At 2010-10-16 16:02:19.151733
+# SVN 2313:2315M
+ DEoptim RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin2 0.040000 0.041722 1.0431 -4.3056
+Rastrigin5 0.106833 0.109000 1.0203 -2.0281
+Rastrigin20 0.536722 0.548389 1.0217 -2.1737
+Wild2 0.066167 0.067444 1.0193 -1.9312
+Wild5 0.180556 0.183056 1.0138 -1.3846
+Wild20 1.029778 1.045000 1.0148 -1.4782
+Genrose2 0.070167 0.072222 1.0293 -2.9295
+Genrose5 0.186056 0.187944 1.0102 -1.0152
+Genrose20 0.891167 0.910278 1.0214 -2.1445
+Genrose50 2.523000 2.570111 1.0187 -1.8673
+MEANS 0.563044 0.573517 1.0186 -1.8599
+
+
+# At 2010-10-16 16:09:42.62347
+# SVN 2317M
+ DEoptim RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin2 0.040222 0.041444 1.0304 -3.03867
+Rastrigin5 0.105389 0.108056 1.0253 -2.53031
+Rastrigin20 0.538056 0.553000 1.0278 -2.77749
+Wild2 0.066222 0.066833 1.0092 -0.92282
+Wild5 0.181722 0.182722 1.0055 -0.55029
+Wild20 1.034167 1.039667 1.0053 -0.53183
+Genrose2 0.069778 0.071778 1.0287 -2.86624
+Genrose5 0.185333 0.186944 1.0087 -0.86930
+Genrose20 0.886389 0.897556 1.0126 -1.25979
+Genrose50 2.523278 2.563389 1.0159 -1.58964
+MEANS 0.563056 0.571139 1.0144 -1.43562
Modified: pkg/RcppDE/src/de4_0.cpp
===================================================================
--- pkg/RcppDE/src/de4_0.cpp 2010-10-16 21:05:18 UTC (rev 2317)
+++ pkg/RcppDE/src/de4_0.cpp 2010-10-16 21:22:25 UTC (rev 2318)
@@ -185,19 +185,11 @@
}
} /* end store pop */
- //for(j = 0; j < i_D; j++) { // store the best member -- could also be a matrix of itermax * i_D
- // d_bestmemit[bestacnt] = t_bestP[j];
- // bestacnt++;
- //}
d_bestmemit.row(i_iter) = t_bestP; // store the best member
-
d_bestvalit[i_iter] = t_bestC; // store the best value
-
- //for (j = 0; j < i_D; j++) t_bestitP[j] = t_bestP[j];
t_bestitP = t_bestP;
t_bestitC = t_bestC;
-
- i_iter++;
+ i_iter++; // increase iteration counter
f_dither = f_weight + unif_rand() * (1.0 - f_weight); // ----computer dithering factor -----------------
@@ -217,139 +209,111 @@
i_r3 = ia_urn2[3];
i_r4 = ia_urn2[4];
- /*===Choice of strategy=======================================================*/
- /*---classical strategy DE/rand/1/bin-----------------------------------------*/
- if (i_strategy == 1) {
+ // ===Choice of strategy=======================================================
+ if (i_strategy == 1) { // ---classical strategy DE/rand/1/bin-----------------------------------------
- j = (int)(unif_rand() * i_D); /* random parameter */
+ j = (int)(unif_rand() * i_D); // random parameter
k = 0;
do {
/* 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++;
- }while((unif_rand() < f_cross) && (k < i_D));
+ } while ((unif_rand() < f_cross) && (k < i_D));
- }
- /*---DE/local-to-best/1/bin---------------------------------------------------*/
- else if (i_strategy == 2) {
+ } else if (i_strategy == 2) { // ---DE/local-to-best/1/bin---------------------------------------------------
- j = (int)(unif_rand() * i_D); /* random parameter */
+ j = (int)(unif_rand() * i_D); // random parameter
k = 0;
do {
/* 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++;
- } while((unif_rand() < f_cross) && (k < i_D));
+ } while ((unif_rand() < f_cross) && (k < i_D));
- }
- /*---DE/best/1/bin with jitter------------------------------------------------*/
- else if (i_strategy == 3) {
+ } else if (i_strategy == 3) { // ---DE/best/1/bin with jitter------------------------------------------------
- j = (int)(unif_rand() * i_D); /* random parameter */
+ j = (int)(unif_rand() * i_D); // random parameter
k = 0;
do {
- /* add fluctuation to random target */
- f_jitter = 0.0001 * unif_rand() + f_weight;
+ f_jitter = 0.0001 * unif_rand() + f_weight; // add fluctuation to random target
t_tmpP[j] = t_bestitP[j] + f_jitter * (ta_oldP.at(i_r1,j) - ta_oldP.at(i_r2,j));
-
j = (j + 1) % i_D;
k++;
- } while((unif_rand() < f_cross) && (k < i_D));
+ } while ((unif_rand() < f_cross) && (k < i_D));
- }
- /*---DE/rand/1/bin with per-vector-dither-------------------------------------*/
- else if (i_strategy == 4) {
+ } else if (i_strategy == 4) { // ---DE/rand/1/bin with per-vector-dither-------------------------------------
- j = (int)(unif_rand() * i_D); /* random parameter */
+ 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 + unif_rand()*(1.0 - f_weight))* (ta_oldP.at(i_r2,j) - ta_oldP.at(i_r3,j));
-
j = (j + 1) % i_D;
k++;
- } while((unif_rand() < f_cross) && (k < i_D));
+ } while ((unif_rand() < f_cross) && (k < i_D));
- }
- /*---DE/rand/1/bin with per-generation-dither---------------------------------*/
- else if (i_strategy == 5) {
+ } else if (i_strategy == 5) { // ---DE/rand/1/bin with per-generation-dither---------------------------------
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_dither * (ta_oldP.at(i_r2,j) - ta_oldP.at(i_r3,j));
j = (j + 1) % i_D;
k++;
- } while((unif_rand() < f_cross) && (k < i_D));
+ } while ((unif_rand() < f_cross) && (k < i_D));
- }
- /*---DE/current-to-p-best/1 (JADE)--------------------------------------------*/
- else if (i_strategy == 6) {
+ } else if (i_strategy == 6) { // ---DE/current-to-p-best/1 (JADE)--------------------------------------------
- /* select from [0, 1, 2, ..., (pNP-1)] */
- i_pbest = sortIndex[(int)(unif_rand() * p_NP)];
-
- j = (int)(unif_rand() * i_D); /* random parameter */
+ i_pbest = sortIndex[(int)(unif_rand() * p_NP)]; // select from [0, 1, 2, ..., (pNP-1)]
+ 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,j) + f_weight * (ta_oldP.at(i_pbest,j) - ta_oldP.at(i,j)) + f_weight * (ta_oldP.at(i_r1,j) - ta_oldP.at(i_r2,j));
-
j = (j + 1) % i_D;
k++;
- }while((unif_rand() < f_cross) && (k < i_D));
+ } while((unif_rand() < f_cross) && (k < i_D));
- }
- /*---variation to DE/rand/1/bin: either-or-algorithm--------------------------*/
- else {
+ } else { // ---variation to DE/rand/1/bin: either-or-algorithm--------------------------
- j = (int)(unif_rand() * i_D); /* random parameter */
+ j = (int)(unif_rand() * i_D); // random parameter
k = 0;
- if (unif_rand() < 0.5) { /* differential mutation, Pmu = 0.5 */
+ if (unif_rand() < 0.5) { // differential mutation, Pmu = 0.5
do {
/* 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++;
- }while((unif_rand() < f_cross) && (k < i_D));
- }
- else {
- /* recombination with K = 0.5*(F+1) -. F-K-Rule */
+ } while((unif_rand() < f_cross) && (k < i_D));
+
+ } else { // recombination with K = 0.5*(F+1) -. F-K-Rule
do {
/* 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++;
- }while((unif_rand() < f_cross) && (k < i_D));
-
+ } while((unif_rand() < f_cross) && (k < i_D));
}
- }/* end if (i_strategy ...*/
+ } // end if (i_strategy ...
- /*----boundary constraints, bounce-back method was not enforcing bounds correctly*/
+ // ----boundary constraints, bounce-back method was not enforcing bounds correctly
for (j = 0; j < i_D; j++) {
if (t_tmpP[j] < fa_minbound[j]) {
- t_tmpP[j] = fa_minbound[j] +
- unif_rand() * (fa_maxbound[j] - fa_minbound[j]);
+ t_tmpP[j] = fa_minbound[j] + unif_rand() * (fa_maxbound[j] - fa_minbound[j]);
}
if (t_tmpP[j] > fa_maxbound[j]) {
- t_tmpP[j] = fa_maxbound[j] -
- unif_rand() * (fa_maxbound[j] - fa_minbound[j]);
+ t_tmpP[j] = fa_maxbound[j] - unif_rand() * (fa_maxbound[j] - fa_minbound[j]);
}
}
- /*------Trial mutation now in t_tmpP-----------------*/
+ // ------Trial mutation now in t_tmpP-----------------
t_tmpC = evaluate(l_nfeval, t_tmpP, par, fcall, rho); // Evaluate mutant in t_tmpP[]
- /* note that i_bs_flag means that we will choose the
- *best NP vectors from the old and new population later*/
+ // note that i_bs_flag means that we will choose the best NP vectors from the old and new population later
if (t_tmpC <= ta_oldC[i] || i_bs_flag) {
/* replace target with mutant */
for (j = 0; j < i_D; j++)
More information about the Rcpp-commits
mailing list