Skip to content

Commit d7f1f69

Browse files
committed
New optimisation routine for gum()
1 parent 84c8738 commit d7f1f69

File tree

2 files changed

+82
-51
lines changed

2 files changed

+82
-51
lines changed

R/adam-gum.R

+69-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,18 @@ utils::globalVariables(c("xregData","xregModel","xregNumber","initialXregEstimat
6666
#' @param model A previously estimated GUM model, if provided, the function
6767
#' will not estimate anything and will use all its parameters.
6868
#' @param ... Other non-documented parameters. See \link[smooth]{adam} for
69-
#' details
69+
#' details. However, there are several unique parameters passed to the optimiser
70+
#' in comparison with \code{adam}:
71+
#' 1. \code{algorithm0}, which defines what algorithm to use in nloptr for the initial
72+
#' optimisation. By default, this is "NLOPT_LN_BOBYQA".
73+
#' 2. \code{algorithm} determines the second optimiser. By default this is
74+
#' "NLOPT_LN_NELDERMEAD".
75+
#' 3. maxeval0 and maxeval, that determine the number of iterations for the two
76+
#' optimisers. By default, \code{maxeval0=1000}, \code{maxeval=40*k}, where
77+
#' k is the number of estimated parameters.
78+
#' 4. xtol_rel0 and xtol_rel, which are 1e-8 and 1e-6 respectively.
79+
#' There are also ftol_rel0, ftol_rel, ftol_abs0 and ftol_abs, which by default
80+
#' are set to values explained in the \code{nloptr.print.options()} function.
7081
#'
7182
#' @return Object of class "adam" is returned with similar elements to the
7283
#' \link[smooth]{adam} function.
@@ -232,6 +243,50 @@ gum <- function(data, orders=c(1,1), lags=c(1,frequency(data)), type=c("additive
232243
regressors=regressors, yName=yName,
233244
silent, modelDo, ParentEnvironment=environment(), ellipsis, fast=FALSE);
234245

246+
# Values for the preliminary optimiser
247+
if(is.null(ellipsis$algorithm0)){
248+
algorithm0 <- "NLOPT_LN_BOBYQA";
249+
}
250+
else{
251+
algorithm0 <- ellipsis$algorithm0;
252+
}
253+
if(is.null(ellipsis$maxeval0)){
254+
maxeval0 <- 1000;
255+
}
256+
else{
257+
maxeval0 <- ellipsis$maxeval0;
258+
}
259+
if(is.null(ellipsis$maxtime0)){
260+
maxtime0 <- -1;
261+
}
262+
else{
263+
maxtime0 <- ellipsis$maxtime0;
264+
}
265+
if(is.null(ellipsis$xtol_rel0)){
266+
xtol_rel0 <- 1e-8;
267+
}
268+
else{
269+
xtol_rel0 <- ellipsis$xtol_rel0;
270+
}
271+
if(is.null(ellipsis$xtol_abs0)){
272+
xtol_abs0 <- 0;
273+
}
274+
else{
275+
xtol_abs0 <- ellipsis$xtol_abs0;
276+
}
277+
if(is.null(ellipsis$ftol_rel0)){
278+
ftol_rel0 <- 0;
279+
}
280+
else{
281+
ftol_rel0 <- ellipsis$ftol_rel0;
282+
}
283+
if(is.null(ellipsis$ftol_abs0)){
284+
ftol_abs0 <- 0;
285+
}
286+
else{
287+
ftol_abs0 <- ellipsis$ftol_abs0;
288+
}
289+
235290
# Check whether the multiplicative model is applicable
236291
if(type=="multiplicative"){
237292
if(any(yInSample<=0)){
@@ -604,6 +659,19 @@ gum <- function(data, orders=c(1,1), lags=c(1,frequency(data)), type=c("additive
604659
}
605660
}
606661

662+
# First run of BOBYQA to get better values of B
663+
res <- nloptr(B, CF, opts=list(algorithm=algorithm0, xtol_rel=xtol_rel0, xtol_abs=xtol_abs0,
664+
ftol_rel=ftol_rel0, ftol_abs=ftol_abs0,
665+
maxeval=maxeval0, maxtime=maxtime0, print_level=print_level),
666+
matVt=matVt, matF=matF, vecG=vecG, matWt=matWt);
667+
668+
if(print_level_hidden>0){
669+
print(res);
670+
}
671+
672+
B[] <- res$solution;
673+
674+
# Tuning the best obtained values using Nelder-Mead
607675
res <- suppressWarnings(nloptr(B, CF,
608676
opts=list(algorithm=algorithm, xtol_rel=xtol_rel, xtol_abs=xtol_abs,
609677
ftol_rel=ftol_rel, ftol_abs=ftol_abs,

man/gum.Rd

+13-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)