StochTree 0.5.0.9000
Loading...
Searching...
No Matches
ordinal_sampler.h
1
5#ifndef STOCHTREE_ORDINAL_SAMPLER_H_
6#define STOCHTREE_ORDINAL_SAMPLER_H_
7
8#include <stochtree/data.h>
9#include <stochtree/ensemble.h>
10#include <stochtree/gamma_sampler.h>
11#include <stochtree/partition_tracker.h>
12#include <stochtree/tree.h>
13
14#include <Eigen/Dense>
15#include <random>
16
17namespace StochTree {
18
19static double sample_truncated_exponential_low_high(double u, double rate, double low, double high) {
20 return -std::log((1 - u) * std::exp(-rate * low) + u * std::exp(-rate * high)) / rate;
21}
22
23static double sample_truncated_exponential_low(double u, double rate, double low) {
24 return -std::log((1 - u) * std::exp(-rate * low)) / rate;
25}
26
27static double sample_truncated_exponential_high(double u, double rate, double high) {
28 return -std::log1p(u * std::expm1(-high * rate)) / rate;
29}
30
31static double sample_exponential(double u, double rate) {
32 return -std::log1p(-u) / rate;
33}
34
44 public:
46 gamma_sampler_ = GammaSampler();
47 }
49
61 static double SampleTruncatedExponential(std::mt19937& gen, double rate, double low = 0.0, double high = 1.0);
62
70 void UpdateLatentVariables(ForestDataset& dataset, Eigen::VectorXd& outcome, std::mt19937& gen);
71
83 double alpha_gamma, double beta_gamma,
84 double gamma_0, std::mt19937& gen);
85
92
93 private:
94 GammaSampler gamma_sampler_;
95};
96
97} // namespace StochTree
98
99#endif // STOCHTREE_ORDINAL_SAMPLER_H_
API for loading and accessing data used to sample tree ensembles The covariates / bases / weights use...
Definition data.h:272
Definition gamma_sampler.h:10
Sampler for ordinal model hyperparameters.
Definition ordinal_sampler.h:43
void UpdateCumulativeExpSums(ForestDataset &dataset)
Update cumulative exponential sums (seg)
void UpdateLatentVariables(ForestDataset &dataset, Eigen::VectorXd &outcome, std::mt19937 &gen)
Update truncated exponential latent variables (Z)
static double SampleTruncatedExponential(std::mt19937 &gen, double rate, double low=0.0, double high=1.0)
Sample from truncated exponential distribution.
void UpdateGammaParams(ForestDataset &dataset, Eigen::VectorXd &outcome, double alpha_gamma, double beta_gamma, double gamma_0, std::mt19937 &gen)
Update gamma cutpoint parameters.
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