Skip to main content

sklears_compose/plugin_architecture/
exampleestimatorfactory_traits.rs

1//! # ExampleEstimatorFactory - Trait Implementations
2//!
3//! This module contains trait implementations for `ExampleEstimatorFactory`.
4//!
5//! ## Implemented Traits
6//!
7//! - `ComponentFactory`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use sklears_core::{
12    error::{Result as SklResult, SklearsError},
13    traits::Estimator,
14    types::Float,
15};
16
17use super::functions::{ComponentFactory, PluginComponent};
18use super::types::{
19    ComponentConfig, ComponentSchema, ConfigValue, ExampleEstimatorFactory, ExampleRegressor,
20    ParameterSchema, ParameterType,
21};
22
23impl ComponentFactory for ExampleEstimatorFactory {
24    fn create(
25        &self,
26        component_type: &str,
27        config: &ComponentConfig,
28    ) -> SklResult<Box<dyn PluginComponent>> {
29        match component_type {
30            "example_regressor" => Ok(Box::new(ExampleRegressor::new(config.clone()))),
31            _ => Err(SklearsError::InvalidInput(format!(
32                "Unknown component type: {component_type}"
33            ))),
34        }
35    }
36    fn available_types(&self) -> Vec<String> {
37        vec!["example_regressor".to_string()]
38    }
39    fn get_schema(&self, component_type: &str) -> Option<ComponentSchema> {
40        match component_type {
41            "example_regressor" => Some(ComponentSchema {
42                name: "ExampleRegressor".to_string(),
43                required_parameters: vec![],
44                optional_parameters: vec![ParameterSchema {
45                    name: "learning_rate".to_string(),
46                    parameter_type: ParameterType::Float {
47                        min_value: Some(0.0),
48                        max_value: Some(1.0),
49                    },
50                    description: "Learning rate for the algorithm".to_string(),
51                    default_value: Some(ConfigValue::Float(0.01)),
52                }],
53                constraints: vec![],
54            }),
55            _ => None,
56        }
57    }
58}