ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::TrainingSpec Class Reference

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.
 

Detailed Description

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:

// Single tree with PDA (lambda = 0.5):
.pp(pp::pda(0.5))
.build();
// Random forest with uniform variable selection:
.size(100)
.pp(pp::pda(0.0))
.build();
Builder & size(int v)
Definition TrainingSpec.hpp:161
Builder & pp(pp::ProjectionPursuit::Ptr v)
Definition TrainingSpec.hpp:132
TrainingSpec build()
Finalize the builder into a TrainingSpec.
Builder & vars(vars::VariableSelection::Ptr v)
Definition TrainingSpec.hpp:136
static Builder builder(types::Mode mode)
Create a builder for the given mode.
Definition TrainingSpec.hpp:227
ProjectionPursuit::Ptr pda(float lambda)
Factory function for a PDA projection pursuit strategy.
@ Classification
Definition Types.hpp:58
VariableSelection::Ptr uniform(int n_vars)
Factory function: uniform random variable selection.

Strategies are held via shared_ptr and are immutable after construction, so TrainingSpec can be freely copied and shared across trees without deep cloning.

Member Typedef Documentation

◆ Ptr

using ppforest2::TrainingSpec::Ptr = std::shared_ptr<TrainingSpec>

Constructor & Destructor Documentation

◆ 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.

Parameters
ppProjection pursuit strategy.
varsVariable selection strategy.
cutpointSplit cutpoint strategy.
stopStop rule strategy.
binarizationBinarization strategy.
groupingGrouping strategy.
leafLeaf creation strategy.
sizeNumber of trees (0 = single tree).
seedRNG seed.
threadsNumber of threads (0 = hardware concurrency).
max_retriesMaximum retry attempts for degenerate trees.

Member Function Documentation

◆ builder()

static Builder ppforest2::TrainingSpec::builder ( types::Mode mode)
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.

◆ create_leaf()

TreeNode::Ptr ppforest2::TrainingSpec::create_leaf ( NodeContext const & ctx,
stats::RNG & rng ) const
inline

Create a leaf node from the current node context.

◆ find_cutpoint()

void ppforest2::TrainingSpec::find_cutpoint ( NodeContext & ctx,
stats::RNG & rng ) const

Compute the split cutpoint. Asserts postcondition: ctx.cutpoint is set.

◆ find_projection()

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.

◆ from_json()

static Ptr ppforest2::TrainingSpec::from_json ( nlohmann::json const & j)
static

Deserialize a training spec from JSON.

◆ group()

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).

◆ init_groups()

stats::GroupPartition ppforest2::TrainingSpec::init_groups ( types::OutcomeVector const & y) const
inline

Create the initial group partition from the training response.

◆ is_forest()

bool ppforest2::TrainingSpec::is_forest ( ) const
inline

Whether this specification describes a forest (size > 0).

◆ make()

template<typename... Args>
static Ptr ppforest2::TrainingSpec::make ( Args &&... args)
inlinestatic

Create a shared pointer to a TrainingSpec.

◆ regroup()

void ppforest2::TrainingSpec::regroup ( NodeContext & ctx,
stats::RNG & rng ) const

Reduce multiclass partition to binary. Asserts postcondition: ctx.y_bin is set.

◆ resolve_threads()

int ppforest2::TrainingSpec::resolve_threads ( ) const
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.

Returns
The number of threads to use for training.

◆ select_vars()

void ppforest2::TrainingSpec::select_vars ( NodeContext & ctx,
stats::RNG & rng ) const

Run variable selection. Asserts postcondition: ctx.var_selection is set.

◆ should_stop()

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).

◆ to_json()

nlohmann::json ppforest2::TrainingSpec::to_json ( ) const

Serialize the training spec to JSON.

Member Data Documentation

◆ binarization

binarize::Binarization::Ptr const ppforest2::TrainingSpec::binarization

Binarization strategy.

◆ cutpoint

cutpoint::Cutpoint::Ptr const ppforest2::TrainingSpec::cutpoint

Split cutpoint strategy.

◆ grouping

grouping::Grouping::Ptr const ppforest2::TrainingSpec::grouping

Grouping strategy.

◆ leaf

leaf::LeafStrategy::Ptr const ppforest2::TrainingSpec::leaf

Leaf creation strategy.

◆ max_retries

int const ppforest2::TrainingSpec::max_retries

Maximum retry attempts for degenerate trees.

◆ mode

types::Mode const ppforest2::TrainingSpec::mode

Training mode (classification or regression).

◆ pp

pp::ProjectionPursuit::Ptr const ppforest2::TrainingSpec::pp

Projection pursuit optimization strategy.

◆ seed

int const ppforest2::TrainingSpec::seed

RNG seed.

◆ size

int const ppforest2::TrainingSpec::size

Number of trees (0 = single tree).

◆ stop

stop::StopRule::Ptr const ppforest2::TrainingSpec::stop

Stop rule strategy.

◆ threads

int const ppforest2::TrainingSpec::threads

Number of threads for parallel forest training.

◆ vars

vars::VariableSelection::Ptr const ppforest2::TrainingSpec::vars

Variable selection strategy.


The documentation for this class was generated from the following file: