From ec7689f03e243ef195b8bb714e8bbead225077a6 Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Mon, 6 May 2019 09:49:29 -0700 Subject: [PATCH] R fallback to Newton if non-zero return code from optimization, to match existing Py behavior (#654) --- R/R/prophet.R | 7 +++++++ python/fbprophet/forecaster.py | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/R/R/prophet.R b/R/R/prophet.R index 74ab976..fd971a9 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -1262,6 +1262,13 @@ fit.prophet <- function(m, df, ...) { ) args <- utils::modifyList(args, list(...)) stan.fit <- do.call(rstan::optimizing, args) + if (stan.fit$return_code != 0) { + message( + 'Optimization terminated abnormally. Falling back to Newton optimizer.' + ) + args$algorithm = 'Newton' + stan.fit <- do.call(rstan::optimizing, args) + } m$params <- stan.fit$par n.iteration <- 1 } diff --git a/python/fbprophet/forecaster.py b/python/fbprophet/forecaster.py index 11fdcda..ffb93de 100644 --- a/python/fbprophet/forecaster.py +++ b/python/fbprophet/forecaster.py @@ -1119,7 +1119,9 @@ class Prophet(object): params = model.optimizing(**args) except RuntimeError: # Fall back on Newton - logger.warning('Default optimization returns with an error. Falling back to Newton method.') + logger.warning( + 'Optimization terminated abnormally. Falling back to Newton.' + ) args['algorithm'] = 'Newton' params = model.optimizing(**args)