Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • O optimParallel
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3
    • Issues 3
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Florian Gerber
  • optimParallel
  • Issues
  • #6
Closed
Open
Created Jun 17, 2019 by Florian Gerber@florian.gerberOwner

hessian 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 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
Assignee
Assign to
Time tracking