Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement future.apply in forecast.mdl_df #271

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Authors@R:
role = "ctb"),
person(given = "George",
family = "Athanasopoulos",
role = "ctb"),
person(given = "David",
family = "Holt",
role = "ctb"))
Description: Provides tools, helpers and data structures for
developing models and time series functions for 'fable' and extension
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
allowing unbalanced hierarchies to be reconciled.
* Produce unique names for unnamed features used with `features()` (#258).
* Documentation improvements
* Performance improvements
* Performance improvements, including using `future.apply()` to parallelize
`forecast()` when the `future` package is attached (#268).

## Breaking changes

Expand Down
37 changes: 31 additions & 6 deletions R/forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,38 @@ forecast.mdl_df <- function(object, new_data = NULL, h = NULL,
object <- bind_new_data(object, new_data)
}

# Evaluate forecasts
object <- dplyr::mutate_at(as_tibble(object), vars(!!!mdls),
forecast, object[["new_data"]],
h = h, point_forecast = point_forecast, ...,
key_data = key_data(object))
object <- tidyr::pivot_longer(object, !!mdls, names_to = ".model", values_to = ".mdl")

object <- tidyr::pivot_longer(object, !!mdls, names_to = ".model", values_to = ".fc")
# Evaluate forecasts
if(is_attached("package:future")){
require_package("future.apply")

object[[".fc"]] <- future.apply::future_mapply(
FUN = forecast,
object[[".mdl"]],
MoreArgs = list(
h = h,
point_forecast = point_forecast,
...,
key_data = key_data(object)
),
SIMPLIFY = FALSE,
future.globals = FALSE
)
}
else{
object[[".fc"]] <- mapply(
FUN = forecast,
object[[".mdl"]],
MoreArgs = list(
h = h,
point_forecast = point_forecast,
...,
key_data = key_data(object)
),
SIMPLIFY = FALSE
)
}

# Combine and re-construct fable
fbl_attr <- attributes(object$.fc[[1]])
Expand Down