37 namespace experimental {
47 virtual char const*
what() const noexcept {
return msg_; }
56 template <
typename decision_forest_t>
59 using node_type =
typename decision_forest_t::node_type;
64 if (root_node_indexes_.empty()) {
65 root_node_indexes_.emplace_back();
67 max_tree_size_ =
std::max(cur_tree_size_, max_tree_size_);
69 if (cur_tree_size_ % alignment_ !=
index_type{}) {
70 auto padding = (alignment_ - cur_tree_size_ % alignment_);
71 for (
auto i =
index_type{}; i < padding; ++i) {
72 add_node(
typename node_type::threshold_type{}, std::nullopt);
76 root_node_indexes_.push_back(root_node_indexes_.back() + cur_tree_size_);
82 template <
typename iter_t>
86 std::optional<int> tl_node_id = std::nullopt,
87 bool default_to_distant_child =
false,
88 typename node_type::metadata_storage_type feature =
typename node_type::metadata_storage_type{},
89 typename node_type::offset_type offset =
typename node_type::offset_type{})
93 auto set_storage = &node_value;
94 auto max_node_categories = *std::max_element(vec_begin, vec_end) + 1;
95 if (max_num_categories_ > bin_width) {
97 node_value = categorical_storage_.size();
99 categorical_storage_.push_back(max_node_categories);
100 categorical_storage_.resize(categorical_storage_.size() + bins_required);
101 set_storage = &(categorical_storage_[node_value + 1]);
103 auto set = bitset{set_storage, max_node_categories};
104 std::for_each(vec_begin, vec_end, [&set](
auto&& cat_index) { set.set(cat_index); });
106 add_node(node_value, tl_node_id,
false, default_to_distant_child,
true, feature, offset,
false);
110 template <
typename iter_t>
113 std::optional<int> tl_node_id = std::nullopt)
116 std::copy(vec_begin, vec_end, std::back_inserter(vector_output_));
117 nodes_.emplace_back(leaf_index,
121 typename node_type::metadata_storage_type{},
122 typename node_type::offset_type{});
124 node_id_mapping_.push_back(
static_cast<index_type>(tl_node_id.value_or(0)));
129 template <
typename value_t>
132 std::optional<int> tl_node_id = std::nullopt,
133 bool is_leaf_node =
true,
134 bool default_to_distant_child =
false,
135 bool is_categorical_node =
false,
136 typename node_type::metadata_storage_type feature =
typename node_type::metadata_storage_type{},
137 typename node_type::offset_type offset =
typename node_type::offset_type{},
138 bool is_inclusive =
false)
140 if (is_inclusive) { val = std::nextafter(val, std::numeric_limits<value_t>::infinity()); }
142 val, is_leaf_node, default_to_distant_child, is_categorical_node, feature, offset);
144 node_id_mapping_.push_back(
static_cast<index_type>(tl_node_id.value_or(0)));
162 if (output_size_ !=
index_type{1} && output_size_ != val) {
171 max_num_categories_{max_num_categories},
178 postproc_constant_{},
181 root_node_indexes_{},
196 #pragma GCC diagnostic push
197 #pragma GCC diagnostic ignored "-Wnarrowing"
198 return decision_forest_t{
211 max_num_categories_ != 0,
212 vector_output_.empty()
214 : std::make_optional<raft_proto::buffer<typename node_type::threshold_type>>(
219 categorical_storage_.empty()
221 : std::make_optional<raft_proto::buffer<typename node_type::index_type>>(
229 static_cast<typename node_type::threshold_type
>(average_factor_),
230 static_cast<typename node_type::threshold_type
>(bias_),
231 static_cast<typename node_type::threshold_type
>(postproc_constant_)};
232 #pragma GCC diagnostic pop
242 double average_factor_;
244 double postproc_constant_;
247 std::vector<node_type> nodes_;
248 std::vector<index_type> root_node_indexes_;
249 std::vector<typename node_type::threshold_type> vector_output_;
250 std::vector<typename node_type::index_type> categorical_storage_;
251 std::vector<index_type> node_id_mapping_;
math_t max(math_t a, math_t b)
Definition: learning_rate.h:27
element_op
Definition: postproc_ops.hpp:29
uint32_t index_type
Definition: index_type.hpp:21
row_op
Definition: postproc_ops.hpp:22
Definition: dbscan.hpp:30
HOST DEVICE constexpr auto ceildiv(T dividend, U divisor)
Definition: ceildiv.hpp:21
int cuda_stream
Definition: cuda_stream.hpp:25
device_type
Definition: device_type.hpp:18
const_agnostic_same_t< T, U > copy(buffer< T > &dst, buffer< U > const &src, typename buffer< T >::index_type dst_offset, typename buffer< U >::index_type src_offset, typename buffer< T >::index_type size, cuda_stream stream)
Definition: buffer.hpp:327
Definition: decision_forest_builder.hpp:57
void set_element_postproc(element_op val)
Definition: decision_forest_builder.hpp:149
void start_new_tree()
Definition: decision_forest_builder.hpp:62
typename decision_forest_t::node_type node_type
Definition: decision_forest_builder.hpp:59
void set_average_factor(double val)
Definition: decision_forest_builder.hpp:153
void add_leaf_vector_node(iter_t vec_begin, iter_t vec_end, std::optional< int > tl_node_id=std::nullopt)
Definition: decision_forest_builder.hpp:111
void set_output_size(index_type val)
Definition: decision_forest_builder.hpp:160
void set_postproc_constant(double val)
Definition: decision_forest_builder.hpp:158
void set_bias(double val)
Definition: decision_forest_builder.hpp:155
decision_forest_builder(index_type max_num_categories=index_type{}, index_type align_bytes=index_type{})
Definition: decision_forest_builder.hpp:168
void add_categorical_node(iter_t vec_begin, iter_t vec_end, std::optional< int > tl_node_id=std::nullopt, bool default_to_distant_child=false, typename node_type::metadata_storage_type feature=typename node_type::metadata_storage_type{}, typename node_type::offset_type offset=typename node_type::offset_type{})
Definition: decision_forest_builder.hpp:83
auto get_decision_forest(index_type num_feature, index_type num_class, raft_proto::device_type mem_type=raft_proto::device_type::cpu, int device=0, raft_proto::cuda_stream stream=raft_proto::cuda_stream{})
Definition: decision_forest_builder.hpp:187
void set_row_postproc(row_op val)
Definition: decision_forest_builder.hpp:151
void add_node(value_t val, std::optional< int > tl_node_id=std::nullopt, bool is_leaf_node=true, bool default_to_distant_child=false, bool is_categorical_node=false, typename node_type::metadata_storage_type feature=typename node_type::metadata_storage_type{}, typename node_type::offset_type offset=typename node_type::offset_type{}, bool is_inclusive=false)
Definition: decision_forest_builder.hpp:130
Definition: decision_forest_builder.hpp:44
model_builder_error(char const *msg)
Definition: decision_forest_builder.hpp:46
model_builder_error()
Definition: decision_forest_builder.hpp:45
virtual char const * what() const noexcept
Definition: decision_forest_builder.hpp:47
Definition: exceptions.hpp:36
A container which may or may not own its own data on host or device.
Definition: buffer.hpp:41