Make Python version consistent with R

This commit is contained in:
Maxim Grishin 2019-09-29 23:24:38 +03:00 committed by Ben Letham
parent 05effe55ac
commit a3ae4715bb
2 changed files with 10 additions and 10 deletions

View file

@ -1264,8 +1264,8 @@ fit.prophet <- function(m, df, ...) {
iter = m$mcmc.samples
)
args <- utils::modifyList(args, list(...))
stan.fit <- do.call(rstan::sampling, args)
m$params <- rstan::extract(stan.fit)
m$stan.fit <- do.call(rstan::sampling, args)
m$params <- rstan::extract(m$stan.fit)
n.iteration <- length(m$params$k)
} else {
args <- list(
@ -1277,15 +1277,15 @@ fit.prophet <- function(m, df, ...) {
as_vector = FALSE
)
args <- utils::modifyList(args, list(...))
stan.fit <- do.call(rstan::optimizing, args)
if (stan.fit$return_code != 0) {
m$stan.fit <- do.call(rstan::optimizing, args)
if (m$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$stan.fit <- do.call(rstan::optimizing, args)
}
m$params <- stan.fit$par
m$params <- m$stan.fit$par
n.iteration <- 1
}

View file

@ -1131,17 +1131,17 @@ class Prophet(object):
)
args.update(kwargs)
try:
params = model.optimizing(**args)
self.stan_fit = model.optimizing(**args)
except RuntimeError:
# Fall back on Newton
logger.warning(
'Optimization terminated abnormally. Falling back to Newton.'
)
args['algorithm'] = 'Newton'
params = model.optimizing(**args)
self.stan_fit = model.optimizing(**args)
for par in params:
self.params[par] = params[par].reshape((1, -1))
for par in self.stan_fit:
self.params[par] = self.stan_fit[par].reshape((1, -1))
# If no changepoints were requested, replace delta with 0s
if len(self.changepoints) == 0: