[Rcpp-commits] r2361 - in pkg/RcppDE: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Oct 26 14:02:12 CEST 2010
Author: edd
Date: 2010-10-26 14:02:11 +0200 (Tue, 26 Oct 2010)
New Revision: 2361
Modified:
pkg/RcppDE/DESCRIPTION
pkg/RcppDE/src/Makevars
pkg/RcppDE/src/de4_0.cpp
pkg/RcppDE/src/evaluate.cpp
Log:
init sortindex for strat==6
correct inner loop for bs=TRUE
depend on RcppArmadillo (>= 0.2.8) for unsafe_col
Modified: pkg/RcppDE/DESCRIPTION
===================================================================
--- pkg/RcppDE/DESCRIPTION 2010-10-24 01:51:28 UTC (rev 2360)
+++ pkg/RcppDE/DESCRIPTION 2010-10-26 12:02:11 UTC (rev 2361)
@@ -9,5 +9,5 @@
It aims to show that "easier, shorter, faster: pick any three" is achievable
when moving code from plain old C to modern C++.
License: GPL (>= 2)
-Depends: Rcpp, RcppArmadillo
+Depends: Rcpp, RcppArmadillo (>= 0.2.8)
LinkingTo: Rcpp, RcppArmadillo
Modified: pkg/RcppDE/src/Makevars
===================================================================
--- pkg/RcppDE/src/Makevars 2010-10-24 01:51:28 UTC (rev 2360)
+++ pkg/RcppDE/src/Makevars 2010-10-26 12:02:11 UTC (rev 2361)
@@ -3,5 +3,5 @@
##PKG_LIBS=$(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -fopenmp
##PKG_LIBS= -fopenmp -lgomp $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
##PKG_CXXFLAGS+=-D_FORTIFY_SOURCE=0 -g0 -funsafe-loop-optimizations -Wunsafe-loop-optimizations
-##PKG_LIBS= $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -lprofiler
+#PKG_LIBS= $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -lprofiler
PKG_LIBS= $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
Modified: pkg/RcppDE/src/de4_0.cpp
===================================================================
--- pkg/RcppDE/src/de4_0.cpp 2010-10-24 01:51:28 UTC (rev 2360)
+++ pkg/RcppDE/src/de4_0.cpp 2010-10-26 12:02:11 UTC (rev 2361)
@@ -18,11 +18,10 @@
int i_specinitialpop, int i_check_winner, int i_av_winner,
arma::mat & ta_popP, arma::mat & ta_oldP, arma::mat & ta_newP, arma::colvec & t_bestP,
arma::colvec & ta_popC, arma::colvec & ta_oldC, arma::colvec & ta_newC, double & t_bestC,
- arma::colvec & t_bestitP, arma::colvec & t_tmpP, //arma::colvec & tempP,
- arma::mat & d_pop, Rcpp::List & d_storepop, arma::mat & d_bestmemit, arma::colvec & d_bestvalit,
- int & i_iterations, double i_pPct, long & l_nfeval);
+ arma::colvec & t_bestitP, arma::colvec & t_tmpP, arma::mat & d_pop, Rcpp::List & d_storepop,
+ arma::mat & d_bestmemit, arma::colvec & d_bestvalit, int & i_iterations, double i_pPct, long & l_nfeval);
void permute(int ia_urn2[], int i_urn2_depth, int i_NP, int i_avoid, int ia_urntmp[]);
-RcppExport double evaluate(long &l_nfeval, const double *param, SEXP parS, SEXP fcall, SEXP env);
+double evaluate(long &l_nfeval, const double *param, SEXP parS, SEXP fcall, SEXP env);
RcppExport SEXP DEoptimC(SEXP lowerS, SEXP upperS, SEXP fnS, SEXP controlS, SEXP rhoS) {
@@ -121,8 +120,10 @@
int p_NP = round(i_pPct * i_NP); // choose at least two best solutions
p_NP = p_NP < 2 ? 2 : p_NP;
arma::icolvec sortIndex(i_NP); // sorted values of ta_oldC
- //for(int i = 0; i < i_NP; i++) sortIndex[i] = i; // FIXME: does this really need to get filled here?
-
+ if (i_strategy == 6) {
+ for (int i = 0; i < i_NP; i++)
+ sortIndex[i] = i;
+ }
GetRNGstate();
initialpop.zeros(); // initialize initial popuplation
@@ -288,20 +289,21 @@
ta_popC.rows(i_NP, 2*i_NP-1) = ta_newC;
int i_len = 2 * i_NP;
- int step = i_len; // array length
+ int step = i_len, done; // array length
while (step > 1) {
step /= 2; // halve the step size
- for (bool done=false; ! done; ) {
+ do {
+ done = 1;
int bound = i_len - step;
for (int j = 0; j < bound; j++) {
int i = j + step + 1;
if (ta_popC[j] > ta_popC[i-1]) {
ta_popP.swap_cols(j, i-1);
ta_popC.swap_rows(j, i-1);
- done = true;
+ done = 0;
} // if
} // for
- } // for (!done)
+ } while (!done); // while
} // while (step > 1)
ta_newP = ta_popP.cols(0, i_NP-1); // now the best NP are in first NP places in gta_pop, use them
ta_newC = ta_popC.rows(0, i_NP-1);
@@ -319,10 +321,11 @@
}
if (same && i_iter > 1) {
i_xav++;
- double tmp_best = evaluate(l_nfeval, t_bestP.memptr(), par, fcall, rho); // if re-evaluation of winner
+ double tmp_best = evaluate(l_nfeval, t_bestP.memptr(), par, fcall, rho); // if re-evaluation of winner
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);
+ 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;
} else {
Modified: pkg/RcppDE/src/evaluate.cpp
===================================================================
--- pkg/RcppDE/src/evaluate.cpp 2010-10-24 01:51:28 UTC (rev 2360)
+++ pkg/RcppDE/src/evaluate.cpp 2010-10-26 12:02:11 UTC (rev 2361)
@@ -10,7 +10,7 @@
// Slighly accelerated version of evaluate to evaluate function fcall with parameters param in environment env
// Uses externally allocated par() vector into which param are copied
//
-RcppExport double evaluate(long &l_nfeval, const double *param, SEXP par, SEXP fcall, SEXP env) {
+double evaluate(long &l_nfeval, const double *param, SEXP par, SEXP fcall, SEXP env) {
// -- safer approach: cast to NumericVector, fill it and eval
//Rcpp::NumericVector parvec(par); // access parS as numeric vector to fill it
//memcpy(parvec.begin(), param, parvec.size() * sizeof(double));
More information about the Rcpp-commits
mailing list