R fallback to Newton if non-zero return code from optimization, to match existing Py behavior (#654)

This commit is contained in:
Ben Letham 2019-05-06 09:49:29 -07:00
parent 7297d98764
commit ec7689f03e
2 changed files with 10 additions and 1 deletions

View file

@ -1262,6 +1262,13 @@ fit.prophet <- function(m, df, ...) {
) )
args <- utils::modifyList(args, list(...)) args <- utils::modifyList(args, list(...))
stan.fit <- do.call(rstan::optimizing, args) 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 m$params <- stan.fit$par
n.iteration <- 1 n.iteration <- 1
} }

View file

@ -1119,7 +1119,9 @@ class Prophet(object):
params = model.optimizing(**args) params = model.optimizing(**args)
except RuntimeError: except RuntimeError:
# Fall back on Newton # 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' args['algorithm'] = 'Newton'
params = model.optimizing(**args) params = model.optimizing(**args)