ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
VariableSelection.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "stats/Stats.hpp"
6
7#include <vector>
8
17namespace ppforest2 {
18 struct NodeContext;
19}
20
21namespace ppforest2::vars {
27 class VariableSelection : public Strategy<VariableSelection> {
28 public:
35 struct Result {
37 std::vector<int> selected_cols;
39 size_t original_size = 0;
40
41 Result() = default;
42
46
57 ::ppforest2::pp::Projector full_vector = ::ppforest2::pp::Projector::Zero(original_size);
58
59 for (size_t i = 0; i < selected_cols.size(); ++i) {
60 full_vector(selected_cols[i]) = reduced_vector(i);
61 }
62
63 return full_vector;
64 }
65 };
66
73 void select(NodeContext& ctx, stats::RNG& rng) const;
74
75 protected:
77 virtual void compute(NodeContext& ctx, stats::RNG& rng) const = 0;
78 };
79
82
85}
CRTP base class providing self-registration for strategy types.
Definition Strategy.hpp:93
std::shared_ptr< VariableSelection > Ptr
Definition Strategy.hpp:95
Abstract strategy for variable selection.
Definition VariableSelection.hpp:27
virtual void compute(NodeContext &ctx, stats::RNG &rng) const =0
Subclass implementation of variable selection.
void select(NodeContext &ctx, stats::RNG &rng) const
Select a subset of variables and store the result in the context.
types::FeatureVector Projector
Column vector of projection coefficients (one per variable).
Definition Projector.hpp:6
pcg32 RNG
Definition Stats.hpp:24
Definition All.hpp:6
VariableSelection::Ptr uniform(int n_vars)
Factory function: uniform random variable selection.
VariableSelection::Ptr all()
Factory function: select all variables (no selection).
Binarization strategies for multiclass-to-binary reduction.
Definition Benchmark.hpp:25
Mutable context accumulating intermediate results during node training.
Definition NodeContext.hpp:20
Result(std::vector< int > const &selected_cols, size_t original_size)
Definition VariableSelection.hpp:43
size_t original_size
Number of columns in the original (unreduced) matrix.
Definition VariableSelection.hpp:39
::ppforest2::pp::Projector expand(::ppforest2::pp::Projector const &reduced_vector) const
Expand a reduced-dimension projector to the original space.
Definition VariableSelection.hpp:56
std::vector< int > selected_cols
Indices of the selected columns in the original matrix.
Definition VariableSelection.hpp:37