mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-16 08:38:30 +00:00
Disabling calculation of uncertainties if uncertainty.samples is not True
This commit is contained in:
parent
eb797eefaa
commit
c95eb0dcd9
1 changed files with 18 additions and 8 deletions
|
|
@ -62,7 +62,8 @@ globalVariables(c(
|
||||||
#' If mcmc.samples>0, this will be integrated over all model parameters,
|
#' If mcmc.samples>0, this will be integrated over all model parameters,
|
||||||
#' which will include uncertainty in seasonality.
|
#' which will include uncertainty in seasonality.
|
||||||
#' @param uncertainty.samples Number of simulated draws used to estimate
|
#' @param uncertainty.samples Number of simulated draws used to estimate
|
||||||
#' uncertainty intervals.
|
#' uncertainty intervals. Settings this value to 0 or False will disable
|
||||||
|
#' uncertainty estimation and speed up the calculation.
|
||||||
#' @param fit Boolean, if FALSE the model is initialized but not fit.
|
#' @param fit Boolean, if FALSE the model is initialized but not fit.
|
||||||
#' @param ... Additional arguments, passed to \code{\link{fit.prophet}}
|
#' @param ... Additional arguments, passed to \code{\link{fit.prophet}}
|
||||||
#'
|
#'
|
||||||
|
|
@ -1343,6 +1344,11 @@ predict.prophet <- function(object, df = NULL, ...) {
|
||||||
df$trend <- predict_trend(object, df)
|
df$trend <- predict_trend(object, df)
|
||||||
seasonal.components <- predict_seasonal_components(object, df)
|
seasonal.components <- predict_seasonal_components(object, df)
|
||||||
intervals <- predict_uncertainty(object, df)
|
intervals <- predict_uncertainty(object, df)
|
||||||
|
if uncertainty.samples{
|
||||||
|
intervals <- predict_uncertainty(object, df)
|
||||||
|
} else {
|
||||||
|
intervals <- NULL
|
||||||
|
}
|
||||||
|
|
||||||
# Drop columns except ds, cap, floor, and trend
|
# Drop columns except ds, cap, floor, and trend
|
||||||
cols <- c('ds', 'trend')
|
cols <- c('ds', 'trend')
|
||||||
|
|
@ -1453,8 +1459,10 @@ predict_seasonal_components <- function(m, df) {
|
||||||
m <- out$m
|
m <- out$m
|
||||||
seasonal.features <- out$seasonal.features
|
seasonal.features <- out$seasonal.features
|
||||||
component.cols <- out$component.cols
|
component.cols <- out$component.cols
|
||||||
lower.p <- (1 - m$interval.width)/2
|
if uncertainty.samples{
|
||||||
upper.p <- (1 + m$interval.width)/2
|
lower.p <- (1 - m$interval.width)/2
|
||||||
|
upper.p <- (1 + m$interval.width)/2
|
||||||
|
}
|
||||||
|
|
||||||
X <- as.matrix(seasonal.features)
|
X <- as.matrix(seasonal.features)
|
||||||
component.predictions <- data.frame(matrix(ncol = 0, nrow = nrow(X)))
|
component.predictions <- data.frame(matrix(ncol = 0, nrow = nrow(X)))
|
||||||
|
|
@ -1466,10 +1474,12 @@ predict_seasonal_components <- function(m, df) {
|
||||||
comp <- comp * m$y.scale
|
comp <- comp * m$y.scale
|
||||||
}
|
}
|
||||||
component.predictions[[component]] <- rowMeans(comp, na.rm = TRUE)
|
component.predictions[[component]] <- rowMeans(comp, na.rm = TRUE)
|
||||||
component.predictions[[paste0(component, '_lower')]] <- apply(
|
if (uncertainty.samples){
|
||||||
comp, 1, stats::quantile, lower.p, na.rm = TRUE)
|
component.predictions[[paste0(component, '_lower')]] <- apply(
|
||||||
component.predictions[[paste0(component, '_upper')]] <- apply(
|
comp, 1, stats::quantile, lower.p, na.rm = TRUE)
|
||||||
comp, 1, stats::quantile, upper.p, na.rm = TRUE)
|
component.predictions[[paste0(component, '_upper')]] <- apply(
|
||||||
|
comp, 1, stats::quantile, upper.p, na.rm = TRUE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(component.predictions)
|
return(component.predictions)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue