Skip to content

Commit 12299e1

Browse files
committed
Updated variance and preprocessing docs
1 parent 86fd507 commit 12299e1

6 files changed

+68
-1
lines changed

R/utils.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ savePreprocessorToJsonString <- function(object){
429429
#'
430430
#' @returns Preprocessor object that can be used with the `preprocessPredictionData` function
431431
#' @export
432+
#'
433+
#' @examples
434+
#' cov_mat <- matrix(1:12, ncol = 3)
435+
#' preprocess_list <- preprocessTrainData(cov_mat)
436+
#' preprocessor_json <- convertPreprocessorToJson(preprocess_list$metadata)
437+
#' preprocessor_roundtrip <- createPreprocessorFromJson(preprocessor_json)
432438
createPreprocessorFromJson <- function(json_object){
433439
# Initialize the metadata list
434440
metadata <- list()
@@ -472,6 +478,12 @@ createPreprocessorFromJson <- function(json_object){
472478
#'
473479
#' @return Preprocessor object that can be used with the `preprocessPredictionData` function
474480
#' @export
481+
#'
482+
#' @examples
483+
#' cov_mat <- matrix(1:12, ncol = 3)
484+
#' preprocess_list <- preprocessTrainData(cov_mat)
485+
#' preprocessor_json_string <- savePreprocessorToJsonString(preprocess_list$metadata)
486+
#' preprocessor_roundtrip <- createPreprocessorFromJsonString(preprocessor_json_string)
475487
createPreprocessorFromJsonString <- function(json_string){
476488
# Load a `CppJson` object from string
477489
preprocessor_json <- createCppJsonString(json_string)

R/variance.R

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
#' @param rng C++ random number generator
66
#' @param a Global variance shape parameter
77
#' @param b Global variance scale parameter
8-
#'
98
#' @export
9+
#'
10+
#' @examples
11+
#' X <- matrix(runif(10*100), ncol = 10)
12+
#' y <- -5 + 10*(X[,1] > 0.5) + rnorm(100)
13+
#' y_std <- (y-mean(y))/sd(y)
14+
#' forest_dataset <- createForestDataset(X)
15+
#' outcome <- createOutcome(y_std)
16+
#' rng <- createCppRNG(1234)
17+
#' a <- 1.0
18+
#' b <- 1.0
19+
#' sigma2 <- sampleGlobalErrorVarianceOneIteration(outcome, forest_dataset, rng, a, b)
1020
sampleGlobalErrorVarianceOneIteration <- function(residual, dataset, rng, a, b) {
1121
return(sample_sigma2_one_iteration_cpp(residual$data_ptr, dataset$data_ptr, rng$rng_ptr, a, b))
1222
}
@@ -19,6 +29,17 @@ sampleGlobalErrorVarianceOneIteration <- function(residual, dataset, rng, a, b)
1929
#' @param b Leaf variance scale parameter
2030
#'
2131
#' @export
32+
#'
33+
#' @examples
34+
#' num_trees <- 100
35+
#' leaf_dimension <- 1
36+
#' is_leaf_constant <- TRUE
37+
#' is_exponentiated <- FALSE
38+
#' active_forest <- createForest(num_trees, leaf_dimension, is_leaf_constant, is_exponentiated)
39+
#' rng <- createCppRNG(1234)
40+
#' a <- 1.0
41+
#' b <- 1.0
42+
#' tau <- sampleLeafVarianceOneIteration(active_forest, rng, a, b)
2243
sampleLeafVarianceOneIteration <- function(forest, rng, a, b) {
2344
return(sample_tau_one_iteration_cpp(forest$forest_ptr, rng$rng_ptr, a, b))
2445
}

man/createPreprocessorFromJson.Rd

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

man/createPreprocessorFromJsonString.Rd

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

man/sampleGlobalErrorVarianceOneIteration.Rd

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

man/sampleLeafVarianceOneIteration.Rd

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

0 commit comments

Comments
 (0)