5#ifndef STOCHTREE_LEAF_MODEL_H_
6#define STOCHTREE_LEAF_MODEL_H_
9#include <stochtree/cutpoint_candidates.h>
10#include <stochtree/data.h>
11#include <stochtree/gamma_sampler.h>
12#include <stochtree/ig_sampler.h>
13#include <stochtree/log.h>
14#include <stochtree/meta.h>
15#include <stochtree/normal_sampler.h>
16#include <stochtree/openmp_utils.h>
17#include <stochtree/partition_tracker.h>
18#include <stochtree/prior.h>
19#include <stochtree/tree.h>
353 kConstantLeafGaussian,
354 kUnivariateRegressionLeafGaussian,
355 kMultivariateRegressionLeafGaussian,
390 sum_yw += outcome(row_idx, 0);
408 sum_w += suff_stat.sum_w;
409 sum_yw += suff_stat.sum_yw;
419 sum_w = lhs.sum_w + rhs.sum_w;
420 sum_yw = lhs.sum_yw + rhs.sum_yw;
430 sum_w = lhs.sum_w - rhs.sum_w;
431 sum_yw = lhs.sum_yw - rhs.sum_yw;
439 return n > threshold;
447 return n >= threshold;
558 sum_yxw += outcome(row_idx, 0) * dataset.
BasisValue(row_idx, 0);
576 sum_xxw += suff_stat.sum_xxw;
577 sum_yxw += suff_stat.sum_yxw;
587 sum_xxw = lhs.sum_xxw + rhs.sum_xxw;
588 sum_yxw = lhs.sum_yxw + rhs.sum_yxw;
598 sum_xxw = lhs.sum_xxw - rhs.sum_xxw;
599 sum_yxw = lhs.sum_yxw - rhs.sum_yxw;
607 return n > threshold;
615 return n >= threshold;
626class GaussianUnivariateRegressionLeafModel {
628 GaussianUnivariateRegressionLeafModel(
double tau) {
632 ~GaussianUnivariateRegressionLeafModel() {}
675 void SetScale(
double tau) { tau_ = tau; }
676 inline bool RequiresBasis() {
return true; }
680 UnivariateNormalSampler normal_sampler_;
688 Eigen::MatrixXd XtWX;
689 Eigen::MatrixXd ytWX;
697 XtWX = Eigen::MatrixXd::Zero(basis_dim, basis_dim);
698 ytWX = Eigen::MatrixXd::Zero(1, basis_dim);
713 for (
int i = 0; i < p; i++) {
715 for (
int j = 0; j < p; j++) {
720 for (
int i = 0; i < p; i++) {
721 ytWX(0, i) += outcome(row_idx, 0) * dataset.
BasisValue(row_idx, i);
722 for (
int j = 0; j < p; j++) {
733 for (
int i = 0; i < p; i++) {
735 for (
int j = 0; j < p; j++) {
747 XtWX += suff_stat.XtWX;
748 ytWX += suff_stat.ytWX;
758 XtWX = lhs.XtWX + rhs.XtWX;
759 ytWX = lhs.ytWX + rhs.ytWX;
769 XtWX = lhs.XtWX - rhs.XtWX;
770 ytWX = lhs.ytWX - rhs.ytWX;
778 return n > threshold;
786 return n >= threshold;
851 void SetScale(Eigen::MatrixXd& Sigma_0) { Sigma_0_ = Sigma_0; }
852 inline bool RequiresBasis() {
return true; }
855 Eigen::MatrixXd Sigma_0_;
856 MultivariateNormalSampler multivariate_normal_sampler_;
860class LogLinearVarianceSuffStat {
863 double weighted_sum_ei;
864 LogLinearVarianceSuffStat() {
866 weighted_sum_ei = 0.0;
879 weighted_sum_ei += std::exp(std::log(outcome(row_idx) * outcome(row_idx)) - tracker.GetSamplePrediction(row_idx) + tracker.GetTreeSamplePrediction(row_idx, tree_idx));
886 weighted_sum_ei = 0.0;
895 weighted_sum_ei += suff_stat.weighted_sum_ei;
903 void AddSuffStat(LogLinearVarianceSuffStat& lhs, LogLinearVarianceSuffStat& rhs) {
905 weighted_sum_ei = lhs.weighted_sum_ei + rhs.weighted_sum_ei;
915 weighted_sum_ei = lhs.weighted_sum_ei - rhs.weighted_sum_ei;
923 return n > threshold;
931 return n >= threshold;
942class LogLinearVarianceLeafModel {
944 LogLinearVarianceLeafModel(
double a,
double b) {
949 ~LogLinearVarianceLeafModel() {}
993 void SetPriorShape(
double a) { a_ = a; }
994 void SetPriorRate(
double b) { b_ = b; }
995 inline bool RequiresBasis() {
return false; }
1000 GammaSampler gamma_sampler_;
1007 double sum_Y_less_K;
1032 unsigned int y =
static_cast<unsigned int>(outcome(row_idx));
1035 double Z = dataset.GetAuxiliaryDataValue(0, row_idx);
1036 double lambda_minus = dataset.GetAuxiliaryDataValue(1, row_idx);
1039 const std::vector<double>& gamma = dataset.GetAuxiliaryDataVectorConst(2);
1040 const std::vector<double>& seg = dataset.GetAuxiliaryDataVectorConst(3);
1042 int K = gamma.size() + 1;
1045 other_sum += std::exp(lambda_minus) * seg[y];
1047 sum_Y_less_K += 1.0;
1048 other_sum += std::exp(lambda_minus) * (Z * std::exp(gamma[y]) + seg[y]);
1068 sum_Y_less_K += suff_stat.sum_Y_less_K;
1069 other_sum += suff_stat.other_sum;
1080 sum_Y_less_K = lhs.sum_Y_less_K + rhs.sum_Y_less_K;
1081 other_sum = lhs.other_sum + rhs.other_sum;
1092 sum_Y_less_K = lhs.sum_Y_less_K - rhs.sum_Y_less_K;
1093 other_sum = lhs.other_sum - rhs.other_sum;
1102 return n > threshold;
1111 return n >= threshold;
1169 inline bool RequiresBasis() {
return false; }
1204template <
typename SuffStatType,
typename... SuffStatConstructorArgs>
1205static inline SuffStatVariant createSuffStat(SuffStatConstructorArgs... leaf_suff_stat_args) {
1206 return SuffStatType(leaf_suff_stat_args...);
1209template <
typename LeafModelType,
typename... LeafModelConstructorArgs>
1210static inline LeafModelVariant createLeafModel(LeafModelConstructorArgs... leaf_model_args) {
1211 return LeafModelType(leaf_model_args...);
1221 if (model_type == kConstantLeafGaussian) {
1222 return createSuffStat<GaussianConstantSuffStat>();
1223 }
else if (model_type == kUnivariateRegressionLeafGaussian) {
1224 return createSuffStat<GaussianUnivariateRegressionSuffStat>();
1225 }
else if (model_type == kMultivariateRegressionLeafGaussian) {
1226 return createSuffStat<GaussianMultivariateRegressionSuffStat, int>(basis_dim);
1227 }
else if (model_type == kLogLinearVariance) {
1228 return createSuffStat<LogLinearVarianceSuffStat>();
1230 return createSuffStat<CloglogOrdinalSuffStat>();
1244 if (model_type == kConstantLeafGaussian) {
1245 return createLeafModel<GaussianConstantLeafModel, double>(tau);
1246 }
else if (model_type == kUnivariateRegressionLeafGaussian) {
1247 return createLeafModel<GaussianUnivariateRegressionLeafModel, double>(tau);
1248 }
else if (model_type == kMultivariateRegressionLeafGaussian) {
1249 return createLeafModel<GaussianMultivariateRegressionLeafModel, Eigen::MatrixXd>(Sigma0);
1250 }
else if (model_type == kLogLinearVariance) {
1251 return createLeafModel<LogLinearVarianceLeafModel, double, double>(a, b);
1253 return createLeafModel<CloglogOrdinalLeafModel, double, double>(a, b);
1257template <
typename SuffStatType,
typename... SuffStatConstructorArgs>
1258static inline void AccumulateSuffStatProposed(
1259 SuffStatType& node_suff_stat, SuffStatType& left_suff_stat, SuffStatType& right_suff_stat, ForestDataset& dataset, ForestTracker& tracker,
1260 ColumnVector& residual,
double global_variance, TreeSplit& split,
int tree_num,
int leaf_num,
int split_feature,
int num_threads,
1261 SuffStatConstructorArgs&... suff_stat_args) {
1263 int node_begin_index = tracker.UnsortedNodeBegin(tree_num, leaf_num);
1264 int node_end_index = tracker.UnsortedNodeEnd(tree_num, leaf_num);
1267 UnsortedNodeSampleTracker* unsorted_node_sample_tracker = tracker.GetUnsortedNodeSampleTracker();
1268 FeatureUnsortedPartition* feature_partition = unsorted_node_sample_tracker->GetFeaturePartition(tree_num);
1271 int chunk_size = (node_end_index - node_begin_index) / num_threads;
1272 if (chunk_size < 100) {
1274 chunk_size = node_end_index - node_begin_index;
1277 if (num_threads > 1) {
1279 std::vector<std::pair<int, int>> thread_ranges(num_threads);
1280 std::vector<SuffStatType> thread_suff_stats_node;
1281 std::vector<SuffStatType> thread_suff_stats_left;
1282 std::vector<SuffStatType> thread_suff_stats_right;
1283 for (
int i = 0; i < num_threads; i++) {
1284 thread_ranges[i] = std::make_pair(node_begin_index + i * chunk_size,
1285 node_begin_index + (i + 1) * chunk_size);
1286 thread_suff_stats_node.emplace_back(suff_stat_args...);
1287 thread_suff_stats_left.emplace_back(suff_stat_args...);
1288 thread_suff_stats_right.emplace_back(suff_stat_args...);
1292 StochTree::ParallelFor(0, num_threads, num_threads, [&](
int i) {
1293 int start_idx = thread_ranges[i].first;
1294 int end_idx = thread_ranges[i].second;
1295 for (
int idx = start_idx; idx < end_idx; idx++) {
1296 int obs_num = feature_partition->indices_[idx];
1297 double feature_value = dataset.CovariateValue(obs_num, split_feature);
1298 thread_suff_stats_node[i].IncrementSuffStat(dataset, residual.GetData(), tracker, obs_num, tree_num);
1299 if (split.SplitTrue(feature_value)) {
1300 thread_suff_stats_left[i].IncrementSuffStat(dataset, residual.GetData(), tracker, obs_num, tree_num);
1302 thread_suff_stats_right[i].IncrementSuffStat(dataset, residual.GetData(), tracker, obs_num, tree_num);
1308 for (
int i = 0; i < num_threads; i++) {
1309 node_suff_stat.AddSuffStatInplace(thread_suff_stats_node[i]);
1310 left_suff_stat.AddSuffStatInplace(thread_suff_stats_left[i]);
1311 right_suff_stat.AddSuffStatInplace(thread_suff_stats_right[i]);
1314 for (
int idx = node_begin_index; idx < node_end_index; idx++) {
1315 int obs_num = feature_partition->indices_[idx];
1316 double feature_value = dataset.CovariateValue(obs_num, split_feature);
1317 node_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, obs_num, tree_num);
1318 if (split.SplitTrue(feature_value)) {
1319 left_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, obs_num, tree_num);
1321 right_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, obs_num, tree_num);
1327template <
typename SuffStatType>
1328static inline void AccumulateSuffStatExisting(SuffStatType& node_suff_stat, SuffStatType& left_suff_stat, SuffStatType& right_suff_stat,
ForestDataset& dataset,
ForestTracker& tracker,
1329 ColumnVector& residual,
double global_variance,
int tree_num,
int split_node_id,
int left_node_id,
int right_node_id) {
1331 auto left_node_begin_iter = tracker.UnsortedNodeBeginIterator(tree_num, left_node_id);
1332 auto left_node_end_iter = tracker.UnsortedNodeEndIterator(tree_num, left_node_id);
1333 auto right_node_begin_iter = tracker.UnsortedNodeBeginIterator(tree_num, right_node_id);
1334 auto right_node_end_iter = tracker.UnsortedNodeEndIterator(tree_num, right_node_id);
1337 for (
auto i = left_node_begin_iter; i != left_node_end_iter; i++) {
1339 left_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, idx, tree_num);
1340 node_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, idx, tree_num);
1344 for (
auto i = right_node_begin_iter; i != right_node_end_iter; i++) {
1346 right_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, idx, tree_num);
1347 node_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, idx, tree_num);
1351template <
typename SuffStatType,
bool sorted>
1354 std::vector<data_size_t>::iterator node_begin_iter;
1355 std::vector<data_size_t>::iterator node_end_iter;
1358 node_begin_iter = tracker.SortedNodeBeginIterator(node_id, 0);
1359 node_end_iter = tracker.SortedNodeEndIterator(node_id, 0);
1361 node_begin_iter = tracker.UnsortedNodeBeginIterator(tree_num, node_id);
1362 node_end_iter = tracker.UnsortedNodeEndIterator(tree_num, node_id);
1366 for (
auto i = node_begin_iter; i != node_end_iter; i++) {
1368 node_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, idx, tree_num);
1372template <
typename SuffStatType>
1375 int feature_num,
int cutpoint_num) {
1377 auto node_begin_iter = tracker.SortedNodeBeginIterator(node_id, feature_num);
1378 auto node_end_iter = tracker.SortedNodeEndIterator(node_id, feature_num);
1381 data_size_t node_begin = tracker.SortedNodeBegin(node_id, feature_num);
1384 data_size_t current_bin_begin = cutpoint_grid_container.BinStartIndex(cutpoint_num, feature_num);
1385 data_size_t current_bin_size = cutpoint_grid_container.BinLength(cutpoint_num, feature_num);
1386 data_size_t next_bin_begin = cutpoint_grid_container.BinStartIndex(cutpoint_num + 1, feature_num);
1390 auto cutpoint_begin_iter = node_begin_iter + (current_bin_begin - node_begin);
1391 auto cutpoint_end_iter = node_begin_iter + (next_bin_begin - node_begin);
1394 for (
auto i = cutpoint_begin_iter; i != cutpoint_end_iter; i++) {
1396 left_suff_stat.IncrementSuffStat(dataset, residual.GetData(), tracker, idx, tree_num);
Marginal likelihood and posterior computation for complementary log-log ordinal BART model.
Definition leaf_model.h:1123
CloglogOrdinalLeafModel(double a, double b)
Construct a new CloglogOrdinalLeafModel object.
Definition leaf_model.h:1132
double SplitLogMarginalLikelihood(CloglogOrdinalSuffStat &left_stat, CloglogOrdinalSuffStat &right_stat, double global_variance)
Log marginal likelihood for a proposed split, evaluated only for observations that fall into the node...
double SuffStatLogMarginalLikelihood(CloglogOrdinalSuffStat &suff_stat, double global_variance)
Helper function to compute log marginal likelihood from sufficient statistics.
double PosteriorParameterShape(CloglogOrdinalSuffStat &suff_stat, double global_variance)
Posterior shape parameter for leaf node log-gamma distribution.
double PosteriorParameterRate(CloglogOrdinalSuffStat &suff_stat, double global_variance)
Posterior rate parameter for leaf node log-gamma distribution.
void SampleLeafParameters(ForestDataset &dataset, ForestTracker &tracker, ColumnVector &residual, Tree *tree, int tree_num, double global_variance, std::mt19937 &gen)
Draw new parameters for every leaf node in tree, using a Gibbs update that conditions on the data,...
double NoSplitLogMarginalLikelihood(CloglogOrdinalSuffStat &suff_stat, double global_variance)
Log marginal likelihood of a node, evaluated only for observations that fall into the node being spli...
Sufficient statistic and associated operations for complementary log-log ordinal BART model.
Definition leaf_model.h:1004
bool SampleGreaterThan(data_size_t threshold)
Check whether accumulated sample size, n, is greater than some threshold.
Definition leaf_model.h:1101
void AddSuffStat(CloglogOrdinalSuffStat &lhs, CloglogOrdinalSuffStat &rhs)
Set the value of each sufficient statistic to the sum of the values provided by lhs and rhs.
Definition leaf_model.h:1078
CloglogOrdinalSuffStat()
Construct a new CloglogOrdinalSuffStat object, setting all sufficient statistics to zero.
Definition leaf_model.h:1013
void SubtractSuffStat(CloglogOrdinalSuffStat &lhs, CloglogOrdinalSuffStat &rhs)
Set the value of each sufficient statistic to the difference between the values provided by lhs and t...
Definition leaf_model.h:1090
void ResetSuffStat()
Reset all of the sufficient statistics to zero.
Definition leaf_model.h:1055
void AddSuffStatInplace(CloglogOrdinalSuffStat &suff_stat)
Increment the value of each sufficient statistic by the values provided by suff_stat.
Definition leaf_model.h:1066
data_size_t SampleSize()
Return the sample size accumulated by a sufficient stat object.
Definition leaf_model.h:1117
bool SampleGreaterThanEqual(data_size_t threshold)
Check whether accumulated sample size, n, is greater than or equal to some threshold.
Definition leaf_model.h:1110
void IncrementSuffStat(ForestDataset &dataset, Eigen::VectorXd &outcome, ForestTracker &tracker, data_size_t row_idx, int tree_idx)
Accumulate data from observation row_idx into the sufficient statistics.
Definition leaf_model.h:1028
Internal wrapper around Eigen::VectorXd interface for univariate floating point data....
Definition data.h:193
Container class for FeatureCutpointGrid objects stored for every feature in a dataset.
Definition cutpoint_candidates.h:110
API for loading and accessing data used to sample tree ensembles The covariates / bases / weights use...
Definition data.h:272
double BasisValue(data_size_t row, int col)
Returns a dataset's basis value stored at (row, col).
Definition data.h:372
double VarWeightValue(data_size_t row)
Returns a dataset's variance weight stored at element row.
Definition data.h:378
bool HasVarWeights()
Whether or not a ForestDataset has (yet) loaded variance weights.
Definition data.h:352
"Superclass" wrapper around tracking data structures for forest sampling algorithms
Definition partition_tracker.h:46
Definition gamma_sampler.h:10
Marginal likelihood and posterior computation for gaussian homoskedastic constant leaf outcome model.
Definition leaf_model.h:458
double SplitLogMarginalLikelihood(GaussianConstantSuffStat &left_stat, GaussianConstantSuffStat &right_stat, double global_variance)
Log marginal likelihood for a proposed split, evaluated only for observations that fall into the node...
double PosteriorParameterVariance(GaussianConstantSuffStat &suff_stat, double global_variance)
Leaf node posterior variance.
void SampleLeafParameters(ForestDataset &dataset, ForestTracker &tracker, ColumnVector &residual, Tree *tree, int tree_num, double global_variance, std::mt19937 &gen)
Draw new parameters for every leaf node in tree, using a Gibbs update that conditions on the data,...
double NoSplitLogMarginalLikelihood(GaussianConstantSuffStat &suff_stat, double global_variance)
Log marginal likelihood of a node, evaluated only for observations that fall into the node being spli...
bool RequiresBasis()
Whether this model requires a basis vector for posterior inference and prediction.
Definition leaf_model.h:521
GaussianConstantLeafModel(double tau)
Construct a new GaussianConstantLeafModel object.
Definition leaf_model.h:465
double PosteriorParameterMean(GaussianConstantSuffStat &suff_stat, double global_variance)
Leaf node posterior mean.
void SetScale(double tau)
Set a new value for the leaf node scale parameter.
Definition leaf_model.h:517
Sufficient statistic and associated operations for gaussian homoskedastic constant leaf outcome model...
Definition leaf_model.h:361
data_size_t SampleSize()
Return the sample size accumulated by a sufficient stat object.
Definition leaf_model.h:452
GaussianConstantSuffStat()
Construct a new GaussianConstantSuffStat object, setting all sufficient statistics to zero.
Definition leaf_model.h:369
void SubtractSuffStat(GaussianConstantSuffStat &lhs, GaussianConstantSuffStat &rhs)
Set the value of each sufficient statistic to the difference between the values provided by lhs and t...
Definition leaf_model.h:428
void AddSuffStat(GaussianConstantSuffStat &lhs, GaussianConstantSuffStat &rhs)
Set the value of each sufficient statistic to the sum of the values provided by lhs and rhs.
Definition leaf_model.h:417
void AddSuffStatInplace(GaussianConstantSuffStat &suff_stat)
Increment the value of each sufficient statistic by the values provided by suff_stat.
Definition leaf_model.h:406
bool SampleGreaterThanEqual(data_size_t threshold)
Check whether accumulated sample size, n, is greater than or equal to some threshold.
Definition leaf_model.h:446
bool SampleGreaterThan(data_size_t threshold)
Check whether accumulated sample size, n, is greater than some threshold.
Definition leaf_model.h:438
void IncrementSuffStat(ForestDataset &dataset, Eigen::VectorXd &outcome, ForestTracker &tracker, data_size_t row_idx, int tree_idx)
Accumulate data from observation row_idx into the sufficient statistics.
Definition leaf_model.h:383
void ResetSuffStat()
Reset all of the sufficient statistics to zero.
Definition leaf_model.h:396
Marginal likelihood and posterior computation for gaussian homoskedastic constant leaf outcome model.
Definition leaf_model.h:797
void SampleLeafParameters(ForestDataset &dataset, ForestTracker &tracker, ColumnVector &residual, Tree *tree, int tree_num, double global_variance, std::mt19937 &gen)
Draw new parameters for every leaf node in tree, using a Gibbs update that conditions on the data,...
Eigen::MatrixXd PosteriorParameterVariance(GaussianMultivariateRegressionSuffStat &suff_stat, double global_variance)
Leaf node posterior variance.
double SplitLogMarginalLikelihood(GaussianMultivariateRegressionSuffStat &left_stat, GaussianMultivariateRegressionSuffStat &right_stat, double global_variance)
Log marginal likelihood for a proposed split, evaluated only for observations that fall into the node...
GaussianMultivariateRegressionLeafModel(Eigen::MatrixXd &Sigma_0)
Construct a new GaussianMultivariateRegressionLeafModel object.
Definition leaf_model.h:804
Eigen::VectorXd PosteriorParameterMean(GaussianMultivariateRegressionSuffStat &suff_stat, double global_variance)
Leaf node posterior mean.
double NoSplitLogMarginalLikelihood(GaussianMultivariateRegressionSuffStat &suff_stat, double global_variance)
Log marginal likelihood of a node, evaluated only for observations that fall into the node being spli...
Sufficient statistic and associated operations for gaussian homoskedastic constant leaf outcome model...
Definition leaf_model.h:684
void AddSuffStatInplace(GaussianMultivariateRegressionSuffStat &suff_stat)
Increment the value of each sufficient statistic by the values provided by suff_stat.
Definition leaf_model.h:745
bool SampleGreaterThan(data_size_t threshold)
Check whether accumulated sample size, n, is greater than some threshold.
Definition leaf_model.h:777
data_size_t SampleSize()
Return the sample size accumulated by a sufficient stat object.
Definition leaf_model.h:791
void AddSuffStat(GaussianMultivariateRegressionSuffStat &lhs, GaussianMultivariateRegressionSuffStat &rhs)
Set the value of each sufficient statistic to the sum of the values provided by lhs and rhs.
Definition leaf_model.h:756
void SubtractSuffStat(GaussianMultivariateRegressionSuffStat &lhs, GaussianMultivariateRegressionSuffStat &rhs)
Set the value of each sufficient statistic to the difference between the values provided by lhs and t...
Definition leaf_model.h:767
bool SampleGreaterThanEqual(data_size_t threshold)
Check whether accumulated sample size, n, is greater than or equal to some threshold.
Definition leaf_model.h:785
void ResetSuffStat()
Reset all of the sufficient statistics to zero.
Definition leaf_model.h:731
GaussianMultivariateRegressionSuffStat(int basis_dim)
Construct a new GaussianMultivariateRegressionSuffStat object.
Definition leaf_model.h:695
void IncrementSuffStat(ForestDataset &dataset, Eigen::VectorXd &outcome, ForestTracker &tracker, data_size_t row_idx, int tree_idx)
Accumulate data from observation row_idx into the sufficient statistics.
Definition leaf_model.h:710
Marginal likelihood and posterior computation for gaussian homoskedastic constant leaf outcome model.
Definition leaf_model.h:626
double SplitLogMarginalLikelihood(GaussianUnivariateRegressionSuffStat &left_stat, GaussianUnivariateRegressionSuffStat &right_stat, double global_variance)
Log marginal likelihood for a proposed split, evaluated only for observations that fall into the node...
void SampleLeafParameters(ForestDataset &dataset, ForestTracker &tracker, ColumnVector &residual, Tree *tree, int tree_num, double global_variance, std::mt19937 &gen)
Draw new parameters for every leaf node in tree, using a Gibbs update that conditions on the data,...
double PosteriorParameterVariance(GaussianUnivariateRegressionSuffStat &suff_stat, double global_variance)
Leaf node posterior variance.
double PosteriorParameterMean(GaussianUnivariateRegressionSuffStat &suff_stat, double global_variance)
Leaf node posterior mean.
double NoSplitLogMarginalLikelihood(GaussianUnivariateRegressionSuffStat &suff_stat, double global_variance)
Log marginal likelihood of a node, evaluated only for observations that fall into the node being spli...
Sufficient statistic and associated operations for gaussian homoskedastic constant leaf outcome model...
Definition leaf_model.h:529
GaussianUnivariateRegressionSuffStat()
Construct a new GaussianUnivariateRegressionSuffStat object, setting all sufficient statistics to zer...
Definition leaf_model.h:537
void SubtractSuffStat(GaussianUnivariateRegressionSuffStat &lhs, GaussianUnivariateRegressionSuffStat &rhs)
Set the value of each sufficient statistic to the difference between the values provided by lhs and t...
Definition leaf_model.h:596
bool SampleGreaterThan(data_size_t threshold)
Check whether accumulated sample size, n, is greater than some threshold.
Definition leaf_model.h:606
bool SampleGreaterThanEqual(data_size_t threshold)
Check whether accumulated sample size, n, is greater than or equal to some threshold.
Definition leaf_model.h:614
data_size_t SampleSize()
Return the sample size accumulated by a sufficient stat object.
Definition leaf_model.h:620
void ResetSuffStat()
Reset all of the sufficient statistics to zero.
Definition leaf_model.h:564
void AddSuffStat(GaussianUnivariateRegressionSuffStat &lhs, GaussianUnivariateRegressionSuffStat &rhs)
Set the value of each sufficient statistic to the sum of the values provided by lhs and rhs.
Definition leaf_model.h:585
void AddSuffStatInplace(GaussianUnivariateRegressionSuffStat &suff_stat)
Increment the value of each sufficient statistic by the values provided by suff_stat.
Definition leaf_model.h:574
void IncrementSuffStat(ForestDataset &dataset, Eigen::VectorXd &outcome, ForestTracker &tracker, data_size_t row_idx, int tree_idx)
Accumulate data from observation row_idx into the sufficient statistics.
Definition leaf_model.h:551
Marginal likelihood and posterior computation for heteroskedastic log-linear variance model.
Definition leaf_model.h:942
double NoSplitLogMarginalLikelihood(LogLinearVarianceSuffStat &suff_stat, double global_variance)
Log marginal likelihood of a node, evaluated only for observations that fall into the node being spli...
double PosteriorParameterShape(LogLinearVarianceSuffStat &suff_stat, double global_variance)
Leaf node posterior shape parameter.
void SampleLeafParameters(ForestDataset &dataset, ForestTracker &tracker, ColumnVector &residual, Tree *tree, int tree_num, double global_variance, std::mt19937 &gen)
Draw new parameters for every leaf node in tree, using a Gibbs update that conditions on the data,...
double SplitLogMarginalLikelihood(LogLinearVarianceSuffStat &left_stat, LogLinearVarianceSuffStat &right_stat, double global_variance)
Log marginal likelihood for a proposed split, evaluated only for observations that fall into the node...
double PosteriorParameterScale(LogLinearVarianceSuffStat &suff_stat, double global_variance)
Leaf node posterior scale parameter.
Sufficient statistic and associated operations for heteroskedastic log-linear variance model.
Definition leaf_model.h:860
bool SampleGreaterThanEqual(data_size_t threshold)
Check whether accumulated sample size, n, is greater than or equal to some threshold.
Definition leaf_model.h:930
void SubtractSuffStat(LogLinearVarianceSuffStat &lhs, LogLinearVarianceSuffStat &rhs)
Set the value of each sufficient statistic to the difference between the values provided by lhs and t...
Definition leaf_model.h:913
void ResetSuffStat()
Reset all of the sufficient statistics to zero.
Definition leaf_model.h:884
data_size_t SampleSize()
Return the sample size accumulated by a sufficient stat object.
Definition leaf_model.h:936
void IncrementSuffStat(ForestDataset &dataset, Eigen::VectorXd &outcome, ForestTracker &tracker, data_size_t row_idx, int tree_idx)
Accumulate data from observation row_idx into the sufficient statistics.
Definition leaf_model.h:877
void AddSuffStatInplace(LogLinearVarianceSuffStat &suff_stat)
Increment the value of each sufficient statistic by the values provided by suff_stat.
Definition leaf_model.h:893
bool SampleGreaterThan(data_size_t threshold)
Check whether accumulated sample size, n, is greater than some threshold.
Definition leaf_model.h:922
void AddSuffStat(LogLinearVarianceSuffStat &lhs, LogLinearVarianceSuffStat &rhs)
Set the value of each sufficient statistic to the sum of the values provided by lhs and rhs.
Definition leaf_model.h:903
Definition normal_sampler.h:26
Class storing a "forest," or an ensemble of decision trees.
Definition ensemble.h:31
Decision tree data structure.
Definition tree.h:66
Definition normal_sampler.h:13
std::variant< GaussianConstantLeafModel, GaussianUnivariateRegressionLeafModel, GaussianMultivariateRegressionLeafModel, LogLinearVarianceLeafModel, CloglogOrdinalLeafModel > LeafModelVariant
Unifying layer for disparate leaf model class types.
Definition leaf_model.h:1198
static SuffStatVariant suffStatFactory(ModelType model_type, int basis_dim=0)
Factory function that creates a new SuffStat object for the specified model type.
Definition leaf_model.h:1220
std::variant< GaussianConstantSuffStat, GaussianUnivariateRegressionSuffStat, GaussianMultivariateRegressionSuffStat, LogLinearVarianceSuffStat, CloglogOrdinalSuffStat > SuffStatVariant
Unifying layer for disparate sufficient statistic class types.
Definition leaf_model.h:1184
ModelType
Leaf models for the forest sampler:
Definition leaf_model.h:352
static LeafModelVariant leafModelFactory(ModelType model_type, double tau, Eigen::MatrixXd &Sigma0, double a, double b)
Factory function that creates a new LeafModel object for the specified model type.
Definition leaf_model.h:1243
A collection of random number generation utilities.
Definition bart.h:15