Skip to content

Commit dbd57b0

Browse files
committed
Removed Rsolnp/csolnp (not ready for primetime). Some fixes for crashes due to RTMB and NaN parameters
1 parent b5b0b5e commit dbd57b0

File tree

13 files changed

+57
-82
lines changed

13 files changed

+57
-82
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Maintainer: Alexios Galanos <alexios@4dscape.com>
77
Description: Unobserved components time series model using the linear innovations state space representation (single source of error) with choice of error distributions and option for dynamic variance. Methods for estimation using automatic differentiation, automatic model selection and ensembling, prediction, filtering, simulation and backtesting. Based on the model described in Hyndman et al (2012) <doi:10.1198/jasa.2011.tm09771>.
88
Depends: R (>= 4.1.0), Rcpp (>= 0.12.9), tsmethods (>= 1.0.0)
99
LinkingTo: Rcpp (>= 0.12.9), TMB, RcppEigen
10-
Imports: TMB (>= 1.7.20), methods, tsaux, tsdistributions, zoo, xts, copula, flextable, data.table, sandwich, nloptr, Rsolnp, RTMB, viridisLite, future, future.apply, progressr
10+
Imports: TMB (>= 1.7.20), methods, tsaux, tsdistributions, zoo, xts, copula, flextable, data.table, sandwich, nloptr, RTMB, viridisLite, future, future.apply, progressr
1111
Suggests:
1212
rmarkdown,
1313
tstests,

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ importFrom(RTMB,eigen)
6363
importFrom(RTMB,matrix)
6464
importFrom(Rcpp,evalCpp)
6565
importFrom(Rcpp,loadModule)
66-
importFrom(Rsolnp,csolnp)
6766
importFrom(TMB,MakeADFun)
6867
importFrom(copula,P2p)
6968
importFrom(copula,normalCopula)

NEWS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# tsissm 1.0.2
22

3-
* The SLSQP solver (from nloptr) sometimes will return NaN for the parameters. Added a stop
4-
clause else it may crash the process (due to RTMB eigen crashing).
5-
* Added option for solnp solver (csolnp from Rsolnp)
3+
* The SLSQP solver (from nloptr) sometimes will return NaN for the parameters during
4+
the optimization phase. Added a stop clause else it may crash the process (due
5+
to RTMB eigen crashing).
66
* Added a solver control function (issm_control)
77

88
# tsissm 1.0.1

R/backtest.R

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#' @param seed an value specifying if and how the random number generator should
2121
#' be initialized (\sQuote{seeded}). Either NULL or an integer that will be used in a
2222
#' call to set.seed before simulating the response vectors.
23-
#' @param solver either \dQuote{nlortr} or \dQuote{solnp}.
23+
#' @param solver only \dQuote{nlortr} currently supported.
24+
#' @param control optional control parameters.
2425
#' @param trace whether to show the progress bar. The user is expected to have
2526
#' set up appropriate handlers for this using the \dQuote{progressr} package.
2627
#' @param ... not used.
@@ -57,8 +58,12 @@
5758
#'
5859
tsbacktest.tsissm.autospec <- function(object, start = floor(length(object$y)/2), end = length(object$y),
5960
h = 1, estimate_every = 1, rolling = FALSE, weights_scheme = c("AIC","BIC","U"), weights = NULL,
60-
seed = NULL, solver = "nloptr", trace = FALSE, ...)
61+
seed = NULL, solver = "nloptr", control = NULL, trace = FALSE, ...)
6162
{
63+
solver <- "nloptr"
64+
if (is.null(control)) {
65+
control <- issm_control(solver = "nloptr", algorithm = "SLSQP", trace = 0)
66+
}
6267
if (object$top_n > 1) {
6368
top_n <- object$top_n
6469
weights_scheme <- match.arg(weights_scheme[1], c("AIC","BIC","U"))
@@ -68,10 +73,10 @@ tsbacktest.tsissm.autospec <- function(object, start = floor(length(object$y)/2)
6873
weights_scheme <- "U"
6974
}
7075
out <- .backtest_ensemble(object, start = start, end = end, h = h, estimate_every = estimate_every, rolling = rolling, weights_scheme = weights_scheme,
71-
weights = weights, seed = seed, solver = solver, trace = trace)
76+
weights = weights, seed = seed, solver = solver, control = control, trace = trace)
7277
} else {
7378
out <- .backtest_top(object, start = start, end = end, h = h, estimate_every = estimate_every, rolling = rolling, seed = seed, solver = solver,
74-
trace = trace)
79+
control = control, trace = trace)
7580
}
7681
return(out)
7782
}
@@ -80,8 +85,12 @@ tsbacktest.tsissm.autospec <- function(object, start = floor(length(object$y)/2)
8085
#' @rdname tsbacktest
8186
#' @export
8287
tsbacktest.tsissm.spec <- function(object, start = floor(length(object$target$y_orig)/2), end = length(object$target$y_orig),
83-
h = 1, estimate_every = 1, rolling = FALSE, seed = NULL, solver = "nloptr", trace = FALSE, ...)
88+
h = 1, estimate_every = 1, rolling = FALSE, seed = NULL, solver = "nloptr", control = NULL, trace = FALSE, ...)
8489
{
90+
solver <- "nloptr"
91+
if (is.null(control)) {
92+
control <- issm_control(solver = "nloptr", algorithm = "SLSQP", trace = 0)
93+
}
8594
parameter <- b <- forecast_dates <- NULL
8695
data <- xts(object$target$y_orig, object$target$index)
8796

@@ -152,7 +161,7 @@ tsbacktest.tsissm.spec <- function(object, start = floor(length(object$target$y_
152161
sampling = object$target$sampling, sample_n = object$variance$sample_n,
153162
init_garch = object$variance$init_variance, garch_order = object$variance$order,
154163
variance = object$variance$type, distribution = object$distribution$type)
155-
mod <- try(estimate(spec, solver = solver, scores = FALSE), silent = TRUE)
164+
mod <- try(estimate(spec, solver = solver, control = control, scores = FALSE), silent = TRUE)
156165
model_coef <- coef(mod)
157166
log_lik <- as.numeric(logLik(mod))
158167
aic <- as.numeric(AIC(mod))
@@ -242,7 +251,7 @@ tsbacktest.tsissm.spec <- function(object, start = floor(length(object$target$y_
242251
}
243252

244253
.backtest_top <- function(object, start = floor(length(object$y)/2), end = length(object$y), h = 1,
245-
estimate_every = 1, rolling = FALSE, seed = NULL, solver = "nloptr",
254+
estimate_every = 1, rolling = FALSE, seed = NULL, solver = "nloptr", control = NULL,
246255
trace = FALSE, ...)
247256
{
248257
parameter <- b <- forecast_dates <- NULL
@@ -305,7 +314,7 @@ tsbacktest.tsissm.spec <- function(object, start = floor(length(object$target$y_
305314
sampling = object$sampling, sample_n = object$sample_n,
306315
init_garch = object$init_garch, garch_order = object$garch_order,
307316
variance = object$variance, distribution = object$distribution, top_n = 1)
308-
mod <- try(estimate(spec, solver = solver, trace = FALSE), silent = TRUE)
317+
mod <- try(estimate(spec, solver = solver, control = control, trace = FALSE), silent = TRUE)
309318
model_coef <- coef(mod)
310319
log_lik <- as.numeric(logLik(mod))
311320
aic <- as.numeric(AIC(mod))
@@ -394,7 +403,7 @@ tsbacktest.tsissm.spec <- function(object, start = floor(length(object$target$y_
394403

395404
.backtest_ensemble <- function(object, start = floor(length(object$y)/2), end = length(object$y),
396405
h = 1, estimate_every = 1, rolling = FALSE, weights_scheme = c("U","AIC","BIC"), weights = NULL,
397-
seed = NULL, solver = "nloptr", trace = FALSE, ...)
406+
seed = NULL, solver = "nloptr", control = NULL, trace = FALSE, ...)
398407
{
399408
if (weights_scheme == "U") {
400409
wfun <- function(x) {
@@ -470,7 +479,7 @@ tsbacktest.tsissm.spec <- function(object, start = floor(length(object$target$y_
470479
sampling = object$sampling, sample_n = object$sample_n,
471480
init_garch = object$init_garch, garch_order = object$garch_order,
472481
variance = object$variance, distribution = object$distribution, top_n = top_n)
473-
mod <- try(estimate(spec, solver = solver, trace = FALSE), silent = TRUE)
482+
mod <- try(estimate(spec, solver = solver, control = control, trace = FALSE), silent = TRUE)
474483
w <- wfun(mod)
475484
L <- index_table[[i]]
476485
M <- split(L, by = "filter_date")

R/estimation.R

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' @description Estimates a model given a specification object using
44
#' maximum likelihood.
55
#' @param object an object of class \dQuote{tsissm.spec} or \dQuote{tsissm.autospec}.
6-
#' @param solver a choice or either \code{nloptr} or \code{solnp}.
6+
#' @param solver only \code{nloptr} currently supported.
77
#' @param control solver control parameters (see \code{\link{issm_control}}).
88
#' @param scores whether to calculate the analytic scores (Jacobian) of the
99
#' likelihood. This is not available for the \dQuote{tsissm.autospec} object.
@@ -90,13 +90,11 @@ estimate.tsissm.autospec <- function(object, solver = "nloptr", control = NULL,
9090
if (solver == "nloptr") {
9191
control <- issm_control(solver = "nloptr", algorithm = "SLSQP", trace = 0)
9292
} else {
93-
control <- issm_control(solver = "solnp", trace = 0)
93+
stop("\nonly nloptr supported")
9494
}
9595
} else {
9696
if (solver == "nloptr") {
9797
control$print_level <- 0
98-
} else {
99-
control$trace <- 0
10098
}
10199
}
102100
distribution <- object$distribution
@@ -698,13 +696,6 @@ tmb_inputs_issm_constant <- function(spec)
698696
lb = spec_list$lower, ub = spec_list$upper, opts = control, fun = fun, issmenv = issmenv)
699697
}
700698
pars <- sol$solution
701-
} else if (solver == "solnp") {
702-
cfun <- make_constraint_solnp(object, fun, issmenv)
703-
sol <- csolnp(pars = fun$par, fn = spec_list$llh_fun, gr = spec_list$grad_fun, ineq_fn = cfun$ineq_fn,
704-
ineq_jac = cfun$ineq_jac, ineq_lower = cfun$ineq_lower, ineq_upper = cfun$ineq_upper,
705-
lower = spec_list$lower, upper = spec_list$upper, control = control, fun = fun, issmenv = issmenv)
706-
sol$status <- sol$convergence
707-
pars <- sol$pars
708699
}
709700

710701
spec_list$data$xseed <- as.numeric(fun$env$data$xseed)
@@ -799,13 +790,6 @@ tmb_inputs_issm_constant <- function(spec)
799790
}
800791
spec_list$data$xseed <- as.numeric(fun$env$data$xseed)
801792
pars <- sol$solution
802-
} else if (solver == "solnp") {
803-
cfun <- make_constraint_solnp(object, fun, issmenv)
804-
sol <- csolnp(pars = fun$par, fn = spec_list$llh_fun, gr = spec_list$grad_fun, ineq_fn = cfun$ineq_fn,
805-
ineq_jac = cfun$ineq_jac, ineq_lower = cfun$ineq_lower, ineq_upper = cfun$ineq_upper,
806-
lower = spec_list$lower, upper = spec_list$upper, control = control, fun = fun, issmenv = issmenv)
807-
sol$status <- sol$convergence
808-
pars <- sol$pars
809793
}
810794

811795
if (return_scores) {

R/solvers.R

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
#' ISSM solver control parameters
22
#'
3-
#' @param solver choice of \sQuote{nloptr} and \sQuote{solnp}
3+
#' @param solver only \sQuote{nloptr} at present
44
#' @param algorithm (nloptr) the algorithm to use
55
#' @param trace (integer) controls print level information
66
#' @param xtol_rel (nloptr) relative tolerance on optimization parameters
77
#' @param maxeval (nloptr) number of function evaluations to stop on
88
#' @param xtol_abs (nloptr) absolute tolerances on optimization parameters
9-
#' @param max_iter (solnp) maximum number of major (outer) iterations
10-
#' @param min_iter (solnp) maximum number of minor (inner) iterations per outer iteration
11-
#' @param rho (solnp) onitial penalty parameter for the augmented Lagrangian
12-
#' @param tol (solnp) convergence tolerance
139
#' @details
14-
#' The function provides defaults for use when using either the \code{\link{nloptr}[nloptr]}
15-
#' or \code{\link{csolnp}[Rsolnp]}. For the
16-
#' former, additional control parameters may be appended to the list if the user so wishes
17-
#' (\sQuote{nloptr} has many more options).
18-
#' @returns a list with the options which is then passed to the appropriate solver.
10+
#' The function provides defaults for use, but additional control parameters may
11+
#' be appended to the list if the user so wishes (\sQuote{nloptr} has many more options).
12+
#' @returns a list with the options which is then passed to the solver.
1913
#' @rdname solver_control
2014
#' @export
2115
issm_control <- function(solver = "nloptr", algorithm = c("SLSQP","AUGLAG/MMA","AUGLAG/CCSAQ"),
22-
trace = 0, xtol_rel = 1e-14, maxeval = 1000, xtol_abs = 1e-12,
23-
rho = 1, max_iter = 400, min_iter = 800, tol = 1e-8)
16+
trace = 0, xtol_rel = 1e-14, maxeval = 1000, xtol_abs = 1e-12)
2417
{
25-
solver <- match.arg(solver[1], c("nloptr","solnp"))
18+
solver <- match.arg(solver[1], c("nloptr"))
2619
if (solver == "nloptr") {
2720
algorithm <- match.arg(algorithm[1], c("SLSQP","AUGLAG/MMA","AUGLAG/CCSAQ"))
2821
maxeval <- max(1, maxeval)
@@ -37,12 +30,5 @@ issm_control <- function(solver = "nloptr", algorithm = c("SLSQP","AUGLAG/MMA","
3730
local_opts = list(algorithm = "NLOPT_LD_CCSAQ", maxeval = maxeval, xtol_rel = xtol_rel))
3831
)
3932
return(ctrl)
40-
} else if (solver == "solnp") {
41-
max_iter <- max(1, max_iter)
42-
min_iter <- min(1, min_iter)
43-
trace <- max(0, trace)
44-
tol <- abs(tol)
45-
ctrl <- list(trace = trace, max_iter = max_iter, min_iter = min_iter, tol = tol)
46-
return(ctrl)
4733
}
4834
}

R/tsissm-package.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#' @importFrom zoo index as.zoo zoo coredata na.locf na.fill is.zoo
1313
#' @importFrom sandwich estfun bwNeweyWest vcovHAC vcovOPG bread
1414
#' @importFrom nloptr nloptr
15-
#' @importFrom Rsolnp csolnp
1615
#' @importFrom xts xts as.xts is.xts
1716
#' @importFrom flextable flextable as_flextable set_caption italic fontsize separate_header add_footer_row add_footer_lines append_chunks as_chunk as_equation as_paragraph compose colformat_double set_header_labels padding bold align autofit hline width
1817
#' @importFrom future.apply future_lapply

R/tsprofile.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#' @param nsim the number of paths to generate.
1717
#' @param seed an object specifying if and how the random number generator
1818
#' should be initialized. See the simulate documentation for more details.
19-
#' @param solver either \dQuote{nlortr} or \dQuote{solnp}.
20-
#' @param trace whether to show the progress bar and additionally output verbose messages.
19+
#' @param solver only \dQuote{nlortr} currently available.
20+
#' @param trace whether to show the progress bar and additionally output verbose messages.
21+
#' @param control optional control parameters.
2122
#' The user is expected to have set up appropriate handlers for this using
2223
#' the \code{\link[progressr]{handlers}} function from the \dQuote{progressr} package.
2324
#' @param ... not currently used.
@@ -32,12 +33,16 @@
3233
#' @rdname tsprofile
3334
#' @export
3435
#'
35-
tsprofile.tsissm.estimate <- function(object, h = 1, nsim = 100, seed = NULL, solver = "nloptr", trace = FALSE, ...)
36+
tsprofile.tsissm.estimate <- function(object, h = 1, nsim = 100, seed = NULL, solver = "nloptr", control = NULL, trace = FALSE, ...)
3637
{
38+
solver <- "nloptr"
39+
if (is.null(control)) {
40+
control <- issm_control(solver = "nloptr", algorithm = "SLSQP", trace = 0)
41+
}
3742
sim <- simulate(object, seed = seed, nsim = nsim, h = length(object$spec$target$y_orig) + h)
3843
sim <- .check_positivity(sim)
3944
if (is.null(sim)) return(sim)
40-
profile <- profile_fun(sim$distribution, object, h = h, solver = solver, control = NULL, trace = trace)
45+
profile <- profile_fun(sim$distribution, object, h = h, solver = solver, control = control, trace = trace)
4146
class(profile) <- "tsissm.profile"
4247
return(profile)
4348
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# tsissm <img src="man/figures/logo.png" align="right" height="139" alt="" />
33

44
[![R-CMD-check](https://github.com/tsmodels/tsissm/actions/workflows/rcmdcheck.yaml/badge.svg)](https://github.com/tsmodels/tsissm/actions/workflows/rcmdcheck.yaml)
5-
[![Last-changedate](https://img.shields.io/badge/last%20change-2025--07--05-yellowgreen.svg)](/commits/master)
5+
[![Last-changedate](https://img.shields.io/badge/last%20change-2025--07--12-yellowgreen.svg)](/commits/master)
66
[![packageversion](https://img.shields.io/badge/Package%20version-1.0.2-orange.svg?style=flat-square)](commits/master)
77
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/tsissm)](https://cran.r-project.org/package=tsissm)
88

man/estimate.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)