Skip to content

Commit

Permalink
remove remaining un-needed dependencies (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjclark committed Nov 14, 2024
1 parent 26e3ba2 commit 0220dea
Show file tree
Hide file tree
Showing 59 changed files with 264 additions and 335 deletions.
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: Multivariate (Dynamic) Generalized Additive Models
Version: 1.1.4
Date: 2024-09-05
Authors@R: person("Nicholas J", "Clark", , "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7131-3301"))
Description: Fit Bayesian Dynamic Generalized Additive Models to sets of time series. Users can build dynamic nonlinear State-Space models that can incorporate semiparametric effects in observation and process components, using a wide range of observation families. Estimation is performed using Markov Chain Monte Carlo with Hamiltonian Monte Carlo in the software 'Stan'. References: Clark & Wells (2022) <doi:10.1111/2041-210X.13974>.
Description: Fit Bayesian Dynamic Generalized Additive Models to multivariate observations. Users can build nonlinear State-Space models that can incorporate semiparametric effects in observation and process components, using a wide range of observation families. Estimation is performed using Markov Chain Monte Carlo with Hamiltonian Monte Carlo in the software 'Stan'. References: Clark & Wells (2022) <doi:10.1111/2041-210X.13974>.
URL: https://github.com/nicholasjclark/mvgam, https://nicholasjclark.github.io/mvgam/
BugReports: https://github.com/nicholasjclark/mvgam/issues
License: MIT + file LICENSE
Expand All @@ -23,10 +23,8 @@ Imports:
bayesplot (>= 1.5.0),
ggplot2 (>= 2.0.0),
parallel,
pbapply,
mvnfast,
purrr,
zoo,
dplyr,
magrittr,
rlang
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Added a `fevd.mvgam()` method to compute forecast error variance decompositions from models fit with Vector Autoregressive dynamics (#21 and #76)

## Bug fixes
* Not necessarily a "bug fix", but this update removes several dependencies to lighten installation and improve efficiency of the workflow (#93)
* Fixed a minor bug in the way `trend_map` recognises levels of the `series` factor
* Bug fix to ensure `lfo_cv` recognises the actual times in `time`, just in case the user supplies data that doesn't start at `t = 1`. Also updated documentation to better reflect this
* Bug fix to ensure `update.mvgam` captures any `knots` or `trend_knots` arguments that were passed to the original model call
Expand Down
30 changes: 16 additions & 14 deletions R/evaluate_mvgams.R
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ roll_eval_mvgam = function(object,
validate_pos_integer(fc_horizon)

# Generate time variable from training data
if(class(object$obs_data)[1] == 'list'){
all_timepoints <- (data.frame(time = object$obs_data$time) %>%
if(inherits(object$obs_data, 'list')){
all_timepoints <- (data.frame(time = object$obs_data$index..time..index) %>%
dplyr::select(time) %>%
dplyr::distinct() %>%
dplyr::arrange(time) %>%
Expand All @@ -350,9 +350,9 @@ roll_eval_mvgam = function(object,

} else {
all_timepoints <- (object$obs_data %>%
dplyr::select(time) %>%
dplyr::select(index..time..index) %>%
dplyr::distinct() %>%
dplyr::arrange(time) %>%
dplyr::arrange(index..time..index) %>%
dplyr::mutate(time = dplyr::row_number())) %>%
dplyr::pull(time)
}
Expand Down Expand Up @@ -393,14 +393,17 @@ roll_eval_mvgam = function(object,
clusterEvalQ(cl, library(mgcv))
clusterEvalQ(cl, library(rstan))
clusterEvalQ(cl, library(dplyr))
clusterExport(cl = cl,
unclass(lsf.str(envir = asNamespace("mvgam"),
all = T)),
envir = as.environment(asNamespace("mvgam"))
)

pbapply::pboptions(type = "none")
evals <- pbapply::pblapply(evaluation_seq, function(timepoint){

# Grab internal functions to export to each worker
funs_list <- c('eval_mvgam')
attr(funs_list, 'envir') <- as.environment(asNamespace("mvgam"))
attr(funs_list, 'mode') <- 'function'

parallel::clusterExport(cl = cl,
funs_list,
envir = as.environment(asNamespace("mvgam")))

evals <- parallel::parLapply(cl = cl, evaluation_seq, function(timepoint){
eval_mvgam(object = object,
n_samples = n_samples,
n_cores = 1,
Expand All @@ -409,8 +412,7 @@ roll_eval_mvgam = function(object,
score = score,
log = log,
weights = weights)
},
cl = cl)
})
stopCluster(cl)

# Take sum of score at each evaluation point for multivariate models
Expand Down
19 changes: 13 additions & 6 deletions R/forecast.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -858,14 +858,21 @@ forecast_draws = function(object,
'obs_uncertainty',
'time_dis'),
envir = environment())

# Grab internal functions to export to each worker
funs_list <- c('extract_general_trend_pars',
'linkfun',
'forecast_trend',
'extract_series_trend_pars',
'mvgam_predict')
attr(funs_list, 'envir') <- as.environment(asNamespace("mvgam"))
attr(funs_list, 'mode') <- 'function'

parallel::clusterExport(cl = cl,
unclass(lsf.str(envir = asNamespace("mvgam"),
all = T)),
funs_list,
envir = as.environment(asNamespace("mvgam")))

pbapply::pboptions(type = "none")

fc_preds <- pbapply::pblapply(seq_len(dim(betas)[1]), function(i){
fc_preds <- parallel::parLapply(cl = cl, seq_len(dim(betas)[1]), function(i){
# Sample index
samp_index <- i

Expand Down Expand Up @@ -1023,7 +1030,7 @@ forecast_draws = function(object,
})
}
out
}, cl = cl)
})
stopCluster(cl)
}

Expand Down
3 changes: 2 additions & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified docs/reference/Rplot001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/Rplot013.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0220dea

Please sign in to comment.