sklears_compose/plugin_architecture/
exampleestimatorplugin_traits.rs1use sklears_core::{
12 error::{Result as SklResult, SklearsError},
13 traits::Estimator,
14 types::Float,
15};
16
17use super::functions::{Plugin, PluginComponent};
18use super::types::{
19 ComponentConfig, ComponentSchema, ConfigValue, ExampleEstimatorPlugin, ExampleRegressor,
20 ParameterSchema, ParameterType, PluginCapability, PluginContext, PluginMetadata,
21};
22
23impl Plugin for ExampleEstimatorPlugin {
24 fn metadata(&self) -> &PluginMetadata {
25 &self.metadata
26 }
27 fn initialize(&mut self, _context: &PluginContext) -> SklResult<()> {
28 Ok(())
29 }
30 fn shutdown(&mut self) -> SklResult<()> {
31 Ok(())
32 }
33 fn capabilities(&self) -> Vec<PluginCapability> {
34 vec![PluginCapability::Estimator]
35 }
36 fn create_component(
37 &self,
38 component_type: &str,
39 config: &ComponentConfig,
40 ) -> SklResult<Box<dyn PluginComponent>> {
41 match component_type {
42 "example_regressor" => Ok(Box::new(ExampleRegressor::new(config.clone()))),
43 _ => Err(SklearsError::InvalidInput(format!(
44 "Unknown component type: {component_type}"
45 ))),
46 }
47 }
48 fn validate_config(&self, _config: &ComponentConfig) -> SklResult<()> {
49 Ok(())
50 }
51 fn get_component_schema(&self, component_type: &str) -> Option<ComponentSchema> {
52 match component_type {
53 "example_regressor" => Some(ComponentSchema {
54 name: "ExampleRegressor".to_string(),
55 required_parameters: vec![],
56 optional_parameters: vec![ParameterSchema {
57 name: "learning_rate".to_string(),
58 parameter_type: ParameterType::Float {
59 min_value: Some(0.0),
60 max_value: Some(1.0),
61 },
62 description: "Learning rate for the algorithm".to_string(),
63 default_value: Some(ConfigValue::Float(0.01)),
64 }],
65 constraints: vec![],
66 }),
67 _ => None,
68 }
69 }
70}