scirs2_metrics/integration/mod.rs
1//! Integration with other scirs2 modules
2//!
3//! This module provides adapters and utilities for integrating scirs2-metrics
4//! with other modules in the scirs2 ecosystem, such as scirs2-neural and scirs2-optim.
5//!
6//! # Neural Integration
7//!
8//! The [`neural`] module provides integration with the scirs2-neural module, allowing
9//! metrics to be used during model training, evaluation, and visualization.
10//!
11//! ```toml
12//! [dependencies]
13//! scirs2-metrics = { version = "0.1.0-beta.4", features = ["neural_common"] }
14//! ```
15//!
16//! ## Basic Usage
17//!
18//! ```no_run
19//! # #[cfg(feature = "neural_common")]
20//! # {
21//! use scirs2_metrics::integration::neural::NeuralMetricAdapter;
22//! use scirs2_core::ndarray::Array;
23//!
24//! // Create metric adapters for common metrics
25//! let accuracy = NeuralMetricAdapter::<f64>::accuracy();
26//! let precision = NeuralMetricAdapter::<f64>::precision();
27//! let recall = NeuralMetricAdapter::<f64>::recall();
28//! let f1_score = NeuralMetricAdapter::<f64>::f1_score();
29//! let mse = NeuralMetricAdapter::<f64>::mse();
30//! let r2 = NeuralMetricAdapter::<f64>::r2();
31//!
32//! // Custom metric adapter
33//! let custom_metric = NeuralMetricAdapter::new(
34//! "custom_metric",
35//! Box::new(|preds, targets| {
36//! // Custom metric calculation
37//! Ok(0.5)
38//! }),
39//! );
40//! # }
41//! ```
42//!
43//! ## Training Callbacks
44//!
45//! The [`MetricsCallback`] can be used to track metrics during neural network training.
46//!
47//! ## Visualizations
48//!
49//! Visualization utilities are provided for common model evaluation plots:
50//!
51//! - Training history curves
52//! - ROC curves
53//! - Precision-Recall curves
54//! - Confusion matrices
55//!
56//! # Optimization Integration
57//!
58//! The [`optim`] module provides integration with the scirs2-optim module, allowing
59//! metrics to be used for hyperparameter optimization and learning rate scheduling.
60//!
61//! ```toml
62//! [dependencies]
63//! scirs2-metrics = { version = "0.1.0-beta.4", features = ["optim_integration"] }
64//! ```
65//!
66//! ## Basic Usage
67//!
68//! ```no_run
69//! # #[cfg(feature = "optim_integration")]
70//! # {
71//! use scirs2_metrics::integration::optim::{MetricOptimizer, MetricLRScheduler};
72//! use scirs2_core::ndarray::Array1;
73//!
74//! // Create a metric optimizer for accuracy
75//! let metric_optimizer = MetricOptimizer::new("accuracy", true);
76//!
77//! // Create scheduler configuration for external use
78//! let scheduler_config = metric_optimizer.create_scheduler_config(0.1, 0.1, 5, 1e-6);
79//!
80//! // Create an actual scheduler using the configuration
81//! let mut scheduler = MetricLRScheduler::new(
82//! scheduler_config.initial_lr,
83//! scheduler_config.factor,
84//! scheduler_config.patience,
85//! scheduler_config.min_lr,
86//! &scheduler_config.metric_name,
87//! true // maximize
88//! );
89//!
90//! // Update scheduler based on a metric value
91//! let metric_value = 0.85;
92//! let new_lr = scheduler.step_with_metric(metric_value);
93//! # }
94//! ```
95//!
96
97// Core integration traits (no dependencies on other modules)
98pub mod traits;
99
100// Feature-gated integration modules
101#[cfg(feature = "neural_common")]
102pub mod neural;
103
104#[cfg(feature = "optim_integration")]
105pub mod optim;