From 0cec11d9ed71a7b0a5f6349689a581c77496075a Mon Sep 17 00:00:00 2001 From: Drew Herren Date: Thu, 31 Oct 2024 02:32:24 -0400 Subject: [PATCH] Updated R method documentation for ForestSamples --- R/cpp11.R | 4 ++++ man/ForestSamples.Rd | 28 +++++++++++++++++++++++++++- src/cpp11.cpp | 8 ++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/R/cpp11.R b/R/cpp11.R index 3f4bce3d..e8fbf36a 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -348,6 +348,10 @@ predict_forest_raw_single_forest_cpp <- function(forest_samples, dataset, forest .Call(`_stochtree_predict_forest_raw_single_forest_cpp`, forest_samples, dataset, forest_num) } +predict_forest_raw_single_tree_cpp <- function(forest_samples, dataset, forest_num, tree_num) { + .Call(`_stochtree_predict_forest_raw_single_tree_cpp`, forest_samples, dataset, forest_num, tree_num) +} + forest_container_get_max_leaf_index_cpp <- function(forest_container, forest_num) { .Call(`_stochtree_forest_container_get_max_leaf_index_cpp`, forest_container, forest_num) } diff --git a/man/ForestSamples.Rd b/man/ForestSamples.Rd index 6c8ec284..88d21f1f 100644 --- a/man/ForestSamples.Rd +++ b/man/ForestSamples.Rd @@ -24,6 +24,7 @@ Wrapper around a C++ container of tree ensembles \item \href{#method-ForestSamples-predict}{\code{ForestSamples$predict()}} \item \href{#method-ForestSamples-predict_raw}{\code{ForestSamples$predict_raw()}} \item \href{#method-ForestSamples-predict_raw_single_forest}{\code{ForestSamples$predict_raw_single_forest()}} +\item \href{#method-ForestSamples-predict_raw_single_tree}{\code{ForestSamples$predict_raw_single_tree()}} \item \href{#method-ForestSamples-set_root_leaves}{\code{ForestSamples$set_root_leaves()}} \item \href{#method-ForestSamples-prepare_for_sampler}{\code{ForestSamples$prepare_for_sampler()}} \item \href{#method-ForestSamples-adjust_residual}{\code{ForestSamples$adjust_residual()}} @@ -230,7 +231,32 @@ Predict "raw" leaf values (without being multiplied by basis) for a specific for } \subsection{Returns}{ matrix of predictions with as many rows as in forest_dataset -and as many columns as samples in the \code{ForestContainer} +and as many columns as dimensions in the leaves of trees in \code{ForestContainer} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ForestSamples-predict_raw_single_tree}{}}} +\subsection{Method \code{predict_raw_single_tree()}}{ +Predict "raw" leaf values (without being multiplied by basis) for a specific tree in a specific forest on every observation in \code{forest_dataset} +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{ForestSamples$predict_raw_single_tree(forest_dataset, forest_num, tree_num)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{forest_dataset}}{\code{ForestDataset} R class} + +\item{\code{forest_num}}{Index of the forest sample within the container} + +\item{\code{tree_num}}{Index of the tree to be queried} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +matrix of predictions with as many rows as in \code{forest_dataset} +and as many columns as dimensions in the leaves of trees in \code{ForestContainer} } } \if{html}{\out{
}} diff --git a/src/cpp11.cpp b/src/cpp11.cpp index cfb26658..18dc931d 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -648,6 +648,13 @@ extern "C" SEXP _stochtree_predict_forest_raw_single_forest_cpp(SEXP forest_samp return cpp11::as_sexp(predict_forest_raw_single_forest_cpp(cpp11::as_cpp>>(forest_samples), cpp11::as_cpp>>(dataset), cpp11::as_cpp>(forest_num))); END_CPP11 } +// forest.cpp +cpp11::writable::doubles_matrix<> predict_forest_raw_single_tree_cpp(cpp11::external_pointer forest_samples, cpp11::external_pointer dataset, int forest_num, int tree_num); +extern "C" SEXP _stochtree_predict_forest_raw_single_tree_cpp(SEXP forest_samples, SEXP dataset, SEXP forest_num, SEXP tree_num) { + BEGIN_CPP11 + return cpp11::as_sexp(predict_forest_raw_single_tree_cpp(cpp11::as_cpp>>(forest_samples), cpp11::as_cpp>>(dataset), cpp11::as_cpp>(forest_num), cpp11::as_cpp>(tree_num))); + END_CPP11 +} // kernel.cpp int forest_container_get_max_leaf_index_cpp(cpp11::external_pointer forest_container, int forest_num); extern "C" SEXP _stochtree_forest_container_get_max_leaf_index_cpp(SEXP forest_container, SEXP forest_num) { @@ -1034,6 +1041,7 @@ static const R_CallMethodDef CallEntries[] = { {"_stochtree_predict_forest_cpp", (DL_FUNC) &_stochtree_predict_forest_cpp, 2}, {"_stochtree_predict_forest_raw_cpp", (DL_FUNC) &_stochtree_predict_forest_raw_cpp, 2}, {"_stochtree_predict_forest_raw_single_forest_cpp", (DL_FUNC) &_stochtree_predict_forest_raw_single_forest_cpp, 3}, + {"_stochtree_predict_forest_raw_single_tree_cpp", (DL_FUNC) &_stochtree_predict_forest_raw_single_tree_cpp, 4}, {"_stochtree_propagate_basis_update_forest_container_cpp", (DL_FUNC) &_stochtree_propagate_basis_update_forest_container_cpp, 5}, {"_stochtree_propagate_trees_column_vector_cpp", (DL_FUNC) &_stochtree_propagate_trees_column_vector_cpp, 2}, {"_stochtree_rfx_container_append_from_json_cpp", (DL_FUNC) &_stochtree_rfx_container_append_from_json_cpp, 3},