gbrt_rs/boosting/
mod.rs

1//! Gradient boosting algorithms and model training.
2//!
3//! This module implements the core gradient boosting algorithms, including
4//! standard gradient boosting and stochastic gradient boosting with
5//! subsampling. It provides the main training loop, model factories, and
6//! training state tracking.
7//!
8//! # Submodules
9//!
10//! - [`gradient_booster`]: Core gradient boosting implementation with training loop
11//! - [`factory`]: Factory functions for creating booster instances from configurations
12//!
13//! # Key Components
14//!
15//! - [`GradientBooster`]: Main gradient boosting model with training and prediction
16//! - [`BoosterFactory`]: Creates booster instances from string names or configs
17//! - [`BoostingType`]: Enumeration of supported boosting algorithms
18//! - [`GBRTConfig`]: Model configuration (re-exported from [`crate::core`])
19//!
20//! # Boosting Algorithms
21//!
22//! This module supports two variants of gradient boosting:
23//!
24//! - **GradientBoosting**: Standard gradient boosting with full dataset at each iteration
25//! - **StochasticGradientBoosting**: Uses row/column subsampling for regularization
26
27mod gradient_booster;
28mod factory;
29
30// Core gradient boosting implementation
31pub use gradient_booster::{
32    // Main gradient boosting model with training loop and prediction.
33    GradientBooster, 
34    // Errors from boosting operations (training, prediction).
35    BoostingError, 
36    // Result type for boosting operations.
37    BoostingResult, 
38    // State of overall training process.
39    TrainingState, 
40    // State of individual boosting iteration.
41    IterationState
42};
43
44// Factory for creating boosters
45pub use factory::{
46    // Factory for creating booster instances from string names.
47    BoosterFactory, 
48    // Create a booster from configuration parameters.
49    create_booster
50};
51
52// Re-export GBRTConfig from core
53pub use crate::core::{
54    // Configuration for gradient boosting models.
55    GBRTConfig
56};
57
58/// Enumeration of supported gradient boosting algorithms.
59///
60/// This enum defines the variants of gradient boosting implemented in the library.
61/// Each variant has different training characteristics and regularization strategies.
62///
63/// # Variants
64///
65/// - [`GradientBoosting`](BoostingType::GradientBoosting): Standard algorithm using full dataset at each iteration
66/// - [`StochasticGradientBoosting`](BoostingType::StochasticGradientBoosting): Uses subsampling for variance reduction
67///
68/// # Regularization
69///
70/// `StochasticGradientBoosting` provides additional regularization through:
71/// - Row subsampling (bagging)
72/// - Column subsampling (feature sampling)
73/// - Typically results in better generalization and faster training
74#[derive(Debug, Clone, Copy, PartialEq)]
75pub enum BoostingType {
76    // Standard gradient boosting using the full dataset at each iteration.
77    GradientBoosting,
78    // Stochastic gradient boosting with row and column subsampling.
79    StochasticGradientBoosting,
80}
81
82// Display implementation for human-readable output
83impl std::fmt::Display for BoostingType {
84    /// Formats the `BoostingType` as a string for display purposes.
85    ///
86    /// This is primarily used for logging, debugging, and serialization.
87    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88        match self {
89            BoostingType::GradientBoosting => write!(f, "GradientBoosting"),
90            BoostingType::StochasticGradientBoosting => write!(f, "StochasticGradientBoosting"),
91        }
92    }
93}
94