Skip to contents

While the BARTSerialization and BCFSerialization topics focus on JSON serialization / deserialization for entire bartmodel and bcfmodel objects, this function group provides an interface for a more focused use case: loading a single ForestSamples container from a broader BART / BCF model (which may include multiple forests and other parametric terms).

loadForestContainerJson converts a CppJson object representing a BART or BCF model into a ForestSamples container by extracting the JSON indexed by a forest label (i.e. "forest_0") and deserializing it into a ForestSamples object.

Both loadForestContainerJson and loadForestContainerCombinedJson operate similarly, but on a list of CppJson or JSON string representations of BART / BCF models with the same structure.

These functions are intended for advanced use cases in which users require detailed control of sampling algorithms and data structures. Minimal input validation and error checks are performed – users are responsible for providing the correct inputs. For tutorials on the "proper" usage of the stochtree's advanced workflow, we provide several vignettes at https://stochtree.ai/

Usage

loadForestContainerJson(json_object, json_forest_label)

loadForestContainerCombinedJson(json_object_list, json_forest_label)

loadForestContainerCombinedJsonString(json_string_list, json_forest_label)

Arguments

json_object

Object of class CppJson

json_forest_label

Label referring to a particular forest (i.e. "forest_0") in the overall json hierarchy (must exist in every json object in a list if a list is provided)

json_object_list

List of objects of class CppJson

json_string_list

List of strings that parse into objects of type CppJson

Value

Each of the functions in this group returns a ForestSamples object.

Examples

X <- matrix(runif(10*100), ncol = 10)
y <- -5 + 10*(X[,1] > 0.5) + rnorm(100)
bart_model <- bart(X, y, num_gfr=0, num_mcmc=10)
bart_json <- saveBARTModelToJson(bart_model)
bart_json_string <- saveBARTModelToJsonString(bart_model)
bart_json_list <- list(bart_json)
bart_json_string_list <- list(bart_json_string)
mean_forest <- loadForestContainerJson(bart_json, "forest_0")
mean_forest <- loadForestContainerCombinedJson(bart_json_list, "forest_0")
mean_forest <- loadForestContainerCombinedJsonString(bart_json_string_list, "forest_0")