opt_nlminb_julia: Optimization using PORT routines

Description Usage Arguments Value See Also Examples

View source: R/opt_nlminb.R

Description

Unconstrained and box-constrained optimization using PORT routines.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
opt_nlminb_julia(
  par0,
  fitMeth = "doubleLog_Beck",
  y,
  t,
  w = NULL,
  ylu = NULL,
  lower = NULL,
  upper = NULL,
  ...
)

Arguments

par0

Initial values for the parameters to be optimized over.

fitMeth

Curve fitting methods, one of c("doubleLog_Beck", "doubleLog_Elmore", "doubleLog_AG", "doubleLog_Zhang")

y

Numeric vector, vegetation index time-series

t

Numeric vector, Date variable

w

(optional) Numeric vector, weights of y. If not specified, weights of all NA values will be wmin, the others will be 1.0.

ylu

ymin, ymax, which is used to force ypred in the range of ylu.

lower

vectors of lower and upper bounds, replicated to be as long as start. If unspecified, all parameters are assumed to be unconstrained.

upper

vectors of lower and upper bounds, replicated to be as long as start. If unspecified, all parameters are assumed to be unconstrained.

...

ignored parameters

Value

A list object of

See Also

stats::nlminb()

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
28
29
30
31
32
33
## Not run: 

t    = seq(1.0, 366, 8)
fun  = doubleLog_Beck
par  = c(0.1 , 0.7, 50, 0.1, 250, 0.1)
par0 = c(0.05, 0.6 , 45, 0.1, 200, 0.2)

ypred = t*0
y     = fun(par, t)

julia_init()
r_julia  <- opt_nlminb_julia(par0, "doubleLog_Beck", y, t)
r_R <- opt_nlminb(par0, f_goal, fun = fun, y = y, t = t, pred = ypred)

list(julia = r_julia, R = r_R) %>%
    map(~c(.$par, .$objective, .$value)) %>%
    do.call(rbind, .)# %>%

n <- length(t)
w <- rep(0.2, n)
# julia is 5 times faster
{
    # microbenchmark::microbenchmark : 18.939826 ms in R
    info <- rbenchmark::benchmark(
        r1 <- opt_nlminb_julia(par0, "doubleLog_Beck", y, t, w),
        r2 <- opt_nlminb(par0, f_goal, fun = fun, y = y, t = t, pred = ypred),
        replications = 500
    )
    print(info)
}


## End(Not run)

phenofit documentation built on April 2, 2020, 5:07 p.m.