optimParallel issueshttps://git.math.uzh.ch/florian.gerber/optimParallel/-/issues2018-07-30T04:34:04+02:00https://git.math.uzh.ch/florian.gerber/optimParallel/-/issues/3index `par` by names does not work2018-07-30T04:34:04+02:00Florian Gerberindex `par` by names does not workThanks to Marc for spotting the issue!
index `par` by names does not work.
set.seed(13); x <- rnorm(1000, 5, 2)
negll <- function(par, x){
-sum(dnorm(x=x, mean=par["mean"], sd=par["sd"], log=TRUE))
}
optim(par=c(mean=1, sd=1), fn=...Thanks to Marc for spotting the issue!
index `par` by names does not work.
set.seed(13); x <- rnorm(1000, 5, 2)
negll <- function(par, x){
-sum(dnorm(x=x, mean=par["mean"], sd=par["sd"], log=TRUE))
}
optim(par=c(mean=1, sd=1), fn=negll, x=x,
method = "L-BFGS-B", lower=c(-Inf, .0001))
The same code cannot be used in optim and optimParallel
library(optimParallel)
cl <- makeCluster(2) # set the number of processor cores
setDefaultCluster(cl=cl) # set 'cl' as default cluster
optimParallel(par=c(mean=1, sd=1), fn=negll, x=x,
method = "L-BFGS-B", lower=c(-Inf, .0001))
# ERRORhttps://git.math.uzh.ch/florian.gerber/optimParallel/-/issues/6hessian has wrong sign if `fnscale=-1`2020-02-21T01:30:38+01:00Florian Gerberhessian has wrong sign if `fnscale=-1`Thanks to Dan for the bug report.
When the user does two things simultaneously
1. changes from a minimization routine to a maximization routine via the argument control=list(fnscale=-1) and
2. requests a return of the hessian via the ...Thanks to Dan for the bug report.
When the user does two things simultaneously
1. changes from a minimization routine to a maximization routine via the argument control=list(fnscale=-1) and
2. requests a return of the hessian via the argument hessian=TRUE,
then `optimParallel()` **fails to flip the sign of the Hessian**.
```
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)) }
out_1 <- optim(par=c(1,1), fn=negll, x=x, method = "L-BFGS-B", lower=c(-Inf, .0001), hessian=T)
out_2 <- optim(par=c(1,1), fn=posll, x=x, method = "L-BFGS-B", lower=c(-Inf, .0001), hessian=T, control=list(fnscale=-1))
out_1$hessian
out_2$hessian
library("optimParallel")
cl <- makeCluster(5)
setDefaultCluster(cl=cl)
out_p1 <- optimParallel(par=c(1,1), fn=negll, x=x, method = "L-BFGS-B", lower=c(-Inf, .0001), hessian=T)
out_p2 <- optimParallel(par=c(1,1), fn=posll, x=x, method = "L-BFGS-B", lower=c(-Inf, .0001), hessian=T, control=list(fnscale=-1))
out_p1$hessian
out_p2$hessian
```https://git.math.uzh.ch/florian.gerber/optimParallel/-/issues/5dispatch to loaded packages2018-07-30T04:32:21+02:00Florian Gerberdispatch to loaded packagesThanks to Stefan for reporting.
library(Matrix)
library(optimParallel)
f = function(x) {
doesnt_work = crossprod(Diagonal(10));
return(sum((x - c(23, 42))**2))
}
cl = makeCluster(2, type='FORK');
setDefaultCluster(cl=cl)
clust...Thanks to Stefan for reporting.
library(Matrix)
library(optimParallel)
f = function(x) {
doesnt_work = crossprod(Diagonal(10));
return(sum((x - c(23, 42))**2))
}
cl = makeCluster(2, type='FORK');
setDefaultCluster(cl=cl)
clusterEvalQ(cl=cl, expr=library('Matrix'))
optimParallel(par=c(0,0), fn=f)
# Error in checkForRemoteErrors(val) :
# 2 nodes produced errors; first error: requires numeric/complex
# matrix/vector arguments`https://git.math.uzh.ch/florian.gerber/optimParallel/-/issues/4access functions from loaded packages using the PSOCK cluster type2018-07-30T04:33:16+02:00Florian Gerberaccess functions from loaded packages using the PSOCK cluster typeThanks to Stefan for reporting.
* improve help page
* add an argument to optimParallel() to load packages?Thanks to Stefan for reporting.
* improve help page
* add an argument to optimParallel() to load packages?