ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Strategy< Derived > Class Template Referenceabstract

CRTP base class providing self-registration for strategy types. More...

#include <Strategy.hpp>

Public Types

using Factory = Ptr (*)(nlohmann::json const&)
 Factory function type for deserializing a strategy from JSON.
 
using Ptr = std::shared_ptr<Derived>
 

Public Member Functions

virtual ~Strategy ()=default
 
virtual std::string display_name () const =0
 Human-readable name for display in summaries.
 
virtual std::set< ppforest2::types::Modesupported_modes () const =0
 Training modes this strategy supports.
 
virtual nlohmann::json to_json () const =0
 Serialize this strategy's configuration to JSON.
 

Static Public Member Functions

static Ptr from_json (nlohmann::json const &j)
 Construct a strategy from its JSON representation.
 
static bool register_strategy (std::string const &name, Factory factory)
 Register a concrete strategy for JSON deserialization.
 

Detailed Description

template<typename Derived>
class Strategy< Derived >

CRTP base class providing self-registration for strategy types.

Each strategy family (ProjectionPursuit, VariableSelection, Cutpoint, StopRule, Binarization, Grouping) inherits from Strategy<Derived> to get a shared_ptr Ptr typedef, a static registry of named factory functions, and a from_json() dispatcher that looks up the "name" field and delegates to the registered factory.

Concrete strategies register themselves at static-init time via the PPFOREST2_REGISTER_STRATEGY macro.

Template Parameters
DerivedThe strategy base class (e.g. ProjectionPursuit).

Member Typedef Documentation

◆ Factory

template<typename Derived>
using Strategy< Derived >::Factory = Ptr (*)(nlohmann::json const&)

Factory function type for deserializing a strategy from JSON.

◆ Ptr

template<typename Derived>
using Strategy< Derived >::Ptr = std::shared_ptr<Derived>

Constructor & Destructor Documentation

◆ ~Strategy()

template<typename Derived>
virtual Strategy< Derived >::~Strategy ( )
virtualdefault

Member Function Documentation

◆ display_name()

◆ from_json()

template<typename Derived>
static Ptr Strategy< Derived >::from_json ( nlohmann::json const & j)
inlinestatic

Construct a strategy from its JSON representation.

Dispatches on the "name" field to the registered factory.

Parameters
jJSON object (must contain "name").
Returns
Shared pointer to the constructed strategy.

◆ register_strategy()

template<typename Derived>
static bool Strategy< Derived >::register_strategy ( std::string const & name,
Factory factory )
inlinestatic

Register a concrete strategy for JSON deserialization.

Called automatically by concrete strategies via inline static initialization. Adding a new strategy only requires defining a static from_json and the PPFOREST2_REGISTER_STRATEGY macro.

Parameters
nameStrategy name (must match the "name" field in JSON).
factoryFactory function that constructs the strategy.
Returns
Always true (return value used for static init).

◆ supported_modes()

template<typename Derived>
virtual std::set< ppforest2::types::Mode > Strategy< Derived >::supported_modes ( ) const
pure virtual

Training modes this strategy supports.

Every concrete strategy MUST explicitly declare which modes it supports — there is no default. This forces implementers to think about mode compatibility rather than silently inheriting both modes and triggering runtime surprises.

Used by TrainingSpec to validate that every selected strategy is compatible with the configured training mode. Fails fast at build time instead of silently misbehaving at train time.

Implemented in ppforest2::binarize::Disabled, ppforest2::binarize::LargestGap, ppforest2::cutpoint::MeanOfMeans, ppforest2::grouping::ByCutpoint, ppforest2::grouping::ByLabel, ppforest2::leaf::MajorityVote, ppforest2::leaf::MeanResponse, ppforest2::pp::PDA, ppforest2::stop::CompositeStop, ppforest2::stop::MaxDepth, ppforest2::stop::MinSize, ppforest2::stop::MinVariance, ppforest2::stop::PureNode, ppforest2::test::MockStop, ppforest2::vars::All, and ppforest2::vars::Uniform.

◆ to_json()

template<typename Derived>
virtual nlohmann::json Strategy< Derived >::to_json ( ) const
pure virtual

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