[Rcpp-commits] r2395 - in pkg/RcppDE: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 5 02:03:05 CET 2010


Author: edd
Date: 2010-11-05 02:03:04 +0100 (Fri, 05 Nov 2010)
New Revision: 2395

Modified:
   pkg/RcppDE/ChangeLog
   pkg/RcppDE/R/DEoptim.R
   pkg/RcppDE/man/DEoptim.Rd
Log:
small tweaks to DEoptim.R
 - make env an argument
 - document it
 - do not redefine fn() as fn1()


Modified: pkg/RcppDE/ChangeLog
===================================================================
--- pkg/RcppDE/ChangeLog	2010-11-04 18:44:47 UTC (rev 2394)
+++ pkg/RcppDE/ChangeLog	2010-11-05 01:03:04 UTC (rev 2395)
@@ -1,3 +1,8 @@
+2010-11-04  Dirk Eddelbuettel  <edd at debian.org>
+
+	* R/DEoptim.R: Make 'env' an optional argument, don't redefine fn()
+	* man/DEoptim.Rd: Document 'env' argument
+
 2010-10-31  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/Makevars: add new define for compilation with OpenMP

Modified: pkg/RcppDE/R/DEoptim.R
===================================================================
--- pkg/RcppDE/R/DEoptim.R	2010-11-04 18:44:47 UTC (rev 2394)
+++ pkg/RcppDE/R/DEoptim.R	2010-11-05 01:03:04 UTC (rev 2395)
@@ -47,8 +47,8 @@
        checkWinner = checkWinner, avWinner = avWinner, p = p)
 }
 
-DEoptim <- function(fn, lower, upper, control = DEoptim.control(), ...) {
-  fn1  <- function(par) fn(par, ...)
+DEoptim <- function(fn, lower, upper, control = DEoptim.control(), env, ...) {
+  ##fn1  <- function(par) fn(par, ...)
   if (length(lower) != length(upper))
     stop("'lower' and 'upper' are not of same length")
   if (!is.vector(lower))
@@ -71,6 +71,8 @@
     nam <- names(upper)
   else
     nam <- paste("par", 1:length(lower), sep = "")
+  if (missing(env))
+    env <- new.env()
 
   ctrl <- do.call(DEoptim.control, as.list(control))
   ctrl$npar <- length(lower)
@@ -93,7 +95,7 @@
   ctrl$trace <- as.numeric(ctrl$trace)
   ctrl$specinitialpop <- as.numeric(ctrl$specinitialpop)
 
-  outC <- .Call("DEoptim", lower, upper, fn1, ctrl, new.env(), PACKAGE = "RcppDE")
+  outC <- .Call("DEoptim", lower, upper, fn, ctrl, env, PACKAGE = "RcppDE")
   ##
   if (length(outC$storepop) > 0) {
     nstorepop <- floor((outC$iter - ctrl$storepopfrom) / ctrl$storepopfreq)

Modified: pkg/RcppDE/man/DEoptim.Rd
===================================================================
--- pkg/RcppDE/man/DEoptim.Rd	2010-11-04 18:44:47 UTC (rev 2394)
+++ pkg/RcppDE/man/DEoptim.Rd	2010-11-05 01:03:04 UTC (rev 2395)
@@ -6,7 +6,7 @@
   Performs evolutionary global optimization via the Differential Evolution algorithm.
 }
 \usage{
-DEoptim(fn, lower, upper, control = DEoptim.control(), ...)
+DEoptim(fn, lower, upper, control = DEoptim.control(), env, ...)
 }
 \arguments{
   \item{fn}{the function to be optimized (minimized). The function should have as its first 
@@ -16,6 +16,7 @@
     of \code{lower} and \code{upper} applied to the i-th parameter. The implementation searches
     between \code{lower} and \code{upper} for the global optimum (minimum) of \code{fn}.}
   \item{control}{a list of control parameters; see \code{\link{DEoptim.control}}.}
+  \item{env}{environment in which to evaluate \code{fn}; a new environment is created if missing.}
   \item{...}{further arguments to be passed to \code{fn}.}
 }
 \details{



More information about the Rcpp-commits mailing list