StochTree 0.5.0.9000
Loading...
Searching...
No Matches
bart_sampler.h
1
5#ifndef STOCHTREE_BART_SAMPLER_H_
6#define STOCHTREE_BART_SAMPLER_H_
7
8#include <stochtree/bart.h>
9#include <stochtree/container.h>
10#include <stochtree/data.h>
11#include <stochtree/ensemble.h>
12#include <stochtree/leaf_model.h>
13#include <stochtree/linear_regression.h>
14#include <stochtree/ordinal_sampler.h>
15#include <stochtree/partition_tracker.h>
16#include <stochtree/prior.h>
17#include <stochtree/probit.h>
18#include <stochtree/random_effects.h>
19#include <stochtree/tree_sampler.h>
20#include <stochtree/variance_model.h>
21#include <iomanip>
22#include <memory>
23#include <sstream>
24#include <string>
25#include <type_traits>
26#include <variant>
27#include <vector>
28
29namespace StochTree {
30
32 public:
33 // If continuation is true, the sampler warm-starts from the last retained sample
34 // already present in `samples` (rather than initializing forests to root), and the
35 // existing forest container is preserved so that new samples are appended to it.
36 //
37 // If warmstart_source is non-null (and continuation is false), this is a FRESH run whose forests /
38 // scalars / rfx are seeded from an EXTERNAL model's samples (`*warmstart_source`) at
39 // `warmstart_sample_num` (1-indexed). This backs bart(previous_model_json=...): the destination
40 // `samples` container is fresh, but the active forest is reconstituted from the previous model's
41 // retained sample. Same-scale is assumed (no leaf rescale); the previous model's y_std is used to
42 // convert its stored global variance back to standardized space, matching the R main-branch flow.
43 // The borrowed pointer need only outlive this constructor call.
44 BARTSampler(BARTSamples& samples, BARTConfig& config, BARTData& data, bool continuation = false,
45 BARTSamples* warmstart_source = nullptr, int warmstart_sample_num = 0);
46
47 // Main entry point for running the BART GFR sampler
48 // If num_chains > 0, captures snapshots of the last num_chains GFR states for fork_chains()
49 void run_gfr(BARTSamples& samples, int num_gfr, bool keep_gfr, int num_chains = 0);
50
51 // Run a single chain of the BART MCMC sampler
52 void run_mcmc(BARTSamples& samples, int num_burnin, int keep_every, int num_mcmc);
53
54 // Run num_chains independent MCMC chains sequentually based on GFR snapshots captured by run_gfr() or re-initialized from root
55 void run_mcmc_chains(BARTSamples& samples, int num_chains, int num_burnin, int keep_every, int num_mcmc);
56
57 // Post-process samples by extracting test set predictions and running any necessary transformations
58 void postprocess_samples(BARTSamples& samples, int start_sample = 0);
59
60 // Serialize the internal RNG state to a string. std::mt19937 round-trips losslessly through
61 // its stream operators, so this captures the exact position in the random stream -- used to
62 // persist RNG state across a sample() / continue_sampling() boundary for bit-identical results.
63 std::string GetRngState() const {
64 std::ostringstream oss;
65 oss << rng_;
66 return oss.str();
67 }
68
69 // Restore the internal RNG state from a string produced by GetRngState(). Resumes the random
70 // stream at exactly the captured position. Must be called after construction (InitializeState
71 // unconditionally re-seeds rng_) and before any sampling draws.
72 void SetRngState(const std::string& state) {
73 std::istringstream iss(state);
74 iss >> rng_;
75 }
76
77 // Regenerate the latent outcome for a continuation warm-start (probit or cloglog). The latent is not
78 // persisted (it is re-drawn each MCMC iteration), so this draws a fresh latent to place the residual
79 // / auxiliary state in a valid, stationary state before the first continued draw. No-op unless the
80 // model uses a latent-augmentation link (probit or cloglog) and has a mean forest. MUST be called
81 // after SetRngState so the draw comes from the resumed (or user-re-seeded) stream rather than the
82 // pre-seed default RNG. For cloglog, the deterministic auxiliary state (eta / cutpoints / residual)
83 // is set up in InitializeState's continuation cloglog block before this draw.
84 void RegenerateLatentOutcome(BARTSamples& samples);
85
86 private:
88 void InitializeState(BARTSamples& samples, bool continuation = false);
89 bool initialized_ = false;
90
92 void RestoreStateFromGFRSnapshot(BARTSamples& samples, int snapshot_index);
93
99 void WarmStartResetFromSample(BARTSamples& samples, BARTSamples& source, int idx);
100
102 void RestoreStateDefault();
103
105 void RunOneIteration(BARTSamples& samples, bool gfr, bool keep_sample, bool write_snapshot = false);
106
108 struct MeanForestInitVisitor {
109 BARTSampler& sampler;
110 BARTSamples& samples;
111 void operator()(GaussianConstantLeafModel& model) {
112 sampler.mean_forest_ = std::make_unique<TreeEnsemble>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
113 samples.mean_forests = std::make_unique<ForestContainer>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
114 sampler.mean_forest_tracker_ = std::make_unique<ForestTracker>(sampler.forest_dataset_->GetCovariates(), sampler.config_.feature_types, sampler.config_.num_trees_mean, sampler.data_.n_train);
115 sampler.tree_prior_mean_ = std::make_unique<TreePrior>(sampler.config_.alpha_mean, sampler.config_.beta_mean, sampler.config_.min_samples_leaf_mean, sampler.config_.max_depth_mean);
116 sampler.mean_forest_->SetLeafValue(sampler.init_val_mean_ / sampler.config_.num_trees_mean);
117 UpdateResidualEntireForest(*sampler.mean_forest_tracker_, *sampler.forest_dataset_, *sampler.residual_, sampler.mean_forest_.get(), !sampler.config_.leaf_constant_mean, std::minus<double>());
118 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
119 sampler.has_mean_forest_ = true;
120 }
121 void operator()(GaussianUnivariateRegressionLeafModel& model) {
122 sampler.mean_forest_ = std::make_unique<TreeEnsemble>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
123 samples.mean_forests = std::make_unique<ForestContainer>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
124 sampler.mean_forest_tracker_ = std::make_unique<ForestTracker>(sampler.forest_dataset_->GetCovariates(), sampler.config_.feature_types, sampler.config_.num_trees_mean, sampler.data_.n_train);
125 sampler.tree_prior_mean_ = std::make_unique<TreePrior>(sampler.config_.alpha_mean, sampler.config_.beta_mean, sampler.config_.min_samples_leaf_mean, sampler.config_.max_depth_mean);
126 sampler.mean_forest_->SetLeafValue(sampler.init_val_mean_ / sampler.config_.num_trees_mean);
127 UpdateResidualEntireForest(*sampler.mean_forest_tracker_, *sampler.forest_dataset_, *sampler.residual_, sampler.mean_forest_.get(), !sampler.config_.leaf_constant_mean, std::minus<double>());
128 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
129 sampler.has_mean_forest_ = true;
130 }
131 void operator()(GaussianMultivariateRegressionLeafModel& model) {
132 sampler.mean_forest_ = std::make_unique<TreeEnsemble>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
133 samples.mean_forests = std::make_unique<ForestContainer>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
134 sampler.mean_forest_tracker_ = std::make_unique<ForestTracker>(sampler.forest_dataset_->GetCovariates(), sampler.config_.feature_types, sampler.config_.num_trees_mean, sampler.data_.n_train);
135 sampler.tree_prior_mean_ = std::make_unique<TreePrior>(sampler.config_.alpha_mean, sampler.config_.beta_mean, sampler.config_.min_samples_leaf_mean, sampler.config_.max_depth_mean);
136 sampler.mean_forest_->SetLeafVector(sampler.init_val_mean_vec_);
137 UpdateResidualEntireForest(*sampler.mean_forest_tracker_, *sampler.forest_dataset_, *sampler.residual_, sampler.mean_forest_.get(), true, std::minus<double>());
138 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
139 sampler.has_mean_forest_ = true;
140 }
141 void operator()(CloglogOrdinalLeafModel& model) {
142 sampler.mean_forest_ = std::make_unique<TreeEnsemble>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
143 samples.mean_forests = std::make_unique<ForestContainer>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
144 sampler.mean_forest_tracker_ = std::make_unique<ForestTracker>(sampler.forest_dataset_->GetCovariates(), sampler.config_.feature_types, sampler.config_.num_trees_mean, sampler.data_.n_train);
145 sampler.tree_prior_mean_ = std::make_unique<TreePrior>(sampler.config_.alpha_mean, sampler.config_.beta_mean, sampler.config_.min_samples_leaf_mean, sampler.config_.max_depth_mean);
146 sampler.mean_forest_->SetLeafValue(sampler.init_val_mean_ / sampler.config_.num_trees_mean);
147 UpdateResidualEntireForest(*sampler.mean_forest_tracker_, *sampler.forest_dataset_, *sampler.residual_, sampler.mean_forest_.get(), false, std::minus<double>());
148 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
149 sampler.has_mean_forest_ = true;
150 }
151 };
152
154 struct MeanForestResetVisitor {
155 BARTSampler& sampler;
156 BARTSamples& samples;
157 TreeEnsemble& forest;
158 void operator()(GaussianConstantLeafModel& model) {
159 sampler.mean_forest_->ReconstituteFromForest(forest);
160 sampler.mean_forest_tracker_->ReconstituteFromForest(forest, *sampler.forest_dataset_, *sampler.residual_, true);
161 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
162 }
163 void operator()(GaussianUnivariateRegressionLeafModel& model) {
164 sampler.mean_forest_->ReconstituteFromForest(forest);
165 sampler.mean_forest_tracker_->ReconstituteFromForest(forest, *sampler.forest_dataset_, *sampler.residual_, true);
166 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
167 }
168 void operator()(GaussianMultivariateRegressionLeafModel& model) {
169 sampler.mean_forest_->ReconstituteFromForest(forest);
170 sampler.mean_forest_tracker_->ReconstituteFromForest(forest, *sampler.forest_dataset_, *sampler.residual_, true);
171 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
172 }
173 void operator()(CloglogOrdinalLeafModel& model) {
174 sampler.mean_forest_->ReconstituteFromForest(forest);
175 sampler.mean_forest_tracker_->ReconstituteFromForest(forest, *sampler.forest_dataset_, *sampler.residual_, true);
176 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
177 }
178 };
179
185 struct MeanForestContinuationInitVisitor {
186 BARTSampler& sampler;
187 BARTSamples& samples; // destination container (appended to for continuation)
188 BARTSamples& source; // seed source (== samples for continuation)
189 int idx; // seed index in source.mean_forests
190 bool fresh_container; // create a fresh destination mean_forests container (previous-model warm-start)
191 void WarmStart() {
192 // Reset active forest, tracker, and tree prior
193 sampler.mean_forest_ = std::make_unique<TreeEnsemble>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
194 sampler.mean_forest_tracker_ = std::make_unique<ForestTracker>(sampler.forest_dataset_->GetCovariates(), sampler.config_.feature_types, sampler.config_.num_trees_mean, sampler.data_.n_train);
195 sampler.tree_prior_mean_ = std::make_unique<TreePrior>(sampler.config_.alpha_mean, sampler.config_.beta_mean, sampler.config_.min_samples_leaf_mean, sampler.config_.max_depth_mean);
196 if (fresh_container) {
197 samples.mean_forests = std::make_unique<ForestContainer>(sampler.config_.num_trees_mean, sampler.config_.leaf_dim_mean, sampler.config_.leaf_constant_mean, sampler.config_.exponentiated_leaf_mean);
198 }
199 sampler.has_mean_forest_ = true;
200 // Re-initialize the active forest and tracker from the seed sample
201 TreeEnsemble& seed_forest = *source.mean_forests->GetEnsemble(idx);
202 sampler.mean_forest_->ReconstituteFromForest(seed_forest);
203 sampler.mean_forest_tracker_->ReconstituteFromForest(seed_forest, *sampler.forest_dataset_, *sampler.residual_, true);
204 sampler.mean_forest_tracker_->UpdatePredictions(sampler.mean_forest_.get(), *sampler.forest_dataset_.get());
205 }
206 void operator()(GaussianConstantLeafModel& model) {
207 WarmStart();
208 }
209 void operator()(GaussianUnivariateRegressionLeafModel& model) {
210 WarmStart();
211 }
212 void operator()(GaussianMultivariateRegressionLeafModel& model) {
213 WarmStart();
214 }
215 void operator()(CloglogOrdinalLeafModel& model) {
216 // Reconstitute the forest from the last sample exactly as the Gaussian case. The tracker
217 // residual swap corrupts the cloglog residual (which holds raw y, not y - f), but
218 // InitializeState's continuation cloglog block overwrites the residual with raw y and sets the
219 // auxiliary state (eta / cutpoints) afterward; the latent is regenerated post-SetRngState.
220 WarmStart();
221 }
222 };
223
225 struct GFROneIterationVisitor {
226 BARTSampler& sampler;
227 BARTSamples& samples;
228 bool keep_sample;
229 void operator()(GaussianConstantLeafModel& model) {
231 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
232 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
233 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, sampler.config_.feature_types,
234 sampler.config_.cutpoint_grid_size, /*keep_forest=*/keep_sample,
235 /*pre_initialized=*/true, /*backfitting=*/true,
236 /*num_features_subsample=*/sampler.config_.num_features_subsample_mean, sampler.config_.num_threads);
237 }
240 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
241 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
242 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, sampler.config_.feature_types,
243 sampler.config_.cutpoint_grid_size, /*keep_forest=*/keep_sample,
244 /*pre_initialized=*/true, /*backfitting=*/true,
245 /*num_features_subsample=*/sampler.config_.num_features_subsample_mean, sampler.config_.num_threads);
246 }
249 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
250 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
251 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, sampler.config_.feature_types,
252 sampler.config_.cutpoint_grid_size, /*keep_forest=*/keep_sample,
253 /*pre_initialized=*/true, /*backfitting=*/true,
254 /*num_features_subsample=*/sampler.config_.num_features_subsample_mean, sampler.config_.num_threads,
255 sampler.config_.leaf_dim_mean);
256 }
257 void operator()(CloglogOrdinalLeafModel& model) {
259 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
260 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
261 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, sampler.config_.feature_types,
262 sampler.config_.cutpoint_grid_size, /*keep_forest=*/keep_sample,
263 /*pre_initialized=*/true, /*backfitting=*/false,
264 /*num_features_subsample=*/sampler.config_.num_features_subsample_mean, sampler.config_.num_threads);
265 }
266 };
267
269 struct MCMCOneIterationVisitor {
270 BARTSampler& sampler;
271 BARTSamples& samples;
272 bool keep_sample;
273 void operator()(GaussianConstantLeafModel& model) {
275 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
276 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
277 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, /*keep_forest=*/keep_sample,
278 /*pre_initialized=*/true, /*backfitting=*/true,
279 /*num_threads=*/sampler.config_.num_threads);
280 }
283 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
284 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
285 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, /*keep_forest=*/keep_sample,
286 /*pre_initialized=*/true, /*backfitting=*/true,
287 /*num_threads=*/sampler.config_.num_threads);
288 }
291 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
292 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
293 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, /*keep_forest=*/keep_sample,
294 /*pre_initialized=*/true, /*backfitting=*/true,
295 /*num_threads=*/sampler.config_.num_threads,
296 sampler.config_.leaf_dim_mean);
297 }
298 void operator()(CloglogOrdinalLeafModel& model) {
300 *sampler.mean_forest_, *sampler.mean_forest_tracker_, *samples.mean_forests, model,
301 *sampler.forest_dataset_, *sampler.residual_, *sampler.tree_prior_mean_, sampler.rng_,
302 sampler.config_.var_weights_mean, sampler.config_.sweep_update_indices_mean, sampler.global_variance_, /*keep_forest=*/keep_sample,
303 /*pre_initialized=*/true, /*backfitting=*/false,
304 /*num_threads=*/sampler.config_.num_threads);
305 }
306 };
307
309 struct ScaleUpdateVisitor {
310 BARTSampler& sampler;
311 double leaf_scale;
312 void operator()(GaussianConstantLeafModel& model) {
313 model.SetScale(leaf_scale);
314 }
316 model.SetScale(leaf_scale);
317 }
319 // No-op for multivariate regression leaf model since scale is a vector
320 }
321 void operator()(CloglogOrdinalLeafModel& model) {
322 // No-op for cloglog ordinal leaf model since scale is not a variance parameter
323 }
324 };
325
327 BARTConfig& config_;
328 BARTData& data_;
329
332 BARTSamples* warmstart_source_ = nullptr;
333 int warmstart_sample_num_ = 0;
334
336 std::variant<GaussianConstantLeafModel, GaussianUnivariateRegressionLeafModel, GaussianMultivariateRegressionLeafModel, CloglogOrdinalLeafModel> mean_leaf_model_;
337 LogLinearVarianceLeafModel variance_leaf_model_;
338
340 std::unique_ptr<TreeEnsemble> mean_forest_;
341 std::unique_ptr<ForestTracker> mean_forest_tracker_;
342 std::unique_ptr<TreePrior> tree_prior_mean_;
343 bool has_mean_forest_ = false;
344 double init_val_mean_;
345 std::vector<double> init_val_mean_vec_;
346 std::unique_ptr<OrdinalSampler> ordinal_sampler_;
347
349 std::unique_ptr<TreeEnsemble> variance_forest_;
350 std::unique_ptr<ForestTracker> variance_forest_tracker_;
351 std::unique_ptr<TreePrior> tree_prior_variance_;
352 bool has_variance_forest_ = false;
353 double init_val_variance_;
354
356 std::unique_ptr<MultivariateRegressionRandomEffectsModel> random_effects_model_;
357 std::unique_ptr<RandomEffectsTracker> random_effects_tracker_;
358 std::unique_ptr<RandomEffectsDataset> random_effects_dataset_;
359 bool has_random_effects_ = false;
360
362 std::unique_ptr<ColumnVector> residual_;
363 std::unique_ptr<ColumnVector> outcome_raw_;
364 std::unique_ptr<ForestDataset> forest_dataset_;
365 std::unique_ptr<ForestDataset> forest_dataset_test_;
366 bool has_test_ = false;
367
369 std::mt19937 rng_;
370
372 double global_variance_;
373 double leaf_scale_;
374 std::vector<double> leaf_scale_multivariate_;
375
376 // Global error scale model
377 std::unique_ptr<GlobalHomoskedasticVarianceModel> var_model_;
378 bool sample_sigma2_global_ = false;
379
380 // Leaf scale model
381 std::unique_ptr<LeafNodeHomoskedasticVarianceModel> leaf_scale_model_;
382 bool sample_sigma2_leaf_ = false;
383
385 struct GFRSnapshot {
386 // Forest state
387 std::unique_ptr<TreeEnsemble> mean_forest; // null if no mean forest
388 std::unique_ptr<TreeEnsemble> variance_forest; // null if no variance forest
389
390 // Global parameters
391 double sigma2;
392 double leaf_scale;
393 std::vector<double> leaf_scale_multivariate;
394
395 // Residual (incorporates forest + RFX contributions for a given sampler iteration)
396 std::vector<double> residual;
397
398 // Heteroskedastic variance model state
399 std::vector<double> variance_weights; // forest_dataset_ var_weights at snapshot time; only valid when variance_forest != null
400
401 // Cloglog model state
402 std::vector<double> cloglog_forest_preds; // cached forest predictions; only populated with cloglog link
403 std::vector<double> cloglog_latent_outcome; // cached latent outcome state; only populated with cloglog link
404 std::vector<double> cloglog_logscale_cutpoints; // cached logscale cutpoints; only populated with cloglog link and ordinal outcome
405
406 // RFX model state (only populated when has_random_effects_)
407 Eigen::VectorXd rfx_working_parameter;
408 Eigen::MatrixXd rfx_group_parameters;
409 Eigen::MatrixXd rfx_group_parameter_covariance;
410 Eigen::MatrixXd rfx_working_parameter_covariance;
411 double rfx_variance_prior_shape;
412 double rfx_variance_prior_scale;
413 };
414
416 std::vector<GFRSnapshot> gfr_snapshots_;
417};
418
419} // namespace StochTree
420
421#endif // STOCHTREE_BART_SAMPLER_H_
Definition bart_sampler.h:31
Marginal likelihood and posterior computation for complementary log-log ordinal BART model.
Definition leaf_model.h:1123
Marginal likelihood and posterior computation for gaussian homoskedastic constant leaf outcome model.
Definition leaf_model.h:458
Marginal likelihood and posterior computation for gaussian homoskedastic constant leaf outcome model.
Definition leaf_model.h:797
Marginal likelihood and posterior computation for gaussian homoskedastic constant leaf outcome model.
Definition leaf_model.h:626
Marginal likelihood and posterior computation for heteroskedastic log-linear variance model.
Definition leaf_model.h:942
Class storing a "forest," or an ensemble of decision trees.
Definition ensemble.h:31
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
Definition bart.h:53
Definition bart.h:22
Definition bart.h:125