Skip to content

Attempting to reduce runtime of several code examples #141

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

Merged
merged 1 commit into from
Feb 6, 2025
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: stochtree
Title: Stochastic tree Ensembles (XBART and BART) for Supervised Learning and Causal Inference
Title: Stochastic Tree Ensembles (XBART and BART) for Supervised Learning and Causal Inference
Version: 0.1.0
Authors@R:
c(
Expand Down
32 changes: 21 additions & 11 deletions R/bart.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train, X_test = X_test)
#' bart_model <- bart(X_train = X_train, y_train = y_train, X_test = X_test,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' plot(rowMeans(bart_model$y_hat_test), y_test, xlab = "predicted", ylab = "actual")
#' abline(0,1,col="red",lty=3,lwd=3)
bart <- function(X_train, y_train, leaf_basis_train = NULL, rfx_group_ids_train = NULL,
Expand Down Expand Up @@ -990,7 +991,8 @@ bart <- function(X_train, y_train, leaf_basis_train = NULL, rfx_group_ids_train
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' y_hat_test <- predict(bart_model, X_test)$y_hat
#' plot(rowMeans(y_hat_test), y_test, xlab = "predicted", ylab = "actual")
#' abline(0,1,col="red",lty=3,lwd=3)
Expand Down Expand Up @@ -1150,7 +1152,7 @@ predict.bartmodel <- function(object, X, leaf_basis = NULL, rfx_group_ids = NULL
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_train = rfx_basis_train,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100)
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' rfx_samples <- getRandomEffectSamples(bart_model)
getRandomEffectSamples.bartmodel <- function(object, ...){
result = list()
Expand Down Expand Up @@ -1200,7 +1202,8 @@ getRandomEffectSamples.bartmodel <- function(object, ...){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' bart_json <- saveBARTModelToJson(bart_model)
saveBARTModelToJson <- function(object){
jsonobj <- createCppJson()
Expand Down Expand Up @@ -1309,7 +1312,8 @@ saveBARTModelToJson <- function(object){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' tmpjson <- tempfile(fileext = ".json")
#' saveBARTModelToJsonFile(bart_model, file.path(tmpjson))
#' unlink(tmpjson)
Expand Down Expand Up @@ -1348,7 +1352,8 @@ saveBARTModelToJsonFile <- function(object, filename){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' bart_json_string <- saveBARTModelToJsonString(bart_model)
saveBARTModelToJsonString <- function(object){
# Convert to Json
Expand Down Expand Up @@ -1387,7 +1392,8 @@ saveBARTModelToJsonString <- function(object){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' bart_json <- saveBARTModelToJson(bart_model)
#' bart_model_roundtrip <- createBARTModelFromJson(bart_json)
createBARTModelFromJson <- function(json_object){
Expand Down Expand Up @@ -1501,7 +1507,8 @@ createBARTModelFromJson <- function(json_object){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' tmpjson <- tempfile(fileext = ".json")
#' saveBARTModelToJsonFile(bart_model, file.path(tmpjson))
#' bart_model_roundtrip <- createBARTModelFromJsonFile(file.path(tmpjson))
Expand Down Expand Up @@ -1545,7 +1552,8 @@ createBARTModelFromJsonFile <- function(json_filename){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' bart_json <- saveBARTModelToJsonString(bart_model)
#' bart_model_roundtrip <- createBARTModelFromJsonString(bart_json)
#' y_hat_mean_roundtrip <- rowMeans(predict(bart_model_roundtrip, X_train)$y_hat)
Expand Down Expand Up @@ -1590,7 +1598,8 @@ createBARTModelFromJsonString <- function(json_string){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' bart_json <- list(saveBARTModelToJson(bart_model))
#' bart_model_roundtrip <- createBARTModelFromCombinedJson(bart_json)
createBARTModelFromCombinedJson <- function(json_object_list){
Expand Down Expand Up @@ -1735,7 +1744,8 @@ createBARTModelFromCombinedJson <- function(json_object_list){
#' X_train <- X[train_inds,]
#' y_test <- y[test_inds]
#' y_train <- y[train_inds]
#' bart_model <- bart(X_train = X_train, y_train = y_train)
#' bart_model <- bart(X_train = X_train, y_train = y_train,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' bart_json_string_list <- list(saveBARTModelToJsonString(bart_model))
#' bart_model_roundtrip <- createBARTModelFromCombinedJsonString(bart_json_string_list)
createBARTModelFromCombinedJsonString <- function(json_string_list){
Expand Down
24 changes: 13 additions & 11 deletions R/bcf.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
#' tau_train <- tau_x[train_inds]
#' bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train,
#' propensity_train = pi_train, X_test = X_test, Z_test = Z_test,
#' propensity_test = pi_test)
#' propensity_test = pi_test, num_gfr = 10,
#' num_burnin = 0, num_mcmc = 10)
#' plot(rowMeans(bcf_model$mu_hat_test), mu_test, xlab = "predicted",
#' ylab = "actual", main = "Prognostic function")
#' abline(0,1,col="red",lty=3,lwd=3)
Expand Down Expand Up @@ -1438,7 +1439,8 @@ bcf <- function(X_train, Z_train, y_train, propensity_train = NULL, rfx_group_id
#' tau_test <- tau_x[test_inds]
#' tau_train <- tau_x[train_inds]
#' bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train,
#' propensity_train = pi_train)
#' propensity_train = pi_train, num_gfr = 10,
#' num_burnin = 0, num_mcmc = 10)
#' preds <- predict(bcf_model, X_test, Z_test, pi_test)
#' plot(rowMeans(preds$mu_hat), mu_test, xlab = "predicted",
#' ylab = "actual", main = "Prognostic function")
Expand Down Expand Up @@ -1632,7 +1634,7 @@ predict.bcfmodel <- function(object, X, Z, propensity = NULL, rfx_group_ids = NU
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10,
#' mu_forest_params = mu_params,
#' tau_forest_params = tau_params)
#' rfx_samples <- getRandomEffectSamples(bcf_model)
Expand Down Expand Up @@ -1723,7 +1725,7 @@ getRandomEffectSamples.bcfmodel <- function(object, ...){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10,
#' mu_forest_params = mu_params,
#' tau_forest_params = tau_params)
#' # bcf_json <- saveBCFModelToJson(bcf_model)
Expand Down Expand Up @@ -1888,7 +1890,7 @@ saveBCFModelToJson <- function(object){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10,
#' mu_forest_params = mu_params,
#' tau_forest_params = tau_params)
#' # saveBCFModelToJsonFile(bcf_model, "test.json")
Expand Down Expand Up @@ -1966,7 +1968,7 @@ saveBCFModelToJsonFile <- function(object, filename){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10,
#' mu_forest_params = mu_params,
#' tau_forest_params = tau_params)
#' # saveBCFModelToJsonString(bcf_model)
Expand Down Expand Up @@ -2046,7 +2048,7 @@ saveBCFModelToJsonString <- function(object){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10,
#' mu_forest_params = mu_params,
#' tau_forest_params = tau_params)
#' bcf_json <- saveBCFModelToJson(bcf_model)
Expand Down Expand Up @@ -2211,7 +2213,7 @@ createBCFModelFromJson <- function(json_object){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10,
#' mu_forest_params = mu_params,
#' tau_forest_params = tau_params)
#' # saveBCFModelToJsonFile(bcf_model, "test.json")
Expand Down Expand Up @@ -2292,7 +2294,7 @@ createBCFModelFromJsonFile <- function(json_filename){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100)
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' # bcf_json <- saveBCFModelToJsonString(bcf_model)
#' # bcf_model_roundtrip <- createBCFModelFromJsonString(bcf_json)
createBCFModelFromJsonString <- function(json_string){
Expand Down Expand Up @@ -2372,7 +2374,7 @@ createBCFModelFromJsonString <- function(json_string){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100)
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' # bcf_json_list <- list(saveBCFModelToJson(bcf_model))
#' # bcf_model_roundtrip <- createBCFModelFromCombinedJson(bcf_json_list)
createBCFModelFromCombinedJson <- function(json_object_list){
Expand Down Expand Up @@ -2584,7 +2586,7 @@ createBCFModelFromCombinedJson <- function(json_object_list){
#' Z_test = Z_test, propensity_test = pi_test,
#' rfx_group_ids_test = rfx_group_ids_test,
#' rfx_basis_test = rfx_basis_test,
#' num_gfr = 100, num_burnin = 0, num_mcmc = 100)
#' num_gfr = 10, num_burnin = 0, num_mcmc = 10)
#' # bcf_json_string_list <- list(saveBCFModelToJsonString(bcf_model))
#' # bcf_model_roundtrip <- createBCFModelFromCombinedJsonString(bcf_json_string_list)
createBCFModelFromCombinedJsonString <- function(json_string_list){
Expand Down
5 changes: 3 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## R CMD check results

0 errors | 0 warnings | 2 notes
0 errors | 0 warnings | 3 notes

* This is a new release.
* checking installed package size ... NOTE installed size is 46.3Mb (linux-only)
* Checking installed package size ... NOTE installed size is 46.3Mb (linux-only)
* Possibly misspelled words in DESCRIPTION: All of the words are proper nouns or technical terms (BCF, Carvalho, Chipman, McCulloch, XBART)
Loading