|
ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
|
Fluent builder for TrainingSpec. More...
#include <TrainingSpec.hpp>
Classes | |
| struct | Config |
| Builder state — the configuration being assembled. More... | |
Public Member Functions | |
| Builder (types::Mode mode) | |
| Builder & | apply_defaults () |
| Fill in any null strategy fields with mode-aware defaults. | |
| Builder & | binarization (binarize::Binarization::Ptr v) |
| TrainingSpec | build () |
Finalize the builder into a TrainingSpec. | |
| Builder & | cutpoint (cutpoint::Cutpoint::Ptr v) |
| Builder & | grouping (grouping::Grouping::Ptr v) |
| Builder & | leaf (leaf::LeafStrategy::Ptr v) |
| Ptr | make () |
Shorthand for std::make_shared<TrainingSpec>(build()). | |
| Builder & | max_retries (int v) |
| Builder & | pp (pp::ProjectionPursuit::Ptr v) |
| Builder & | seed (int v) |
| Builder & | size (int v) |
| Builder & | stop (stop::StopRule::Ptr v) |
| Builder & | threads (int v) |
| Builder & | vars (vars::VariableSelection::Ptr v) |
Public Attributes | |
| Config | config |
| types::Mode const | mode |
Fluent builder for TrainingSpec.
mode is required at construction — it's structurally primary (drives the mode-dependent default strategies and gates mode-compatibility checks), not a post-construction tweak, so there's no .mode() setter.
The Builder's mutable state is grouped in the nested Config struct, exposed as the public config member. The fluent setters (.pp(v), .size(5), …) keep their conventional names by writing through config.pp / config.size, so the setter names don't collide with the field names.
Strategy fields in Config start as nullptr and are resolved to mode-aware defaults by apply_defaults() — which build() invokes automatically. Calling apply_defaults() directly is useful when a caller wants to inspect the resolved spec before constructing (e.g. for JSON round-trip tests).
The single source of truth for default selection lives in apply_defaults() — CLI and R both pass only the strategies the user supplied and rely on the Builder for the rest, so adding a new mode-aware default means changing exactly one location.
Strategy factory calls are made in TrainingSpec.cpp so the header includes only base-class strategy headers.
|
inlineexplicit |
| Builder & ppforest2::TrainingSpec::Builder::apply_defaults | ( | ) |
Fill in any null strategy fields with mode-aware defaults.
Idempotent — only assigns when a field is currently nullptr, so re-calling after explicit overrides leaves user choices intact.
Dispatches on mode exactly once (via the per-mode apply_mode_defaults overloads in the implementation file), so adding a new mode means adding a new overload — not adding more is_regression branches throughout the function.
Defaults by mode:
pp: pp::pda(0.0) (both modes)vars: vars::all() (both modes)cutpoint: cutpoint::mean_of_means() (both modes)stop: stop::pure_node() for classification; stop::any({min_size(5), min_variance(0.01)}) for regressionbinarize: binarize::largest_gap() for classification; binarize::disabled() for regression (regression's by_cutpoint grouping always yields 2 groups, so binarize is a no-op)grouping: grouping::by_label() for classification; grouping::by_cutpoint() for regressionleaf: leaf::majority_vote() for classification; leaf::mean_response() for regressionReturns *this for fluent chaining.
|
inline |
| TrainingSpec ppforest2::TrainingSpec::Builder::build | ( | ) |
Finalize the builder into a TrainingSpec.
Calls apply_defaults() first so any unset strategies receive their mode-aware default, then constructs and returns the spec.
|
inline |
|
inline |
|
inline |
| Ptr ppforest2::TrainingSpec::Builder::make | ( | ) |
Shorthand for std::make_shared<TrainingSpec>(build()).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| Config ppforest2::TrainingSpec::Builder::config |
| types::Mode const ppforest2::TrainingSpec::Builder::mode |