optim_DFP_NAPA: optim_DFP_NAPA

Description Usage Arguments Examples

View source: R/optim_DFP_NAPA.R

Description

optim_DFP_NAPA is a non-arbitrary precision implementation of DFP (Davidon-Fletcher-Powel) quasi-newton optimization algorithm

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
optim_DFP_NAPA(
  starts,
  func,
  tolerance = 10^-8,
  maxSteps = 100,
  lineSearchMaxSteps = 100,
  keepValues = FALSE,
  Memory = 100,
  outFile = NULL,
  ...
)

Arguments

starts

vector of starting values for the function parameters

func

function to optimize, first argument is a vector containing the parameters to be optimized over

tolerance

tolerance for determining stopping condition (how close to zero is considered small enough for the gradient). Note that smaller tolerance may require much larger maxSteps and lineSearchMaxSteps.

maxSteps

maximum number of iterations for the optimization algorithm

lineSearchMaxSteps

maximum number of iterations for each line search (occurs for every iteration of the optimization algorithm).

keepValues

if TRUE will return all visited values (up to the number specified by Memory) during the optimization, rather than only the final values.

Memory

maximum number of iterations to remember (default is 100)

outFile

if not NULL, name of file to save results to (will be overwritten at each iteration).

...

extra parameters passed on to func

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# (1D example, compared against stats::optim)
optim_DFP_NAPA(-15.253, func=function(x){(x-10)^2}, maxSteps = 10, tolerance = 10^-6)
optim(par = 15, fn = function(x){(x-10)^2}, hessian = TRUE,   method="BFGS")

# (1D example, compared against stats::optim)
fun <- function(par, xdat) {
 -1*prod(dpois(x = xdat, lambda = par))
}

xdat <- c(8,11)#rpois(n = 2, lambda = 10)
starts <- 10

optim_DFP_NAPA(starts, fun, xdat=xdat, tolerance=10^-9)
optim(par = starts, fn = fun, hessian = TRUE, method="BFGS", xdat=xdat)

# (2D example, compared against stats::optim)
fun2D <- function(par, xdat, ydat) {
  par <- exp(par)
  -1*(sum(dpois(x = xdat, lambda = par[1], log=TRUE))+sum(dpois(x = ydat, lambda = par[2], log=TRUE)))
}
    
xdat2D <- c(1,2,3)
ydat2D <- c(5,8,9)
starts2D <- log(c(5,7))

op1 <- optim_DFP_NAPA(starts2D, fun2D, xdat=xdat2D, ydat=ydat2D, tolerance=10^-7)
op2 <- optim(par = starts2D, fn = fun2D, hessian = TRUE, method="BFGS", xdat=xdat2D, ydat=ydat2D)

mrparker909/optimizeAPA documentation built on June 28, 2020, 3:57 p.m.