% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/serialization.R
\name{RandomEffectSamplesSerialization}
\alias{RandomEffectSamplesSerialization}
\alias{loadRandomEffectSamplesJson}
\alias{loadRandomEffectSamplesCombinedJson}
\alias{loadRandomEffectSamplesCombinedJsonString}
\title{Random Effects Container Serialization Routines}
\usage{
loadRandomEffectSamplesJson(json_object, json_rfx_num)

loadRandomEffectSamplesCombinedJson(json_object_list, json_rfx_num)

loadRandomEffectSamplesCombinedJsonString(json_string_list, json_rfx_num)
}
\arguments{
\item{json_object}{Object of class \code{CppJson}}

\item{json_rfx_num}{Integer index indicating the position of the random effects term to be unpacked (must exist in every json object in a list if a list is provided)}

\item{json_object_list}{List of objects of class \code{CppJson}}

\item{json_string_list}{List of objects of class \code{CppJson}}
}
\value{
Each of the functions in this group returns a \code{RandomEffectSamples} object.
}
\description{
While the \link{BARTSerialization} and \link{BCFSerialization} topics focus on JSON serialization / deserialization for
entire \code{bartmodel} and \code{bcfmodel} objects, this function group provides an interface for a more focused use case:
loading a single \link{RandomEffectSamples} container from a broader BART / BCF model (which may include forests and other parametric terms).

\code{loadRandomEffectSamplesJson} converts a \link{CppJson} object representing a BART or BCF model into a \link{RandomEffectSamples} container
by extracting the JSON indexed by an integer label (i.e. \code{0}) and deserializing it into a \link{RandomEffectSamples} object.

Both \code{loadRandomEffectSamplesJson} and \code{loadRandomEffectSamplesCombinedJson} operate similarly, but on a list of \link{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 \url{https://stochtree.ai/}
}
\examples{
n <- 100
p <- 10
X <- matrix(runif(n*p), ncol = p)
rfx_group_ids <- sample(1:2, size = n, replace = TRUE)
rfx_basis <- rep(1.0, n)
y <- (-5 + 10*(X[,1] > 0.5)) + (-2*(rfx_group_ids==1)+2*(rfx_group_ids==2))
bart_model <- bart(X_train=X, y_train=y, rfx_group_ids_train=rfx_group_ids,
                   rfx_basis_train = rfx_basis, 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)
rfx_container <- loadRandomEffectSamplesJson(bart_json, 0)
rfx_container <- loadRandomEffectSamplesCombinedJson(bart_json_list, 0)
rfx_container <- loadRandomEffectSamplesCombinedJsonString(bart_json_string_list, 0)

}
