Skip to content

Commit b3347ce

Browse files
committed
Found and fixed other uses of shorthand T/F instead of TRUE/FALSE
1 parent d204848 commit b3347ce

File tree

12 files changed

+47
-47
lines changed

12 files changed

+47
-47
lines changed

R/bart.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ bart <- function(X_train, y_train, leaf_basis_train = NULL, rfx_group_ids_train
555555
outcome_train <- createOutcome(resid_train)
556556

557557
# Random number generator (std::mt19937)
558-
if (is.null(random_seed)) random_seed = sample(1:10000,1,F)
558+
if (is.null(random_seed)) random_seed = sample(1:10000,1,FALSE)
559559
rng <- createCppRNG(random_seed)
560560

561561
# Sampling data structures
@@ -632,7 +632,7 @@ bart <- function(X_train, y_train, leaf_basis_train = NULL, rfx_group_ids_train
632632
if (requires_basis) init_values_mean_forest <- rep(0., ncol(leaf_basis_train))
633633
else init_values_mean_forest <- 0.
634634
active_forest_mean$prepare_for_sampler(forest_dataset_train, outcome_train, forest_model_mean, leaf_model_mean_forest, init_values_mean_forest)
635-
active_forest_mean$adjust_residual(forest_dataset_train, outcome_train, forest_model_mean, requires_basis, F)
635+
active_forest_mean$adjust_residual(forest_dataset_train, outcome_train, forest_model_mean, requires_basis, FALSE)
636636
}
637637

638638
# Initialize the leaves of each tree in the variance forest
@@ -645,7 +645,7 @@ bart <- function(X_train, y_train, leaf_basis_train = NULL, rfx_group_ids_train
645645
if (num_gfr > 0){
646646
for (i in 1:num_gfr) {
647647
# Keep all GFR samples at this stage -- remove from ForestSamples after MCMC
648-
# keep_sample <- ifelse(keep_gfr, T, F)
648+
# keep_sample <- ifelse(keep_gfr, TRUE, FALSE)
649649
keep_sample <- TRUE
650650
if (keep_sample) sample_counter <- sample_counter + 1
651651
# Print progress

R/bcf.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ bcf <- function(X_train, Z_train, y_train, propensity_train = NULL, rfx_group_id
813813
outcome_train <- createOutcome(resid_train)
814814

815815
# Random number generator (std::mt19937)
816-
if (is.null(random_seed)) random_seed = sample(1:10000,1,F)
816+
if (is.null(random_seed)) random_seed = sample(1:10000,1,FALSE)
817817
rng <- createCppRNG(random_seed)
818818

819819
# Sampling data structures
@@ -840,10 +840,10 @@ bcf <- function(X_train, Z_train, y_train, propensity_train = NULL, rfx_group_id
840840
}
841841

842842
# Container of forest samples
843-
forest_samples_mu <- createForestSamples(num_trees_mu, 1, T)
844-
forest_samples_tau <- createForestSamples(num_trees_tau, 1, F)
845-
active_forest_mu <- createForest(num_trees_mu, 1, T)
846-
active_forest_tau <- createForest(num_trees_tau, 1, F)
843+
forest_samples_mu <- createForestSamples(num_trees_mu, 1, TRUE)
844+
forest_samples_tau <- createForestSamples(num_trees_tau, 1, FALSE)
845+
active_forest_mu <- createForest(num_trees_mu, 1, TRUE)
846+
active_forest_tau <- createForest(num_trees_tau, 1, FALSE)
847847
if (include_variance_forest) {
848848
forest_samples_variance <- createForestSamples(num_trees_variance, 1, TRUE, TRUE)
849849
active_forest_variance <- createForest(num_trees_variance, 1, TRUE, TRUE)
@@ -852,12 +852,12 @@ bcf <- function(X_train, Z_train, y_train, propensity_train = NULL, rfx_group_id
852852
# Initialize the leaves of each tree in the prognostic forest
853853
init_mu <- mean(resid_train)
854854
active_forest_mu$prepare_for_sampler(forest_dataset_train, outcome_train, forest_model_mu, 0, init_mu)
855-
active_forest_mu$adjust_residual(forest_dataset_train, outcome_train, forest_model_mu, F, F)
855+
active_forest_mu$adjust_residual(forest_dataset_train, outcome_train, forest_model_mu, FALSE, FALSE)
856856

857857
# Initialize the leaves of each tree in the treatment effect forest
858858
init_tau <- 0.
859859
active_forest_tau$prepare_for_sampler(forest_dataset_train, outcome_train, forest_model_tau, 1, init_tau)
860-
active_forest_tau$adjust_residual(forest_dataset_train, outcome_train, forest_model_tau, T, F)
860+
active_forest_tau$adjust_residual(forest_dataset_train, outcome_train, forest_model_tau, TRUE, FALSE)
861861

862862
# Initialize the leaves of each tree in the variance forest
863863
if (include_variance_forest) {
@@ -868,7 +868,7 @@ bcf <- function(X_train, Z_train, y_train, propensity_train = NULL, rfx_group_id
868868
if (num_gfr > 0){
869869
for (i in 1:num_gfr) {
870870
# Keep all GFR samples at this stage -- remove from ForestSamples after MCMC
871-
# keep_sample <- ifelse(keep_gfr, T, F)
871+
# keep_sample <- ifelse(keep_gfr, TRUE, FALSE)
872872
keep_sample <- TRUE
873873
if (keep_sample) sample_counter <- sample_counter + 1
874874
# Print progress

R/forest.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ ForestSamples <- R6::R6Class(
231231

232232
#' @description
233233
#' Return constant leaf status of trees in a `ForestContainer` object
234-
#' @return `T` if leaves are constant, `F` otherwise
234+
#' @return `TRUE` if leaves are constant, `FALSE` otherwise
235235
is_constant_leaf = function() {
236236
return(is_constant_leaf_forest_container_cpp(self$forest_container_ptr))
237237
},
238238

239239
#' @description
240240
#' Return exponentiation status of trees in a `ForestContainer` object
241-
#' @return `T` if leaf predictions must be exponentiated, `F` otherwise
241+
#' @return `TRUE` if leaf predictions must be exponentiated, `FALSE` otherwise
242242
is_exponentiated = function() {
243243
return(is_exponentiated_forest_container_cpp(self$forest_container_ptr))
244244
},
@@ -692,14 +692,14 @@ Forest <- R6::R6Class(
692692

693693
#' @description
694694
#' Return constant leaf status of trees in a `Forest` object
695-
#' @return `T` if leaves are constant, `F` otherwise
695+
#' @return `TRUE` if leaves are constant, `FALSE` otherwise
696696
is_constant_leaf = function() {
697697
return(is_constant_leaf_active_forest_cpp(self$forest_ptr))
698698
},
699699

700700
#' @description
701701
#' Return exponentiation status of trees in a `Forest` object
702-
#' @return `T` if leaf predictions must be exponentiated, `F` otherwise
702+
#' @return `TRUE` if leaf predictions must be exponentiated, `FALSE` otherwise
703703
is_exponentiated = function() {
704704
return(is_exponentiated_active_forest_cpp(self$forest_ptr))
705705
},

R/kernel.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ computeForestLeafVariances <- function(model_object, forest_type, forest_inds=NU
150150
if (!model_object$model_params$include_mean_forest) {
151151
stop("Mean forest was not sampled in the bart model provided")
152152
}
153-
if (model_object$model_params$sample_sigma_leaf == F) {
153+
if (!model_object$model_params$sample_sigma_leaf) {
154154
stop("Leaf scale parameter was not sampled for the mean forest in the bart model provided")
155155
}
156156
leaf_scale_vector <- model_object$sigma2_leaf_samples
@@ -163,12 +163,12 @@ computeForestLeafVariances <- function(model_object, forest_type, forest_inds=NU
163163
} else {
164164
stopifnot(forest_type %in% c("prognostic", "treatment", "variance"))
165165
if (forest_type=="prognostic") {
166-
if (model_object$model_params$sample_sigma_leaf_mu == F) {
166+
if (!model_object$model_params$sample_sigma_leaf_mu) {
167167
stop("Leaf scale parameter was not sampled for the prognostic forest in the bcf model provided")
168168
}
169169
leaf_scale_vector <- model_object$sigma_leaf_mu_samples
170170
} else if (forest_type=="treatment") {
171-
if (model_object$model_params$sample_sigma_leaf_tau == F) {
171+
if (!model_object$model_params$sample_sigma_leaf_tau) {
172172
stop("Leaf scale parameter was not sampled for the treatment effect forest in the bcf model provided")
173173
}
174174
leaf_scale_vector <- model_object$sigma_leaf_tau_samples

R/utils.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ preprocessTrainDataFrame <- function(input_df) {
177177
# Detect ordered and unordered categorical variables
178178

179179
# First, ordered categorical: users must have explicitly
180-
# converted this to a factor with ordered = T
180+
# converted this to a factor with ordered = TRUE
181181
factor_mask <- sapply(input_df, is.factor)
182182
ordered_mask <- sapply(input_df, is.ordered)
183183
ordered_cat_matches <- factor_mask & ordered_mask
@@ -528,9 +528,9 @@ createForestCovariates <- function(input_data, ordered_cat_vars = NULL, unordere
528528
stop("input_data must be either a matrix or a data frame")
529529
}
530530
df_vars <- names(input_df)
531-
if (is.null(ordered_cat_vars)) ordered_cat_matches <- rep(F, length(df_vars))
531+
if (is.null(ordered_cat_vars)) ordered_cat_matches <- rep(FALSE, length(df_vars))
532532
else ordered_cat_matches <- df_vars %in% ordered_cat_vars
533-
if (is.null(unordered_cat_vars)) unordered_cat_matches <- rep(F, length(df_vars))
533+
if (is.null(unordered_cat_vars)) unordered_cat_matches <- rep(FALSE, length(df_vars))
534534
else unordered_cat_matches <- df_vars %in% unordered_cat_vars
535535
numeric_matches <- ((!ordered_cat_matches) & (!unordered_cat_matches))
536536
ordered_cat_vars <- df_vars[ordered_cat_matches]

man/Forest.Rd

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

man/ForestSamples.Rd

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

test/R/testthat/test-bart.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ test_that("Warmstart BART", {
244244
((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) +
245245
((0.75 <= X[,1]) & (1 > X[,1])) * (7.5)
246246
)
247-
rfx_group_ids <- sample(1:2, size = n, replace = T)
247+
rfx_group_ids <- sample(1:2, size = n, replace = TRUE)
248248
rfx_basis <- rep(1, n)
249249
rfx_coefs <- c(-5, 5)
250250
rfx_term <- rfx_coefs[rfx_group_ids] * rfx_basis

test/R/testthat/test-bcf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ test_that("Warmstart BCF", {
298298
((0.75 <= X[,2]) & (1 > X[,2])) * (2.0)
299299
)
300300
Z <- rbinom(n, 1, pi_X)
301-
rfx_group_ids <- sample(1:2, size = n, replace = T)
301+
rfx_group_ids <- sample(1:2, size = n, replace = TRUE)
302302
rfx_basis <- rep(1, n)
303303
rfx_coefs <- c(-5, 5)
304304
rfx_term <- rfx_coefs[rfx_group_ids] * rfx_basis

test/R/testthat/test-categorical.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test_that("In-sample one-hot encoding works for unordered categorical variables"
1212
0,1,0,0,0,
1313
0,0,0,1,0,
1414
0,1,0,0,0),
15-
byrow = T, ncol = 5)
15+
byrow = TRUE, ncol = 5)
1616
x1_levels_expected <- c("1","2","3","4")
1717

1818
x2 <- c("a","c","b","c","d","a","c","a","b","d")
@@ -28,7 +28,7 @@ test_that("In-sample one-hot encoding works for unordered categorical variables"
2828
1,0,0,0,0,
2929
0,1,0,0,0,
3030
0,0,0,1,0),
31-
byrow = T, ncol = 5)
31+
byrow = TRUE, ncol = 5)
3232
x2_levels_expected <- c("a","b","c","d")
3333

3434
x3 <- c(3.2,2.4,1.5,4.6,3.2,2.4,3.2,2.4,4.6,2.4)
@@ -44,7 +44,7 @@ test_that("In-sample one-hot encoding works for unordered categorical variables"
4444
0,1,0,0,0,
4545
0,0,0,1,0,
4646
0,1,0,0,0),
47-
byrow = T, ncol = 5)
47+
byrow = TRUE, ncol = 5)
4848
x3_levels_expected <- c("1.5","2.4","3.2","4.6")
4949

5050
expect_equal(x1_onehot$Xtilde, x1_expected)
@@ -65,7 +65,7 @@ test_that("Out-of-sample one-hot encoding works for unordered categorical variab
6565
0,0,0,1,0,
6666
0,0,1,0,0,
6767
0,0,0,0,1),
68-
byrow = T, ncol = 5)
68+
byrow = TRUE, ncol = 5)
6969

7070
x2 <- c("a","c","b","c","d","a","c","a","b","d")
7171
x2_test <- c("a","c","g","b","f")
@@ -76,7 +76,7 @@ test_that("Out-of-sample one-hot encoding works for unordered categorical variab
7676
0,0,0,0,1,
7777
0,1,0,0,0,
7878
0,0,0,0,1),
79-
byrow = T, ncol = 5)
79+
byrow = TRUE, ncol = 5)
8080

8181
x3 <- c(3.2,2.4,1.5,4.6,3.2,2.4,3.2,2.4,4.6,2.4)
8282
x3_test <- c(10.3,-0.5,4.6,3.2,1.8)
@@ -87,7 +87,7 @@ test_that("Out-of-sample one-hot encoding works for unordered categorical variab
8787
0,0,0,1,0,
8888
0,0,1,0,0,
8989
0,0,0,0,1),
90-
byrow = T, ncol = 5)
90+
byrow = TRUE, ncol = 5)
9191

9292
expect_equal(x1_test_onehot, x1_test_expected)
9393
expect_equal(x2_test_onehot, x2_test_expected)
@@ -102,13 +102,13 @@ test_that("In-sample preprocessing for ordered categorical variables", {
102102
x1_vector_expected <- c(1,3,2,4,3,5,4)
103103
x1_levels_expected <- string_var_response_levels
104104

105-
x2 <- factor(x1, levels = string_var_response_levels, ordered = T)
105+
x2 <- factor(x1, levels = string_var_response_levels, ordered = TRUE)
106106
x2_preprocessing <- orderedCatInitializeAndPreprocess(x2)
107107
x2_vector_expected <- c(1,3,2,4,3,5,4)
108108
x2_levels_expected <- string_var_response_levels
109109

110110
string_var_levels_reordered <- c("5. Strongly agree", "4. Agree", "3. Neither agree nor disagree", "2. Disagree", "1. Strongly disagree")
111-
x3 <- factor(x1, levels = string_var_levels_reordered, ordered = T)
111+
x3 <- factor(x1, levels = string_var_levels_reordered, ordered = TRUE)
112112
x3_preprocessing <- orderedCatInitializeAndPreprocess(x3)
113113
x3_vector_expected <- c(5,3,4,2,3,1,2)
114114
x3_levels_expected <- string_var_levels_reordered
@@ -135,7 +135,7 @@ test_that("Out-of-sample preprocessing for ordered categorical variables", {
135135
x1_preprocessing <- orderedCatPreprocess(x1, string_var_response_levels)
136136
x1_vector_expected <- c(1,3,2,4,3,5,4)
137137

138-
x2 <- factor(x1, levels = string_var_response_levels, ordered = T)
138+
x2 <- factor(x1, levels = string_var_response_levels, ordered = TRUE)
139139
x2_preprocessing <- orderedCatPreprocess(x2, string_var_response_levels)
140140
x2_vector_expected <- c(1,3,2,4,3,5,4)
141141

test/R/testthat/test-predict.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ test_that("Prediction from trees with constant leaf", {
77
4.4, 5.4, 10.4,
88
5.3, 9.3, 3.6,
99
6.1, 10.4, 4.4),
10-
byrow = T, nrow = 6)
10+
byrow = TRUE, nrow = 6)
1111
n <- nrow(X)
1212
p <- ncol(X)
1313
forest_dataset = createForestDataset(X)
14-
forest_samples <- createForestSamples(num_trees, 1, T)
14+
forest_samples <- createForestSamples(num_trees, 1, TRUE)
1515

1616
# Initialize a forest with constant root predictions
1717
forest_samples$add_forest_with_constant_leaves(0.)
@@ -60,12 +60,12 @@ test_that("Prediction from trees with univariate leaf basis", {
6060
4.4, 5.4, 10.4,
6161
5.3, 9.3, 3.6,
6262
6.1, 10.4, 4.4),
63-
byrow = T, nrow = 6)
63+
byrow = TRUE, nrow = 6)
6464
W = as.matrix(c(-1,-1,-1,1,1,1))
6565
n <- nrow(X)
6666
p <- ncol(X)
6767
forest_dataset = createForestDataset(X,W)
68-
forest_samples <- createForestSamples(num_trees, 1, F)
68+
forest_samples <- createForestSamples(num_trees, 1, FALSE)
6969

7070
# Initialize a forest with constant root predictions
7171
forest_samples$add_forest_with_constant_leaves(0.)
@@ -118,12 +118,12 @@ test_that("Prediction from trees with multivariate leaf basis", {
118118
4.4, 5.4, 10.4,
119119
5.3, 9.3, 3.6,
120120
6.1, 10.4, 4.4),
121-
byrow = T, nrow = 6)
121+
byrow = TRUE, nrow = 6)
122122
n <- nrow(X)
123123
p <- ncol(X)
124124
W = matrix(c(1,1,1,1,1,1,-1,-1,-1,1,1,1), byrow=FALSE, nrow=6)
125125
forest_dataset = createForestDataset(X,W)
126-
forest_samples <- createForestSamples(num_trees, output_dim, F)
126+
forest_samples <- createForestSamples(num_trees, output_dim, FALSE)
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test_that("Residual updates correctly propagated after forest sampling step", {
77
4.4, 5.4, 10.4,
88
5.3, 9.3, 3.6,
99
6.1, 10.4, 4.4),
10-
byrow = T, nrow = 6)
10+
byrow = TRUE, nrow = 6)
1111
W = matrix(c(1, 1, 1, 1, 1, 1), nrow = 6)
1212
n = nrow(X)
1313
p = ncol(X)
@@ -44,17 +44,17 @@ test_that("Residual updates correctly propagated after forest sampling step", {
4444
variable_weights=variable_weights, variance_forest_shape=a_forest,
4545
variance_forest_scale=b_forest, cutpoint_grid_size=cutpoint_grid_size)
4646
forest_model = createForestModel(forest_dataset, forest_model_config, global_model_config)
47-
forest_samples = createForestSamples(num_trees, 1, F)
48-
active_forest = createForest(num_trees, 1, F)
47+
forest_samples = createForestSamples(num_trees, 1, FALSE)
48+
active_forest = createForest(num_trees, 1, FALSE)
4949

5050
# Initialize the leaves of each tree in the prognostic forest
5151
active_forest$prepare_for_sampler(forest_dataset, residual, forest_model, 0, mean(resid))
52-
active_forest$adjust_residual(forest_dataset, residual, forest_model, F, F)
52+
active_forest$adjust_residual(forest_dataset, residual, forest_model, FALSE, FALSE)
5353

5454
# Run the forest sampling algorithm for a single iteration
5555
forest_model$sample_one_iteration(
5656
forest_dataset, residual, forest_samples, active_forest,
57-
cpp_rng, forest_model_config, global_model_config, keep_forest = T, gfr = T
57+
cpp_rng, forest_model_config, global_model_config, keep_forest = TRUE, gfr = TRUE
5858
)
5959

6060
# Get the current residual after running the sampler

0 commit comments

Comments
 (0)