mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-17 08:40:56 +00:00
R fallback to Newton if non-zero return code from optimization, to match existing Py behavior (#654)
This commit is contained in:
parent
7297d98764
commit
ec7689f03e
2 changed files with 10 additions and 1 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue