Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 36aa106

Browse files
committedJan 29, 2025
Updated interface and function names
1 parent 4fd36be commit 36aa106

14 files changed

+43
-43
lines changed
 

‎NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ export(createBCFModelFromJsonString)
2525
export(createCppJson)
2626
export(createCppJsonFile)
2727
export(createCppJsonString)
28+
export(createCppRNG)
2829
export(createForest)
29-
export(createForestContainer)
3030
export(createForestCovariates)
3131
export(createForestCovariatesFromMetadata)
3232
export(createForestDataset)
3333
export(createForestModel)
34+
export(createForestSamples)
3435
export(createOutcome)
3536
export(createPreprocessorFromJson)
3637
export(createPreprocessorFromJsonString)
37-
export(createRNG)
3838
export(createRandomEffectSamples)
3939
export(createRandomEffectsDataset)
4040
export(createRandomEffectsModel)

‎R/bart.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ bart <- function(X_train, y_train, leaf_basis_train = NULL, rfx_group_ids_train
536536

537537
# Random number generator (std::mt19937)
538538
if (is.null(random_seed)) random_seed = sample(1:10000,1,F)
539-
rng <- createRNG(random_seed)
539+
rng <- createCppRNG(random_seed)
540540

541541
# Sampling data structures
542542
feature_types <- as.integer(feature_types)
@@ -549,11 +549,11 @@ bart <- function(X_train, y_train, leaf_basis_train = NULL, rfx_group_ids_train
549549

550550
# Container of forest samples
551551
if (include_mean_forest) {
552-
forest_samples_mean <- createForestContainer(num_trees_mean, output_dimension, is_leaf_constant, FALSE)
552+
forest_samples_mean <- createForestSamples(num_trees_mean, output_dimension, is_leaf_constant, FALSE)
553553
active_forest_mean <- createForest(num_trees_mean, output_dimension, is_leaf_constant, FALSE)
554554
}
555555
if (include_variance_forest) {
556-
forest_samples_variance <- createForestContainer(num_trees_variance, 1, TRUE, TRUE)
556+
forest_samples_variance <- createForestSamples(num_trees_variance, 1, TRUE, TRUE)
557557
active_forest_variance <- createForest(num_trees_variance, 1, TRUE, TRUE)
558558
}
559559

‎R/bcf.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ bcf <- function(X_train, Z_train, y_train, propensity_train = NULL, rfx_group_id
760760

761761
# Random number generator (std::mt19937)
762762
if (is.null(random_seed)) random_seed = sample(1:10000,1,F)
763-
rng <- createRNG(random_seed)
763+
rng <- createCppRNG(random_seed)
764764

765765
# Sampling data structures
766766
forest_model_mu <- createForestModel(forest_dataset_train, feature_types, num_trees_mu, nrow(X_train), alpha_mu, beta_mu, min_samples_leaf_mu, max_depth_mu)
@@ -770,12 +770,12 @@ bcf <- function(X_train, Z_train, y_train, propensity_train = NULL, rfx_group_id
770770
}
771771

772772
# Container of forest samples
773-
forest_samples_mu <- createForestContainer(num_trees_mu, 1, T)
774-
forest_samples_tau <- createForestContainer(num_trees_tau, 1, F)
773+
forest_samples_mu <- createForestSamples(num_trees_mu, 1, T)
774+
forest_samples_tau <- createForestSamples(num_trees_tau, 1, F)
775775
active_forest_mu <- createForest(num_trees_mu, 1, T)
776776
active_forest_tau <- createForest(num_trees_tau, 1, F)
777777
if (include_variance_forest) {
778-
forest_samples_variance <- createForestContainer(num_trees_variance, 1, TRUE, TRUE)
778+
forest_samples_variance <- createForestSamples(num_trees_variance, 1, TRUE, TRUE)
779779
active_forest_variance <- createForest(num_trees_variance, 1, TRUE, TRUE)
780780
}
781781

‎R/calibration.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' X <- matrix(runif(n*p), ncol = p)
1919
#' y <- 10*X[,1] - 20*X[,2] + rnorm(n)
2020
#' nu <- 3
21-
#' lambda <- calibrate_inverse_gamma_error_variance(y, X, nu = nu)
21+
#' lambda <- calibrateInverseGammaErrorVariance(y, X, nu = nu)
2222
#' sigma2hat <- mean(resid(lm(y~X))^2)
2323
#' mean(var(y)/rgamma(100000, nu, rate = nu*lambda) < sigma2hat)
2424
calibrateInverseGammaErrorVariance <- function(y, X, W = NULL, nu = 3, quant = 0.9, standardize = TRUE) {

‎R/forest.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ Forest <- R6::R6Class(
758758
#'
759759
#' @return `ForestSamples` object
760760
#' @export
761-
createForestContainer <- function(num_trees, output_dimension=1, is_leaf_constant=F, is_exponentiated=F) {
761+
createForestSamples <- function(num_trees, output_dimension=1, is_leaf_constant=F, is_exponentiated=F) {
762762
return(invisible((
763763
ForestSamples$new(num_trees, output_dimension, is_leaf_constant, is_exponentiated)
764764
)))

‎R/model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ ForestModel <- R6::R6Class(
170170
#'
171171
#' @return `CppRng` object
172172
#' @export
173-
createRNG <- function(random_seed = -1){
173+
createCppRNG <- function(random_seed = -1){
174174
return(invisible((
175175
CppRNG$new(random_seed)
176176
)))

‎_pkgdown.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ reference:
8888
- ForestModel
8989
- createForestModel
9090
- ForestSamples
91-
- createForestContainer
91+
- createForestSamples
9292
- CppRNG
93-
- createRNG
93+
- createCppRNG
9494
- calibrateInverseGammaErrorVariance
9595
- preprocessParams
9696
- computeMaxLeafIndex

‎man/calibrateInverseGammaErrorVariance.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/createRNG.Rd renamed to ‎man/createCppRNG.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/createForestContainer.Rd renamed to ‎man/createForestSamples.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/R/testthat/test-predict.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_that("Prediction from trees with constant leaf", {
1111
n <- nrow(X)
1212
p <- ncol(X)
1313
forest_dataset = createForestDataset(X)
14-
forest_samples <- createForestContainer(num_trees, 1, T)
14+
forest_samples <- createForestSamples(num_trees, 1, T)
1515

1616
# Initialize a forest with constant root predictions
1717
forest_samples$add_forest_with_constant_leaves(0.)
@@ -65,7 +65,7 @@ test_that("Prediction from trees with univariate leaf basis", {
6565
n <- nrow(X)
6666
p <- ncol(X)
6767
forest_dataset = createForestDataset(X,W)
68-
forest_samples <- createForestContainer(num_trees, 1, F)
68+
forest_samples <- createForestSamples(num_trees, 1, F)
6969

7070
# Initialize a forest with constant root predictions
7171
forest_samples$add_forest_with_constant_leaves(0.)
@@ -123,7 +123,7 @@ test_that("Prediction from trees with multivariate leaf basis", {
123123
p <- ncol(X)
124124
W = matrix(c(1,1,1,1,1,1,-1,-1,-1,1,1,1), byrow=F, nrow=6)
125125
forest_dataset = createForestDataset(X,W)
126-
forest_samples <- createForestContainer(num_trees, output_dim, F)
126+
forest_samples <- createForestSamples(num_trees, output_dim, F)
127127

128128
# Initialize a forest with constant root predictions
129129
forest_samples$add_forest_with_constant_leaves(c(1.,1.))

‎test/R/testthat/test-residual.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ test_that("Residual updates correctly propagated after forest sampling step", {
3333
b_forest = 0
3434

3535
# RNG
36-
cpp_rng = createRNG(-1)
36+
cpp_rng = createCppRNG(-1)
3737

3838
# Create forest sampler and forest container
3939
forest_model = createForestModel(forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf, max_depth)
40-
forest_samples = createForestContainer(num_trees, 1, F)
40+
forest_samples = createForestSamples(num_trees, 1, F)
4141
active_forest = createForest(num_trees, 1, F)
4242

4343
# Initialize the leaves of each tree in the prognostic forest

‎vignettes/CustomSamplingRoutine.Rmd

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ if (leaf_regression) {
128128
outcome <- createOutcome(resid)
129129
130130
# Random number generator (std::mt19937)
131-
rng <- createRNG()
131+
rng <- createCppRNG()
132132
133133
# Sampling data structures
134134
forest_model <- createForestModel(forest_dataset, feature_types,
@@ -139,10 +139,10 @@ forest_model <- createForestModel(forest_dataset, feature_types,
139139
# container of forest samples (which is written to when
140140
# a sample is not discarded due to burn-in / thinning)
141141
if (leaf_regression) {
142-
forest_samples <- createForestContainer(num_trees, 1, F)
142+
forest_samples <- createForestSamples(num_trees, 1, F)
143143
active_forest <- createForest(num_trees, 1, F)
144144
} else {
145-
forest_samples <- createForestContainer(num_trees, 1, T)
145+
forest_samples <- createForestSamples(num_trees, 1, T)
146146
active_forest <- createForest(num_trees, 1, T)
147147
}
148148
```
@@ -317,7 +317,7 @@ if (leaf_regression) {
317317
outcome <- createOutcome(resid)
318318
319319
# Random number generator (std::mt19937)
320-
rng <- createRNG()
320+
rng <- createCppRNG()
321321
322322
# Sampling data structures
323323
forest_model <- createForestModel(forest_dataset, feature_types,
@@ -328,10 +328,10 @@ forest_model <- createForestModel(forest_dataset, feature_types,
328328
# container of forest samples (which is written to when
329329
# a sample is not discarded due to burn-in / thinning)
330330
if (leaf_regression) {
331-
forest_samples <- createForestContainer(num_trees, 1, F)
331+
forest_samples <- createForestSamples(num_trees, 1, F)
332332
active_forest <- createForest(num_trees, 1, F)
333333
} else {
334-
forest_samples <- createForestContainer(num_trees, 1, T)
334+
forest_samples <- createForestSamples(num_trees, 1, T)
335335
active_forest <- createForest(num_trees, 1, T)
336336
}
337337
@@ -552,7 +552,7 @@ if (leaf_regression) {
552552
outcome <- createOutcome(resid)
553553
554554
# Random number generator (std::mt19937)
555-
rng <- createRNG()
555+
rng <- createCppRNG()
556556
557557
# Sampling data structures
558558
forest_model <- createForestModel(forest_dataset, feature_types,
@@ -563,10 +563,10 @@ forest_model <- createForestModel(forest_dataset, feature_types,
563563
# container of forest samples (which is written to when
564564
# a sample is not discarded due to burn-in / thinning)
565565
if (leaf_regression) {
566-
forest_samples <- createForestContainer(num_trees, 1, F)
566+
forest_samples <- createForestSamples(num_trees, 1, F)
567567
active_forest <- createForest(num_trees, 1, F)
568568
} else {
569-
forest_samples <- createForestContainer(num_trees, 1, T)
569+
forest_samples <- createForestSamples(num_trees, 1, T)
570570
active_forest <- createForest(num_trees, 1, T)
571571
}
572572
@@ -786,7 +786,7 @@ if (leaf_regression) {
786786
outcome <- createOutcome(resid)
787787
788788
# Random number generator (std::mt19937)
789-
rng <- createRNG()
789+
rng <- createCppRNG()
790790
791791
# Sampling data structures
792792
forest_model <- createForestModel(forest_dataset, feature_types,
@@ -797,10 +797,10 @@ forest_model <- createForestModel(forest_dataset, feature_types,
797797
# container of forest samples (which is written to when
798798
# a sample is not discarded due to burn-in / thinning)
799799
if (leaf_regression) {
800-
forest_samples <- createForestContainer(num_trees, 1, F)
800+
forest_samples <- createForestSamples(num_trees, 1, F)
801801
active_forest <- createForest(num_trees, 1, F)
802802
} else {
803-
forest_samples <- createForestContainer(num_trees, 1, T)
803+
forest_samples <- createForestSamples(num_trees, 1, T)
804804
active_forest <- createForest(num_trees, 1, T)
805805
}
806806
```
@@ -1132,7 +1132,7 @@ forest_dataset_tau <- createForestDataset(X_tau, tau_basis)
11321132
outcome <- createOutcome(resid)
11331133
11341134
# Random number generator (std::mt19937)
1135-
rng <- createRNG()
1135+
rng <- createCppRNG()
11361136
11371137
# Sampling data structures
11381138
forest_model_mu <- createForestModel(
@@ -1145,9 +1145,9 @@ forest_model_tau <- createForestModel(
11451145
)
11461146
11471147
# Container of forest samples
1148-
forest_samples_mu <- createForestContainer(num_trees_mu, 1, T)
1148+
forest_samples_mu <- createForestSamples(num_trees_mu, 1, T)
11491149
active_forest_mu <- createForest(num_trees_mu, 1, T)
1150-
forest_samples_tau <- createForestContainer(num_trees_tau, 1, F)
1150+
forest_samples_tau <- createForestSamples(num_trees_tau, 1, F)
11511151
active_forest_tau <- createForest(num_trees_tau, 1, F)
11521152
11531153
# Initialize the leaves of each tree in the prognostic forest

‎vignettes/PriorCalibration.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ In this case, $\nu$ is set by default to 3 and $\lambda$ is calibrated as follow
4949
1. An "overestimate," $\hat{\sigma}^2$, of $\sigma^2$ is obtained via simple linear regression of $y$ on $X$
5050
2. $\lambda$ is chosen to ensure that $p(\sigma^2 < \hat{\sigma}^2) = q$ for some value $q$, typically set to a default value of 0.9.
5151

52-
This is done in `stochtree` via the `calibrate_inverse_gamma_error_variance` function.
52+
This is done in `stochtree` via the `calibrateInverseGammaErrorVariance` function.
5353

5454
```{r}
5555
# Load library
@@ -81,7 +81,7 @@ y_train <- y[train_inds]
8181
8282
# Calibrate the scale parameter for the variance term as in Chipman et al (2010)
8383
nu <- 3
84-
lambda <- calibrate_inverse_gamma_error_variance(y_train, X_train, nu = nu)
84+
lambda <- calibrateInverseGammaErrorVariance(y_train, X_train, nu = nu)
8585
```
8686

8787
Now we run a BART model with this variance parameterization

0 commit comments

Comments
 (0)
Please sign in to comment.