StochTree 0.5.0.9000
Loading...
Searching...
No Matches
prediction.h
1
5#ifndef STOCHTREE_PREDICTION_H_
6#define STOCHTREE_PREDICTION_H_
7
8#include <vector>
9#include <stochtree/bart.h>
10#include <stochtree/bcf.h>
11#include <stochtree/container.h>
12#include <stochtree/meta.h>
13#include <stochtree/random_effects.h>
14
15namespace StochTree {
16
18enum class PredType {
19 kPosterior,
20 kMean
21};
22
33enum class PredScale {
34 kLinear,
35 kProbability,
36 kClass
37};
38
41 bool y_hat = true;
42 bool mean_forest = false;
43 bool variance_forest = false;
44 bool random_effects = false;
45};
46
56 // Outcome conditional mean
57 std::vector<double> y_hat;
58
59 // Covariate-dependent prognostic term (mu(x))
60 std::vector<double> mean_forest_predictions;
61
62 // Conditional variance term
63 std::vector<double> variance_forest_predictions;
64
65 // Random effects predictions
66 std::vector<double> rfx_predictions;
67};
68
74 // Metadata about the samples / model (e.g., number of samples, burn-in, etc.)
75 int num_samples = 0;
76 int num_obs = 0;
77 int num_basis = 0;
78 double y_bar = 0.0;
79 double y_std = 0.0;
80 bool has_variance_forest = false;
81 bool has_rfx = false;
82 BARTRFXModelSpec rfx_model_spec;
83 PredType pred_type = PredType::kPosterior;
84 BARTPredTerms pred_terms;
85 PredScale pred_scale = PredScale::kLinear;
86 LinkFunction link_function = LinkFunction::Identity;
87 OutcomeType outcome_type = OutcomeType::Continuous;
88 int cloglog_num_classes = 0;
89};
90
103
106 bool y_hat = true;
107 bool mu_x = false;
108 bool tau_x = false;
109 bool prognostic_function = false;
110 bool cate = false;
111 bool conditional_variance = false;
112 bool random_effects = false;
113};
114
124 // Outcome conditional mean
125 std::vector<double> y_hat;
126
127 // Covariate-dependent prognostic term (mu(x))
128 std::vector<double> mu_x;
129
130 // Covariate-dependent treatment effect term (tau(x))
131 std::vector<double> tau_x;
132
133 // Prognostic function (includes mu(x) and any random intercepts, provided random effects
134 // were estimated with `intercept_only` or `intercept_plus_treatment` specification)
135 std::vector<double> prognostic_function;
136
137 // CATE function (includes tau(x) and any random slopes on treatment, provided
138 // random effects were estimated with `intercept_plus_treatment` specification)
139 std::vector<double> cate;
140
141 // Conditional variance term
142 std::vector<double> conditional_variance;
143
144 // Random effects predictions
145 std::vector<double> random_effects;
146};
147
153 // Metadata about the samples / model (e.g., number of samples, burn-in, etc.) could be added here as needed
154 int num_samples = 0;
155 int num_obs = 0;
156 int treatment_dim = 0;
157 double y_bar = 0.0;
158 double y_std = 0.0;
159 bool has_variance_forest = false;
160 bool has_rfx = false;
161 BCFRFXModelSpec rfx_model_spec;
162 bool adaptive_coding = false;
163 bool sample_tau_0 = false;
164 PredType pred_type = PredType::kPosterior;
165 BCFPredTerms pred_terms;
166 PredScale pred_scale = PredScale::kLinear;
167};
168
181
182} // namespace StochTree
183
184#endif // STOCHTREE_PREDICTION_H_
static void GFRSampleOneIter(TreeEnsemble &active_forest, ForestTracker &tracker, ForestContainer &forests, LeafModel &leaf_model, ForestDataset &dataset, ColumnVector &residual, TreePrior &tree_prior, std::mt19937 &gen, std::vector< double > &variable_weights, std::vector< int > &sweep_update_indices, double global_variance, std::vector< FeatureType > &feature_types, int cutpoint_grid_size, bool keep_forest, bool pre_initialized, bool backfitting, int num_features_subsample, int num_threads, LeafSuffStatConstructorArgs &... leaf_suff_stat_args)
Definition tree_sampler.h:816
A collection of random number generation utilities.
Definition bart.h:15
BARTPredictionResult predict_bart_model(BARTData &data, BARTSamples &samples, BARTPredictionMetadata &metadata)
BART prediction function.
PredType
Determines whether posterior predictions are returned as-is or pre-aggregated.
Definition prediction.h:18
PredScale
Determines the scale of predictions (i.e. whether a probability / class transformation is applied)
Definition prediction.h:33
BCFPredictionResult predict_bcf_model(BCFData &data, BCFSamples &samples, BCFPredictionMetadata &metadata)
BCF prediction function.
Definition bart.h:22
Selector for model terms that should be predicted.
Definition prediction.h:40
Metadata for the BART prediction routine.
Definition prediction.h:73
Struct returning BART model predictions.
Definition prediction.h:55
Definition bart.h:125
Definition bcf.h:23
Selector for model terms that should be predicted.
Definition prediction.h:105
Metadata for the BCF prediction routine.
Definition prediction.h:152
Struct returning BCF model predictions.
Definition prediction.h:123
Definition bcf.h:145