Learn R Programming

phenofit (version 0.2.0)

opt_FUN: Unified optimization function

Description

I_optimx is rich of functionality, but with a low computing performance. Some basic optimization functions are unified here, with some input and output format.

  • opt_ncminf General-Purpose Unconstrained Non-Linear Optimization, see ucminf.

  • opt_nlminb Optimization using PORT routines, see nlminb.

  • opt_nlm Non-Linear Minimization, nlm.

  • opt_optim General-purpose Optimization, see optim.

Usage

opt_ucminf(par0, objective, ...)

opt_nlminb(par0, objective, ...)

opt_nlm(par0, objective, ...)

opt_optim(par0, objective, method = "BFGS", ...)

Arguments

par0

Initial values for the parameters to be optimized over.

objective

A function to be minimized (or maximized), with first argument the vector of parameters over which minimization is to take place. It should return a scalar result.

...

other parameters passed to objective.

method

optimization method to be used in p_optim. See optim.

Value

convcode

An integer code. 0 indicates successful convergence. Various methods may or may not return sufficient information to allow all the codes to be specified. An incomplete list of codes includes

1

indicates that the iteration limit maxit had been reached.

20

indicates that the initial set of parameters is inadmissible, that is, that the function cannot be computed or returns an infinite, NULL, or NA value.

21

indicates that an intermediate set of parameters is inadmissible.

10

indicates degeneracy of the Nelder--Mead simplex.

51

indicates a warning from the "L-BFGS-B" method; see component message for further details.

52

indicates an error from the "L-BFGS-B" method; see component message for further details.

9999

error

value

The value of fn corresponding to par

par

The best parameter found

nitns

the number of iterations

fevals

The number of calls to objective.

See Also

optim_pheno, I_optim

Examples

Run this code
# NOT RUN {
library(phenofit)
library(ggplot2)
library(magrittr)
library(purrr)

# simulate vegetation time-series
fFUN = doubleLog.Beck
par = c(
  mn  = 0.1,
  mx  = 0.7,
  sos = 50,
  rsp = 0.1,
  eos = 250,
  rau = 0.1)
t    <- seq(1, 365, 8)
tout <- seq(1, 365, 1)
y <- fFUN(par, t)

# initial parameter
par0 <- c(
  mn  = 0.15,
  mx  = 0.65,
  sos = 100,
  rsp = 0.12,
  eos = 200,
  rau = 0.12)

objective <- f_goal # goal function
optFUNs   <- c("opt_ucminf", "opt_nlminb", "opt_nlm", "opt_optim") %>% set_names(., .)

opts <- lapply(optFUNs, function(optFUN){
    optFUN <- get(optFUN)
    opt <- optFUN(par0, objective, y = y, t = t, fun = fFUN)
    opt$ysim <- fFUN(opt$par, t)
    opt
})

# visualization
df   <- map(opts, "ysim") %>% as.data.frame() %>% cbind(t, y, .)
pdat <- reshape2::melt(df, c("t", "y"), variable.name = "optFUN")

ggplot(pdat) + 
    geom_point(data = data.frame(t, y), aes(t, y), size = 2) + 
    geom_line(aes(t, value, color = optFUN), size = 0.9)

# }

Run the code above in your browser using DataLab