mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-18 08:53:42 +00:00
Make Python version consistent with R
This commit is contained in:
parent
05effe55ac
commit
a3ae4715bb
2 changed files with 10 additions and 10 deletions
|
|
@ -1264,8 +1264,8 @@ fit.prophet <- function(m, df, ...) {
|
||||||
iter = m$mcmc.samples
|
iter = m$mcmc.samples
|
||||||
)
|
)
|
||||||
args <- utils::modifyList(args, list(...))
|
args <- utils::modifyList(args, list(...))
|
||||||
stan.fit <- do.call(rstan::sampling, args)
|
m$stan.fit <- do.call(rstan::sampling, args)
|
||||||
m$params <- rstan::extract(stan.fit)
|
m$params <- rstan::extract(m$stan.fit)
|
||||||
n.iteration <- length(m$params$k)
|
n.iteration <- length(m$params$k)
|
||||||
} else {
|
} else {
|
||||||
args <- list(
|
args <- list(
|
||||||
|
|
@ -1277,15 +1277,15 @@ fit.prophet <- function(m, df, ...) {
|
||||||
as_vector = FALSE
|
as_vector = FALSE
|
||||||
)
|
)
|
||||||
args <- utils::modifyList(args, list(...))
|
args <- utils::modifyList(args, list(...))
|
||||||
stan.fit <- do.call(rstan::optimizing, args)
|
m$stan.fit <- do.call(rstan::optimizing, args)
|
||||||
if (stan.fit$return_code != 0) {
|
if (m$stan.fit$return_code != 0) {
|
||||||
message(
|
message(
|
||||||
'Optimization terminated abnormally. Falling back to Newton optimizer.'
|
'Optimization terminated abnormally. Falling back to Newton optimizer.'
|
||||||
)
|
)
|
||||||
args$algorithm = 'Newton'
|
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
|
n.iteration <- 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1131,17 +1131,17 @@ class Prophet(object):
|
||||||
)
|
)
|
||||||
args.update(kwargs)
|
args.update(kwargs)
|
||||||
try:
|
try:
|
||||||
params = model.optimizing(**args)
|
self.stan_fit = model.optimizing(**args)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
# Fall back on Newton
|
# Fall back on Newton
|
||||||
logger.warning(
|
logger.warning(
|
||||||
'Optimization terminated abnormally. Falling back to Newton.'
|
'Optimization terminated abnormally. Falling back to Newton.'
|
||||||
)
|
)
|
||||||
args['algorithm'] = 'Newton'
|
args['algorithm'] = 'Newton'
|
||||||
params = model.optimizing(**args)
|
self.stan_fit = model.optimizing(**args)
|
||||||
|
|
||||||
for par in params:
|
for par in self.stan_fit:
|
||||||
self.params[par] = params[par].reshape((1, -1))
|
self.params[par] = self.stan_fit[par].reshape((1, -1))
|
||||||
|
|
||||||
# If no changepoints were requested, replace delta with 0s
|
# If no changepoints were requested, replace delta with 0s
|
||||||
if len(self.changepoints) == 0:
|
if len(self.changepoints) == 0:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue