33 using Ptr = std::unique_ptr<Bagged<M>>;
80 std::vector<std::uint8_t> in_bag(
static_cast<std::size_t
>(n_total), 0);
83 if (i >= 0 && i < n_total) {
84 in_bag[
static_cast<std::size_t
>(i)] = 1;
89 oob.reserve(
static_cast<std::size_t
>(n_total));
90 for (
int i = 0; i < n_total; ++i) {
91 if (in_bag[
static_cast<std::size_t
>(i)] == 0) {
105 if (row_idx.empty()) {
147 template<
typename M,
typename F>
149 int const n =
static_cast<int>(bags.size());
150 for (
int k = 0; k < n; ++k) {
151 Bagged<M> const& bag = *bags[
static_cast<std::size_t
>(k)];
152 std::vector<int> oob_idx = bag.
oob_indices(n_total);
153 if (oob_idx.empty()) {
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:33
Eigen::Matrix< Outcome, Eigen::Dynamic, 1 > OutcomeVector
Dynamic-size column vector of predictions.
Definition Types.hpp:42
Eigen::Matrix< Feature, Eigen::Dynamic, 1 > FeatureVector
Dynamic-size column vector of feature values.
Definition Types.hpp:36
Feature Outcome
Scalar type for predictions (float for both classification and regression).
Definition Types.hpp:30
Binarization strategies for multiclass-to-binary reduction.
Definition Benchmark.hpp:25
void for_each_bag_with_oob(std::vector< std::unique_ptr< Bagged< M > > > const &bags, int n_total, F fn)
Apply fn to every bag in bags that has usable OOB rows.
Definition Bagged.hpp:148
Bootstrap-aggregated model wrapper.
Definition Bagged.hpp:32
static Ptr make(std::unique_ptr< Derived > model, std::vector< int > sample_indices)
Construct a Bagged<M> and return it as a Ptr.
Definition Bagged.hpp:54
std::unique_ptr< Bagged< M > > Ptr
Definition Bagged.hpp:33
bool operator!=(Bagged const &other) const
Definition Bagged.hpp:127
types::OutcomeVector predict(types::FeatureMatrix const &x) const
Delegate batch prediction to the wrapped model.
Definition Bagged.hpp:62
types::OutcomeVector predict_oob(types::FeatureMatrix const &x, std::vector< int > const &row_idx) const
Predict a subset of rows (typically OOB indices).
Definition Bagged.hpp:104
std::vector< int > sample_indices
Definition Bagged.hpp:38
std::unique_ptr< Tree > model
Definition Bagged.hpp:36
bool degenerate() const
Whether the wrapped model reported a degenerate training run.
Definition Bagged.hpp:112
std::vector< int > oob_indices(int n_total) const
Row indices of training observations not in the bootstrap sample.
Definition Bagged.hpp:75
bool operator==(Bagged const &other) const
Structural equality on the wrapped model only.
Definition Bagged.hpp:126
types::Outcome predict(types::FeatureVector const &x) const
Delegate single-row prediction to the wrapped model.
Definition Bagged.hpp:59
Bagged(std::unique_ptr< M > model, std::vector< int > sample_indices)
Definition Bagged.hpp:40