Commit 73418e0e authored by Florian Gerber's avatar Florian Gerber
Browse files

v 1.0

parent 99af6a54
Package: optimParallel
Type: Package
Title: Parallel Version of the L-BFGS-B Optimization Method
Version: 0.8-1
Date: 2019-05-07
Version: 1.0
Date: 2020-02-24
Author: Florian Gerber
Maintainer: Florian Gerber <florian.gerber@math.uzh.ch>
Description: Provides a parallel version of the L-BFGS-B method of optim(). 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.
......@@ -12,4 +12,4 @@ BugReports: https://git.math.uzh.ch/florian.gerber/optimParallel/issues
Depends: R (>= 3.5), stats, parallel
Suggests: R.rsp, roxygen2, spam, microbenchmark, testthat, ggplot2, numDeriv, lbfgsb3, lbfgsb3c
VignetteBuilder: R.rsp
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
- version 0.8-1:
commit dfbf0197d2b1cd02b36fa7877cf5506127a52150
- version 1.0:
commit 373ce0334eb05a7c382bd95d086b83966ceb64e1
Author: Florian Gerber <florian.gerber@math.uzh.ch>
Date: Tue May 7 10:07:40 2019 -0600
(1) improve documentation
Date: Mon Feb 24 17:51:45 2020 -0700
(1) bug fix: hessian has now correct sign if 'fnscale=-1'
(2) Vignette and citation info updated
- version 0.8:
commit f0a8ed6e658cb481d549fd908d5640bf03abf394
......
......@@ -40,9 +40,9 @@
#' and its (approximate) gradient in parallel.\cr\cr
#' 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().
#' ArXiv e-prints. URL http://arxiv.org/abs/1804.11058.
#' @references F. Gerber, R. Furrer (2019)
#' optimParallel: An R package providing a parallel version of the L-BFGS-B optimization method.
#' The R Journal, 11(1):352-358, https://doi.org/10.32614/RJ-2019-030
#' Also available as vignette of this package \code{vignette("optimParallel")}.
#'
#' @section Notes:
......@@ -156,6 +156,8 @@ optimParallel <- function(par, fn, gr = NULL, ...,
out <- stats::optim(par=par, fn=fg$f, gr=fg$g, method = "L-BFGS-B", lower=lower,
upper=upper, control=control, hessian=hessian)
out$value <- out$value*fg$control$fnscale
if(hessian[1])
out$hessian <- out$hessian*fg$control$fnscale
if(fg$parallel$loginfo){
out[[length(out)+1]] <- fg$getLog()
names(out)[length(out)] <- "loginfo"
......
......@@ -7,7 +7,7 @@ optimParallel can significantly reduce the optimization time. For a p-parameter
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 for more information.
See the R Journal article https://doi.org/10.32614/RJ-2019-030 for more information.
It is also available as vignette.
R> vignette("optimParallel")
\ No newline at end of file
citHeader("To cite optimParallel in publications use:")
citEntry(entry = "article",
title = "optimParallel: an R Package Providing Parallel Versions of the Gradient-Based Optimization Methods of optim()",
title = "optimParallel: An R Package Providing a Parallel Version of the L-BFGS-B Optimization Method",
author = personList(as.person("Florian Gerber"),
as.person("Reinhard Furrer")
),
journal = "ArXiv e-prints",
year = "2018",
volume = "",
number = "",
pages = "1--4",
url = "http://arxiv.org/abs/1804.11058",
doi = "",
journal = "The R Journal",
year = "2019",
volume = "11",
number = "1",
pages = "352--358",
url = "https://doi.org/10.32614/RJ-2019-030",
doi = "10.32614/RJ-2019-030",
textVersion =
paste("F. Gerber and R. Furrer (2018)",
"optimParallel: an R Package Providing Parallel Versions of the Gradient-Based Optimization Methods of optim(). URL http://arxiv.org/abs/1804.11058")
paste("F. Gerber and R. Furrer (2019)",
"optimParallel: An R package providing a parallel version of the L-BFGS-B optimization method.
The R Journal, 11(1):352-358, 2019, https://doi.org/10.32614/RJ-2019-030")
)
......@@ -12,8 +12,17 @@
\alias{optimparallel-Package}
\title{parallel version of the L-BFGS-B method of \code{\link[stats]{optim}}}
\usage{
optimParallel(par, fn, gr = NULL, ..., lower = -Inf, upper = Inf,
control = list(), hessian = FALSE, parallel = list())
optimParallel(
par,
fn,
gr = NULL,
...,
lower = -Inf,
upper = Inf,
control = list(),
hessian = FALSE,
parallel = list()
)
}
\arguments{
\item{par}{see the documentation of \code{\link[stats]{optim}}.}
......@@ -100,7 +109,7 @@ an R script reproducing the issue and the output of \code{sessionInfo()}.
\examples{
negll <- function(par, x, sleep=0, verbose=TRUE){
if(verbose)
cat(par, "\\n")
cat(par, "\n")
Sys.sleep(sleep)
-sum(dnorm(x=x, mean=par[1], sd=par[2], log=TRUE))
}
......@@ -162,9 +171,9 @@ optimParallel(par=1, fn=fn, a=20, b=1)
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().
ArXiv e-prints. URL http://arxiv.org/abs/1804.11058.
F. Gerber, R. Furrer (2019)
optimParallel: An R package providing a parallel version of the L-BFGS-B optimization method.
The R Journal, 11(1):352-358, https://doi.org/10.32614/RJ-2019-030
Also available as vignette of this package \code{vignette("optimParallel")}.
}
\seealso{
......
......@@ -87,3 +87,19 @@ test_that("optimParallel - fn and gr can have different aguments",{
})
test_that("optimParallel return correct sign of hessian if 'fnscale=-1'", {
set.seed(13)
x <- rnorm(1000, 5, 2)
negll <- function(par, x) { -sum(dnorm(x=x, mean=par[1], sd=par[2], log=TRUE)) }
posll <- function(par, x) { sum(dnorm(x=x, mean=par[1], sd=par[2], log=TRUE)) }
compareOptim(list(par=c(1,1), fn=negll, x=x,
control=control, hessian=TRUE),
verbose=verbose)
compareOptim(list(par=c(1,1), fn=posll, x=x,
control=c(control, fnscale=-1), hessian=TRUE),
verbose=verbose)
})
rm(list=ls())
set.seed(11)
x <- rnorm(n = 1e7, mean = 5, sd = 2)
......@@ -7,8 +6,8 @@ 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")
#install.packages("optimParallel")
library(optimParallel)
cl <- makeCluster(detectCores()); setDefaultCluster(cl = cl)
o2 <- optimParallel(par = c(1, 1), fn = negll, x = x, lower = c(-Inf, 0.0001))
identical(o1, o2)
......@@ -75,7 +74,7 @@ tail(o6$loginfo, n = 3)
## benchmark example
library("microbenchmark")
library(microbenchmark)
measure <- function(expr, times=50, unit="s"){
m <- microbenchmark(list=expr, times=times)
summary(m, unit="s")["mean"]
......
Supports Markdown
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