mod interaction;
mod polynomial;
mod ratio;
mod selector;
pub mod smart;
mod stats;
use crate::defaults::feature_generation as feature_generation_defaults;
pub use interaction::{InteractionGenerator, InteractionType, PairSelection};
pub use polynomial::PolynomialGenerator;
pub use ratio::RatioGenerator;
pub use selector::{FeatureSelector, SelectionConfig};
pub use smart::{
FeaturePlan, LttFeaturePlan, SmartFeatureConfig, SmartFeatureEngine, SmartFeaturePreset,
TimeFeatureType,
};
pub trait FeatureGenerator: Send + Sync {
fn generate(
&self,
data: &[f32],
num_features: usize,
feature_names: &[String],
) -> (Vec<f32>, Vec<String>);
fn name(&self) -> &'static str;
}
#[derive(Debug, Clone)]
pub struct FeatureGenerationConfig {
pub polynomials: bool,
pub ratios: bool,
pub interactions: bool,
pub max_degree: usize,
pub max_ratios_per_feature: usize,
pub max_interaction_pairs: usize,
pub interaction_types: Vec<InteractionType>,
pub selection: SelectionConfig,
}
impl Default for FeatureGenerationConfig {
fn default() -> Self {
Self {
polynomials: feature_generation_defaults::DEFAULT_POLYNOMIALS,
ratios: feature_generation_defaults::DEFAULT_RATIOS,
interactions: feature_generation_defaults::DEFAULT_INTERACTIONS, max_degree: feature_generation_defaults::DEFAULT_MAX_DEGREE,
max_ratios_per_feature: feature_generation_defaults::DEFAULT_MAX_RATIOS_PER_FEATURE,
max_interaction_pairs: feature_generation_defaults::DEFAULT_MAX_INTERACTION_PAIRS,
interaction_types: vec![InteractionType::Multiply],
selection: SelectionConfig::default(),
}
}
}
impl FeatureGenerationConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_polynomials(mut self, enabled: bool) -> Self {
self.polynomials = enabled;
self
}
pub fn with_ratios(mut self, enabled: bool) -> Self {
self.ratios = enabled;
self
}
pub fn with_interactions(mut self, enabled: bool) -> Self {
self.interactions = enabled;
self
}
pub fn with_max_degree(mut self, degree: usize) -> Self {
self.max_degree = degree;
self
}
pub fn with_max_ratios_per_feature(mut self, max: usize) -> Self {
self.max_ratios_per_feature = max;
self
}
pub fn with_max_interaction_pairs(mut self, max: usize) -> Self {
self.max_interaction_pairs = max;
self
}
pub fn with_interaction_types(mut self, types: Vec<InteractionType>) -> Self {
self.interaction_types = types;
self
}
pub fn with_selection(mut self, config: SelectionConfig) -> Self {
self.selection = config;
self
}
}