34 ForestContainer(
int num_trees,
int output_dimension = 1,
bool is_leaf_constant =
true,
bool is_exponentiated =
false);
44 ForestContainer(
int num_samples,
int num_trees,
int output_dimension = 1,
bool is_leaf_constant =
true,
bool is_exponentiated =
false);
52 void MergeForests(
int inbound_forest_index,
int outbound_forest_index) {
53 forests_[inbound_forest_index]->MergeForest(*forests_[outbound_forest_index]);
62 forests_[forest_index]->AddValueToLeaves(constant_value);
71 forests_[forest_index]->MultiplyLeavesByValue(constant_multiple);
136 std::vector<double> PredictRawSingleTree(
ForestDataset& dataset,
int forest_num,
int tree_num);
137 void PredictInPlace(
ForestDataset& dataset, std::vector<double>& output);
138 void PredictRawInPlace(
ForestDataset& dataset, std::vector<double>& output,
bool row_major =
true);
139 void PredictRawInPlace(
ForestDataset& dataset,
int forest_num, std::vector<double>& output);
140 void PredictRawSingleTreeInPlace(
ForestDataset& dataset,
int forest_num,
int tree_num, std::vector<double>& output);
141 void PredictLeafIndicesInplace(Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>>& covariates,
142 Eigen::Map<Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>>& output,
143 std::vector<int>& forest_indices,
int num_trees, data_size_t n);
145 inline TreeEnsemble* GetEnsemble(
int i) {
return forests_[i].get(); }
146 inline int32_t NumSamples() {
return num_samples_; }
147 inline int32_t NumTrees() {
return num_trees_; }
148 inline int32_t NumTrees(
int ensemble_num) {
return forests_[ensemble_num]->NumTrees(); }
149 inline int32_t NumLeaves(
int ensemble_num) {
return forests_[ensemble_num]->NumLeaves(); }
150 inline int32_t EnsembleTreeMaxDepth(
int ensemble_num,
int tree_num) {
return forests_[ensemble_num]->TreeMaxDepth(tree_num); }
151 inline double EnsembleAverageMaxDepth(
int ensemble_num) {
return forests_[ensemble_num]->AverageMaxDepth(); }
152 inline double AverageMaxDepth() {
153 double numerator = 0.;
154 double denominator = 0.;
155 for (
int i = 0; i < num_samples_; i++) {
156 for (
int j = 0; j < num_trees_; j++) {
157 numerator +=
static_cast<double>(forests_[i]->TreeMaxDepth(j));
161 return numerator / denominator;
163 inline int32_t OutputDimension() {
return output_dimension_; }
164 inline int32_t OutputDimension(
int ensemble_num) {
return forests_[ensemble_num]->OutputDimension(); }
165 inline bool IsLeafConstant() {
return is_leaf_constant_; }
166 inline bool IsLeafConstant(
int ensemble_num) {
return forests_[ensemble_num]->IsLeafConstant(); }
167 inline bool IsExponentiated() {
return is_exponentiated_; }
168 inline bool IsExponentiated(
int ensemble_num) {
return forests_[ensemble_num]->IsExponentiated(); }
169 inline bool AllRoots(
int ensemble_num) {
return forests_[ensemble_num]->AllRoots(); }
170 inline void SetLeafValue(
int ensemble_num,
double leaf_value) { forests_[ensemble_num]->SetLeafValue(leaf_value); }
171 inline void SetLeafVector(
int ensemble_num, std::vector<double>& leaf_vector) { forests_[ensemble_num]->SetLeafVector(leaf_vector); }
172 inline void IncrementSampleCount() { num_samples_++; }
174 void SaveToJsonFile(std::string filename) {
175 nlohmann::json model_json = this->
to_json();
176 std::ofstream output_file(filename);
177 output_file << model_json << std::endl;
180 void LoadFromJsonFile(std::string filename) {
181 std::ifstream f(filename);
182 nlohmann::json file_tree_json = nlohmann::json::parse(f);
187 std::string DumpJsonString() {
188 nlohmann::json model_json = this->
to_json();
189 return model_json.dump();
192 void LoadFromJsonString(std::string& json_string) {
193 nlohmann::json file_tree_json = nlohmann::json::parse(json_string);
202 output_dimension_ = 0;
203 is_leaf_constant_ = 0;
204 initialized_ =
false;
210 void from_json(
const nlohmann::json& forest_container_json);
215 std::vector<std::unique_ptr<TreeEnsemble>> forests_;
218 int output_dimension_;
219 bool is_exponentiated_{
false};
220 bool is_leaf_constant_;
221 bool initialized_{
false};
ForestContainer(int num_samples, int num_trees, int output_dimension=1, bool is_leaf_constant=true, bool is_exponentiated=false)
Construct a new ForestContainer object.
void AppendForestContainerSamples(std::unique_ptr< ForestContainer > &dst, const std::unique_ptr< ForestContainer > &src, const char *name)
Append every retained forest sample from src onto the end of dst (deep copy). Used by BARTSamples::Me...
Definition container.h:229