|
ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
|
Training configuration for projection pursuit trees and forests. More...
#include <TrainingSpec.hpp>
Classes | |
| class | Builder |
| Fluent builder for TrainingSpec. More... | |
Public Types | |
| using | Ptr = std::shared_ptr<TrainingSpec> |
Public Member Functions | |
| TrainingSpec (pp::ProjectionPursuit::Ptr pp, vars::VariableSelection::Ptr vars, cutpoint::Cutpoint::Ptr cutpoint, stop::StopRule::Ptr stop, binarize::Binarization::Ptr binarization, grouping::Grouping::Ptr grouping, leaf::LeafStrategy::Ptr leaf, types::Mode mode, int size, int seed, int threads, int max_retries) | |
| Construct a training specification. | |
| TreeNode::Ptr | create_leaf (NodeContext const &ctx, stats::RNG &rng) const |
| Create a leaf node from the current node context. | |
| void | find_cutpoint (NodeContext &ctx, stats::RNG &rng) const |
Compute the split cutpoint. Asserts postcondition: ctx.cutpoint is set. | |
| void | find_projection (NodeContext &ctx, stats::RNG &rng) const |
Run projection pursuit optimization. Asserts postcondition: ctx.projector and ctx.pp_index_value are set. | |
| void | group (NodeContext &ctx, stats::RNG &rng) const |
| Split observations into two child partitions. | |
| stats::GroupPartition | init_groups (types::OutcomeVector const &y) const |
| Create the initial group partition from the training response. | |
| bool | is_forest () const |
| Whether this specification describes a forest (size > 0). | |
| void | regroup (NodeContext &ctx, stats::RNG &rng) const |
Reduce multiclass partition to binary. Asserts postcondition: ctx.y_bin is set. | |
| int | resolve_threads () const |
| Get the number of threads to use for training. | |
| void | select_vars (NodeContext &ctx, stats::RNG &rng) const |
Run variable selection. Asserts postcondition: ctx.var_selection is set. | |
| bool | should_stop (NodeContext const &ctx, stats::RNG &rng) const |
| Check whether the node should stop growing. | |
| nlohmann::json | to_json () const |
| Serialize the training spec to JSON. | |
Static Public Member Functions | |
| static Builder | builder (types::Mode mode) |
| Create a builder for the given mode. | |
| static Ptr | from_json (nlohmann::json const &j) |
| Deserialize a training spec from JSON. | |
| template<typename... Args> | |
| static Ptr | make (Args &&... args) |
| Create a shared pointer to a TrainingSpec. | |
Public Attributes | |
| binarize::Binarization::Ptr const | binarization |
| Binarization strategy. | |
| cutpoint::Cutpoint::Ptr const | cutpoint |
| Split cutpoint strategy. | |
| grouping::Grouping::Ptr const | grouping |
| Grouping strategy. | |
| leaf::LeafStrategy::Ptr const | leaf |
| Leaf creation strategy. | |
| int const | max_retries |
| Maximum retry attempts for degenerate trees. | |
| types::Mode const | mode |
| Training mode (classification or regression). | |
| pp::ProjectionPursuit::Ptr const | pp |
| Projection pursuit optimization strategy. | |
| int const | seed |
| RNG seed. | |
| int const | size |
| Number of trees (0 = single tree). | |
| stop::StopRule::Ptr const | stop |
| Stop rule strategy. | |
| int const | threads |
| Number of threads for parallel forest training. | |
| vars::VariableSelection::Ptr const | vars |
| Variable selection strategy. | |
Training configuration for projection pursuit trees and forests.
Composes seven strategies (projection pursuit, variable selection, split cutpoint, stop rule, binarization, grouping, leaf) together with forest-level parameters (size, seed, threads, max retries).
TrainingSpec is a concrete class — new strategies are plugged in via the builder, not by subclassing:
Strategies are held via shared_ptr and are immutable after construction, so TrainingSpec can be freely copied and shared across trees without deep cloning.
| using ppforest2::TrainingSpec::Ptr = std::shared_ptr<TrainingSpec> |
| ppforest2::TrainingSpec::TrainingSpec | ( | pp::ProjectionPursuit::Ptr | pp, |
| vars::VariableSelection::Ptr | vars, | ||
| cutpoint::Cutpoint::Ptr | cutpoint, | ||
| stop::StopRule::Ptr | stop, | ||
| binarize::Binarization::Ptr | binarization, | ||
| grouping::Grouping::Ptr | grouping, | ||
| leaf::LeafStrategy::Ptr | leaf, | ||
| types::Mode | mode, | ||
| int | size, | ||
| int | seed, | ||
| int | threads, | ||
| int | max_retries ) |
Construct a training specification.
| pp | Projection pursuit strategy. |
| vars | Variable selection strategy. |
| cutpoint | Split cutpoint strategy. |
| stop | Stop rule strategy. |
| binarization | Binarization strategy. |
| grouping | Grouping strategy. |
| leaf | Leaf creation strategy. |
| size | Number of trees (0 = single tree). |
| seed | RNG seed. |
| threads | Number of threads (0 = hardware concurrency). |
| max_retries | Maximum retry attempts for degenerate trees. |
|
inlinestatic |
Create a builder for the given mode.
Mode is required because it's structurally primary: it determines the default binarize strategy and the mode-compatibility checks for every other strategy. There is no "no-mode" TrainingSpec.
|
inline |
Create a leaf node from the current node context.
| void ppforest2::TrainingSpec::find_cutpoint | ( | NodeContext & | ctx, |
| stats::RNG & | rng ) const |
Compute the split cutpoint. Asserts postcondition: ctx.cutpoint is set.
| void ppforest2::TrainingSpec::find_projection | ( | NodeContext & | ctx, |
| stats::RNG & | rng ) const |
Run projection pursuit optimization. Asserts postcondition: ctx.projector and ctx.pp_index_value are set.
|
static |
Deserialize a training spec from JSON.
| void ppforest2::TrainingSpec::group | ( | NodeContext & | ctx, |
| stats::RNG & | rng ) const |
Split observations into two child partitions.
Writes ctx.lower_y_part / ctx.upper_y_part. Sets ctx.aborted if the grouping produced no progress (i.e. one child covers the whole parent).
|
inline |
Create the initial group partition from the training response.
|
inline |
Whether this specification describes a forest (size > 0).
|
inlinestatic |
Create a shared pointer to a TrainingSpec.
| void ppforest2::TrainingSpec::regroup | ( | NodeContext & | ctx, |
| stats::RNG & | rng ) const |
Reduce multiclass partition to binary. Asserts postcondition: ctx.y_bin is set.
|
inline |
Get the number of threads to use for training.
If the number of threads is not specified, the number of hardware concurrency is returned.
| void ppforest2::TrainingSpec::select_vars | ( | NodeContext & | ctx, |
| stats::RNG & | rng ) const |
Run variable selection. Asserts postcondition: ctx.var_selection is set.
| bool ppforest2::TrainingSpec::should_stop | ( | NodeContext const & | ctx, |
| stats::RNG & | rng ) const |
Check whether the node should stop growing.
Returns true if the configured stop rule fires, OR if the node has fewer than 2 groups (a tree-level invariant — no configured rule can split a single group, so stopping is the only sane option).
| nlohmann::json ppforest2::TrainingSpec::to_json | ( | ) | const |
Serialize the training spec to JSON.
| binarize::Binarization::Ptr const ppforest2::TrainingSpec::binarization |
Binarization strategy.
| cutpoint::Cutpoint::Ptr const ppforest2::TrainingSpec::cutpoint |
Split cutpoint strategy.
| grouping::Grouping::Ptr const ppforest2::TrainingSpec::grouping |
Grouping strategy.
| leaf::LeafStrategy::Ptr const ppforest2::TrainingSpec::leaf |
Leaf creation strategy.
| int const ppforest2::TrainingSpec::max_retries |
Maximum retry attempts for degenerate trees.
| types::Mode const ppforest2::TrainingSpec::mode |
Training mode (classification or regression).
| pp::ProjectionPursuit::Ptr const ppforest2::TrainingSpec::pp |
Projection pursuit optimization strategy.
| int const ppforest2::TrainingSpec::seed |
RNG seed.
| int const ppforest2::TrainingSpec::size |
Number of trees (0 = single tree).
| stop::StopRule::Ptr const ppforest2::TrainingSpec::stop |
Stop rule strategy.
| int const ppforest2::TrainingSpec::threads |
Number of threads for parallel forest training.
| vars::VariableSelection::Ptr const ppforest2::TrainingSpec::vars |
Variable selection strategy.