From 088aa1497e0b9a12bb3fa01387675ed95abf700f Mon Sep 17 00:00:00 2001 From: Drew Herren Date: Sat, 8 Feb 2025 00:14:22 -0600 Subject: [PATCH 1/2] Fixed R examples with uninitialized random effects terms (which triggered valgrind errors in CRAN checks) --- DESCRIPTION | 3 +- R/random_effects.R | 52 +++++++++++++++++++++++----- man/resetRandomEffectsModel.Rd | 12 +++++++ man/resetRandomEffectsTracker.Rd | 12 +++++++ man/rootResetRandomEffectsModel.Rd | 14 +++++--- man/rootResetRandomEffectsTracker.Rd | 14 +++++--- man/stochtree-package.Rd | 4 ++- 7 files changed, 93 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 842a0a19..94084553 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,5 +49,6 @@ SystemRequirements: C++17 Imports: R6, stats -URL: https://stochtree.ai +URL: https://stochtree.ai/, https://github.com/StochasticTree/stochtree +BugReports: https://github.com/StochasticTree/stochtree/issues Config/testthat/edition: 3 diff --git a/R/random_effects.R b/R/random_effects.R index f9d0b70c..e4199155 100644 --- a/R/random_effects.R +++ b/R/random_effects.R @@ -416,6 +416,18 @@ createRandomEffectsModel <- function(num_components, num_groups) { #' rfx_model <- createRandomEffectsModel(num_components, num_groups) #' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) #' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +#' alpha_init <- rep(1,num_components) +#' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) +#' sigma_alpha_init <- diag(1,num_components,num_components) +#' sigma_xi_init <- diag(1,num_components,num_components) +#' sigma_xi_shape <- 1 +#' sigma_xi_scale <- 1 +#' rfx_model$set_working_parameter(alpha_init) +#' rfx_model$set_group_parameters(xi_init) +#' rfx_model$set_working_parameter_cov(sigma_alpha_init) +#' rfx_model$set_group_parameter_cov(sigma_xi_init) +#' rfx_model$set_variance_prior_shape(sigma_xi_shape) +#' rfx_model$set_variance_prior_scale(sigma_xi_scale) #' for (i in 1:3) { #' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, #' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, @@ -458,6 +470,18 @@ resetRandomEffectsModel <- function(rfx_model, rfx_samples, sample_num, sigma_al #' rfx_model <- createRandomEffectsModel(num_components, num_groups) #' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) #' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +#' alpha_init <- rep(1,num_components) +#' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) +#' sigma_alpha_init <- diag(1,num_components,num_components) +#' sigma_xi_init <- diag(1,num_components,num_components) +#' sigma_xi_shape <- 1 +#' sigma_xi_scale <- 1 +#' rfx_model$set_working_parameter(alpha_init) +#' rfx_model$set_group_parameters(xi_init) +#' rfx_model$set_working_parameter_cov(sigma_alpha_init) +#' rfx_model$set_group_parameter_cov(sigma_xi_init) +#' rfx_model$set_variance_prior_shape(sigma_xi_shape) +#' rfx_model$set_variance_prior_scale(sigma_xi_scale) #' for (i in 1:3) { #' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, #' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, @@ -493,15 +517,21 @@ resetRandomEffectsTracker <- function(rfx_tracker, rfx_model, rfx_dataset, resid #' rng <- createCppRNG(1234) #' num_groups <- length(unique(rfx_group_ids)) #' num_components <- ncol(rfx_basis) -#' alpha_init <- c(1) +#' rfx_model <- createRandomEffectsModel(num_components, num_groups) +#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) +#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +#' alpha_init <- rep(1,num_components) #' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) #' sigma_alpha_init <- diag(1,num_components,num_components) #' sigma_xi_init <- diag(1,num_components,num_components) #' sigma_xi_shape <- 1 #' sigma_xi_scale <- 1 -#' rfx_model <- createRandomEffectsModel(num_components, num_groups) -#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) -#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +#' rfx_model$set_working_parameter(alpha_init) +#' rfx_model$set_group_parameters(xi_init) +#' rfx_model$set_working_parameter_cov(sigma_alpha_init) +#' rfx_model$set_group_parameter_cov(sigma_xi_init) +#' rfx_model$set_variance_prior_shape(sigma_xi_shape) +#' rfx_model$set_variance_prior_scale(sigma_xi_scale) #' for (i in 1:3) { #' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, #' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, @@ -540,15 +570,21 @@ rootResetRandomEffectsModel <- function(rfx_model, alpha_init, xi_init, sigma_al #' rng <- createCppRNG(1234) #' num_groups <- length(unique(rfx_group_ids)) #' num_components <- ncol(rfx_basis) -#' alpha_init <- c(1) +#' rfx_model <- createRandomEffectsModel(num_components, num_groups) +#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) +#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +#' alpha_init <- rep(1,num_components) #' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) #' sigma_alpha_init <- diag(1,num_components,num_components) #' sigma_xi_init <- diag(1,num_components,num_components) #' sigma_xi_shape <- 1 #' sigma_xi_scale <- 1 -#' rfx_model <- createRandomEffectsModel(num_components, num_groups) -#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) -#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +#' rfx_model$set_working_parameter(alpha_init) +#' rfx_model$set_group_parameters(xi_init) +#' rfx_model$set_working_parameter_cov(sigma_alpha_init) +#' rfx_model$set_group_parameter_cov(sigma_xi_init) +#' rfx_model$set_variance_prior_shape(sigma_xi_shape) +#' rfx_model$set_variance_prior_scale(sigma_xi_scale) #' for (i in 1:3) { #' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, #' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, diff --git a/man/resetRandomEffectsModel.Rd b/man/resetRandomEffectsModel.Rd index 47afb38b..fec99b77 100644 --- a/man/resetRandomEffectsModel.Rd +++ b/man/resetRandomEffectsModel.Rd @@ -36,6 +36,18 @@ num_components <- ncol(rfx_basis) rfx_model <- createRandomEffectsModel(num_components, num_groups) rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +alpha_init <- rep(1,num_components) +xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) +sigma_alpha_init <- diag(1,num_components,num_components) +sigma_xi_init <- diag(1,num_components,num_components) +sigma_xi_shape <- 1 +sigma_xi_scale <- 1 +rfx_model$set_working_parameter(alpha_init) +rfx_model$set_group_parameters(xi_init) +rfx_model$set_working_parameter_cov(sigma_alpha_init) +rfx_model$set_group_parameter_cov(sigma_xi_init) +rfx_model$set_variance_prior_shape(sigma_xi_shape) +rfx_model$set_variance_prior_scale(sigma_xi_scale) for (i in 1:3) { rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, diff --git a/man/resetRandomEffectsTracker.Rd b/man/resetRandomEffectsTracker.Rd index 743978e1..5249ca96 100644 --- a/man/resetRandomEffectsTracker.Rd +++ b/man/resetRandomEffectsTracker.Rd @@ -44,6 +44,18 @@ num_components <- ncol(rfx_basis) rfx_model <- createRandomEffectsModel(num_components, num_groups) rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +alpha_init <- rep(1,num_components) +xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) +sigma_alpha_init <- diag(1,num_components,num_components) +sigma_xi_init <- diag(1,num_components,num_components) +sigma_xi_shape <- 1 +sigma_xi_scale <- 1 +rfx_model$set_working_parameter(alpha_init) +rfx_model$set_group_parameters(xi_init) +rfx_model$set_working_parameter_cov(sigma_alpha_init) +rfx_model$set_group_parameter_cov(sigma_xi_init) +rfx_model$set_variance_prior_shape(sigma_xi_shape) +rfx_model$set_variance_prior_scale(sigma_xi_scale) for (i in 1:3) { rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, diff --git a/man/rootResetRandomEffectsModel.Rd b/man/rootResetRandomEffectsModel.Rd index 03043fa4..c58a09e9 100644 --- a/man/rootResetRandomEffectsModel.Rd +++ b/man/rootResetRandomEffectsModel.Rd @@ -47,15 +47,21 @@ outcome <- createOutcome(y_std) rng <- createCppRNG(1234) num_groups <- length(unique(rfx_group_ids)) num_components <- ncol(rfx_basis) -alpha_init <- c(1) +rfx_model <- createRandomEffectsModel(num_components, num_groups) +rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) +rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +alpha_init <- rep(1,num_components) xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) sigma_alpha_init <- diag(1,num_components,num_components) sigma_xi_init <- diag(1,num_components,num_components) sigma_xi_shape <- 1 sigma_xi_scale <- 1 -rfx_model <- createRandomEffectsModel(num_components, num_groups) -rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) -rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +rfx_model$set_working_parameter(alpha_init) +rfx_model$set_group_parameters(xi_init) +rfx_model$set_working_parameter_cov(sigma_alpha_init) +rfx_model$set_group_parameter_cov(sigma_xi_init) +rfx_model$set_variance_prior_shape(sigma_xi_shape) +rfx_model$set_variance_prior_scale(sigma_xi_scale) for (i in 1:3) { rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, diff --git a/man/rootResetRandomEffectsTracker.Rd b/man/rootResetRandomEffectsTracker.Rd index 82893d0e..8de2c514 100644 --- a/man/rootResetRandomEffectsTracker.Rd +++ b/man/rootResetRandomEffectsTracker.Rd @@ -33,15 +33,21 @@ outcome <- createOutcome(y_std) rng <- createCppRNG(1234) num_groups <- length(unique(rfx_group_ids)) num_components <- ncol(rfx_basis) -alpha_init <- c(1) +rfx_model <- createRandomEffectsModel(num_components, num_groups) +rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) +rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +alpha_init <- rep(1,num_components) xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups) sigma_alpha_init <- diag(1,num_components,num_components) sigma_xi_init <- diag(1,num_components,num_components) sigma_xi_shape <- 1 sigma_xi_scale <- 1 -rfx_model <- createRandomEffectsModel(num_components, num_groups) -rfx_tracker <- createRandomEffectsTracker(rfx_group_ids) -rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) +rfx_model$set_working_parameter(alpha_init) +rfx_model$set_group_parameters(xi_init) +rfx_model$set_working_parameter_cov(sigma_alpha_init) +rfx_model$set_group_parameter_cov(sigma_xi_init) +rfx_model$set_variance_prior_shape(sigma_xi_shape) +rfx_model$set_variance_prior_scale(sigma_xi_scale) for (i in 1:3) { rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome, rfx_tracker=rfx_tracker, rfx_samples=rfx_samples, diff --git a/man/stochtree-package.Rd b/man/stochtree-package.Rd index 47e1e917..1b2ceb6d 100644 --- a/man/stochtree-package.Rd +++ b/man/stochtree-package.Rd @@ -11,7 +11,9 @@ Flexible stochastic tree ensemble software. Robust implementations of Bayesian A \seealso{ Useful links: \itemize{ - \item \url{https://stochtree.ai} + \item \url{https://stochtree.ai/} + \item \url{https://github.com/StochasticTree/stochtree} + \item Report bugs at \url{https://github.com/StochasticTree/stochtree/issues} } } From c6c0b6be080733ae522dfca792c4141abca42357 Mon Sep 17 00:00:00 2001 From: Drew Herren Date: Sat, 8 Feb 2025 00:30:34 -0600 Subject: [PATCH 2/2] Updated CRAN comments --- cran-comments.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cran-comments.md b/cran-comments.md index ea263345..2ce42f9c 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -27,3 +27,20 @@ We have converted `T` and `F` to `TRUE` and `FALSE` in the R code. > Some code lines in examples are commented out. Please never do that. We no longer do this, and apologize for the oversight. + +## CRAN comments (20250207) + +Below we address issues raised by CRAN on Feb 7, 2025 + +### Valgrind + +A valgrind-instrumented version of R exposed memory issues in several examples +in the `stochtree` documentation. The specific issue is + +> Conditional jump or move depends on uninitialised value(s) + +The examples that triggered this were in fact working with Eigen matrices +with uninitialized values. + +This has been corrected and we have verified that running the `stochtree` +examples no longer produce this memcheck error.