Commit f46556ce authored by Florian Gerber's avatar Florian Gerber

v 7.2

parent 02465b94
Package: optimParallel
Type: Package
Title: Parallel Versions of the Gradient-Based optim() Methods
Version: 0.7-1
Date: 2018-04-30
Version: 0.7-2
Date: 2018-05-01
Author: Florian Gerber
Maintainer: Florian Gerber <florian.gerber@math.uzh.ch>
Description: provides a parallel versions of the gradient-based optim() methods. The main function of the package is optimParallel(), which has the same usage and output as optim(). Using optimParallel() can significantly reduce the optimization time.
Description: Provides parallel versions of the gradient-based optim() methods. The main function of the package is optimParallel(), which has the same usage and output as optim(). Using optimParallel() can significantly reduce the optimization time.
License: GPL (>= 2)
URL: https://git.math.uzh.ch/florian.gerber/optimParallel
BugReports: https://git.math.uzh.ch/florian.gerber/optimParallel
BugReports: https://git.math.uzh.ch/florian.gerber/optimParallel/issues
Depends: R (>= 3.1), stats, parallel
Suggests: R.rsp, roxygen2, spam, microbenchmark, testthat, ggplot2, numDeriv
VignetteBuilder: R.rsp
......
......@@ -43,11 +43,12 @@
#' @details \code{optimParallel} is a wrapper to \code{\link[stats]{optim}} and relies on the lexical scoping mechanism of R
#' and the R package \pkg{parallel} to evaluate \code{fn}
#' and its (approximate) gradient in parallel.\cr\cr
#' The default values of the argument \code{parallel} can be set via\cr\code{options("optimParallel.forward", "optimParallel.loginfo")}.
#' Some default values of the argument \code{parallel} can be set via\cr\code{options("optimParallel.forward", "optimParallel.loginfo")}.
#'
#' @references F. Gerber, R. Furrer (2018)
#' optimParallel: an R Package Providing Parallel Versions of the Gradient-Based Optimization Methods of optim().
#' Available as vignette and soon on arXiv.org with a citable URL.
#' ArXiv e-prints. URL http://arxiv.org/abs/1804.11058.
#' Also available as vignette of this package \code{vignette("optimParallel")}.
#'
#' @seealso
#' \code{\link[stats]{optim}},
......
......@@ -6,3 +6,8 @@ The package provides parallel versions of the gradient-based optim methods
optimParallel can significantly reduce the optimization time. For a p-parameter optimization based
on "L-BFGS-B", the speed increase is about factor 1+2p when no analytic gradient is specified and
1+2p processor cores are available.
See the ArXiv e-prints URL http://arxiv.org/abs/1804.11058
also available as package vignette.
R> vignette("optimParallel")
\ No newline at end of file
citHeader("To cite optimParallel in publications use:")
citEntry(entry = "Unpublished",
citEntry(entry = "article",
title = "optimParallel: an R Package Providing Parallel Versions of the Gradient-Based Optimization Methods of optim()",
author = personList(as.person("Florian Gerber"),
as.person("Reinhard Furrer")
),
journal = "",
journal = "ArXiv e-prints",
year = "2018",
volume = "",
number = "",
pages = "1--4",
url = "",
url = "http://arxiv.org/abs/1804.11058",
doi = "",
note = "Pre-print available as package vignette and (soon) on arXiv.org with a citable URL.",
textVersion =
paste("F. Gerber and R. Furrer (2018)",
"optimParallel: an R Package Providing Parallel Versions of the Gradient-Based Optimization Methods of optim(), package vignette.")
"optimParallel: an R Package Providing Parallel Versions of the Gradient-Based Optimization Methods of optim(). URL http://arxiv.org/abs/1804.11058")
)
......@@ -69,7 +69,7 @@ For a \eqn{p}-parameter optimization based on \code{"L-BFGS-B"}, the speed incre
\code{optimParallel} is a wrapper to \code{\link[stats]{optim}} and relies on the lexical scoping mechanism of R
and the R package \pkg{parallel} to evaluate \code{fn}
and its (approximate) gradient in parallel.\cr\cr
The default values of the argument \code{parallel} can be set via\cr\code{options("optimParallel.forward", "optimParallel.loginfo")}.
Some default values of the argument \code{parallel} can be set via\cr\code{options("optimParallel.forward", "optimParallel.loginfo")}.
}
\examples{
negll <- function(par, x, sleep=0, verbose=TRUE){
......@@ -127,7 +127,8 @@ setDefaultCluster(cl=NULL); stopCluster(cl) }
\references{
F. Gerber, R. Furrer (2018)
optimParallel: an R Package Providing Parallel Versions of the Gradient-Based Optimization Methods of optim().
Available as vignette and soon on arXiv.org with a citable URL.
ArXiv e-prints. URL http://arxiv.org/abs/1804.11058.
Also available as vignette of this package \code{vignette("optimParallel")}.
}
\seealso{
\code{\link[stats]{optim}},
......
rm(list=ls())
set.seed(11)
install.packages("optimParallel")
x <- rnorm(n=1000, mean=5, sd=2)
negll <- function(par, x) -sum(dnorm(x=x, mean=par[1], sd=par[2], log=TRUE))
o1 <- optim(par=c(1, 1), fn=negll, x=x, method="L-BFGS-B", lower=c(-Inf, 0.0001))
o1$par
install.packages("optimParallel")
library("optimParallel")
cl <- makeCluster(detectCores()); setDefaultCluster(cl=cl)
o2 <- optimParallel(par=c(1, 1), fn=negll, x=x, method="L-BFGS-B",
lower=c(-Inf, 0.0001))
identical(o1, o2)
o3 <- optimParallel(par=c(1, 1), fn=negll, x=x, method="L-BFGS-B",
lower=c(-Inf, 0.0001), parallel=list(loginfo=TRUE))
print(o3$loginfo[1:3,], digits=3)
## make fig
library(ggplot2); theme_set(theme_bw())
pdf("path.pdf", width = 8*.9*.9, height = 5*.8*.9)
grid <- expand.grid(par1=seq(.7, 7, length.out=100),
par2=seq(.7, 4, length.out=100),
z=NA)
for(i in 1:nrow(grid))
grid$z[i] <- negll(c(grid$par1[i], grid$par2[i]), x=x)
col <- alpha(colorRampPalette(c("gray"))(55), 1)
stroke <- 1.1
shape <- 1
ggplot(data=data.frame(o3$log), aes(x=par1, y=par2)) +
geom_contour(mapping=aes(x=par1, y=par2, z=z, color=..level..), data=grid,
bins=55) +
geom_vline(xintercept=data.frame(o3$log)[nrow(o3$log),"par1"], color="darkRed") +
geom_hline(yintercept=data.frame(o3$log)[nrow(o3$log),"par2"], color="darkRed") +
geom_segment(aes(xend=c(tail(par1, n=-1), NA), yend=c(tail(par2, n=-1), NA)),
arrow=arrow(length=unit(0.5,"cm"), type = "open", angle=30), size=.7,
color="darkBlue") +
geom_point(data=head(data.frame(o3$log),1), size =2, color="darkBlue")+
scale_color_gradientn(colours=col)+
scale_x_continuous(expand = c(0,0), limits=range(grid$par1)) +
scale_y_continuous(expand = c(0,0), limits=range(grid$par2)) +
xlab(expression(mu)) + ylab(expression(sigma))+
theme(legend.position="none",
panel.grid.major = element_blank(), panel.grid.minor = element_blank())
dev.off()
demo_generator <- function(fn, gr){
par_last <- value <- grad <- NA
eval <- function(par){
if(!identical(par, par_last)){
message("--> evaluate fn() and gr()")
par_last <<- par
value <<- fn(par)
grad <<- gr(par)
} else
message("--> read stored value")
}
f <- function(par){
eval(par=par)
value
}
g <- function(par){
eval(par=par)
grad
}
list(f=f, g=g)
}
demo <- demo_generator(fn=sum, gr=prod)
demo$f(1:5)
demo$g(1:5)
fn <- function(par, sleep){
Sys.sleep(sleep)
sum(par^2)
}
gr <- function(par, sleep){
Sys.sleep(sleep)
2*par
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment