1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Optimization and performance enhancements for metrics computation
//!
//! This module provides optimized implementations of metrics calculations
//! for improved performance, memory efficiency, and numerical stability.
//!
//! The optimization module contains four main components:
//!
//! 1. `parallel` - Tools for parallel computation of metrics
//! 2. `memory` - Tools for memory-efficient metrics computation
//! 3. `numeric` - Tools for numerically stable metrics computation
//! 4. `quantum_acceleration` - Quantum-inspired algorithms for exponential speedups
//!
//! # Examples
//!
//! ## Using StableMetrics for numerical stability
//!
//! ```
//! use scirs2_metrics::optimization::numeric::StableMetrics;
//! use scirs2_metrics::error::Result;
//!
//! fn compute_kl_divergence(p: &[f64], q: &[f64]) -> Result<f64> {
//! let stable = StableMetrics::<f64>::new()
//! .with_epsilon(1e-10)
//! .with_clip_values(true);
//! stable.kl_divergence(p, q)
//! }
//! ```
//!
//! ## Using parallel computation for batch metrics
//!
//! ```
//! use scirs2_metrics::optimization::parallel::{ParallelConfig, compute_metrics_batch};
//! use scirs2_metrics::error::Result;
//! use scirs2_core::ndarray::Array1;
//!
//! fn compute_multiple_metrics(y_true: &Array1<f64>, y_pred: &Array1<f64>) -> Result<Vec<f64>> {
//! let config = ParallelConfig {
//! parallel_enabled: true,
//! min_chunk_size: 1000,
//! num_threads: None,
//! };
//!
//! let metrics: Vec<Box<dyn Fn(&Array1<f64>, &Array1<f64>) -> Result<f64> + Send + Sync>> = vec![
//! // Define your metric functions here
//! ];
//!
//! compute_metrics_batch(y_true, y_pred, &metrics, &config)
//! }
//! ```
//!
//! ## Using memory-efficient metrics for large datasets
//!
//! ```
//! use scirs2_metrics::optimization::memory::{StreamingMetric, ChunkedMetrics};
//! use scirs2_metrics::error::Result;
//!
//! struct StreamingMeanAbsoluteError;
//!
//! impl StreamingMetric<f64> for StreamingMeanAbsoluteError {
//! type State = (f64, usize); // Running sum and count
//!
//! fn init_state(&self) -> Self::State {
//! (0.0, 0)
//! }
//!
//! fn update_state(&self, state: &mut Self::State, batch_true: &[f64], batch_pred: &[f64]) -> Result<()> {
//! for (y_t, y_p) in batch_true.iter().zip(batch_pred.iter()) {
//! state.0 += (y_t - y_p).abs();
//! state.1 += 1;
//! }
//! Ok(())
//! }
//!
//! fn finalize(&self, state: &Self::State) -> Result<f64> {
//! if state.1 == 0 {
//! return Err(scirs2_metrics::error::MetricsError::InvalidInput(
//! "No data processed".to_string()
//! ));
//! }
//! Ok(state.0 / state.1 as f64)
//! }
//! }
//! ```
//!
//! ## Using quantum-inspired acceleration for large-scale computations
//!
//! ```
//! use scirs2_metrics::optimization::quantum_acceleration::{QuantumMetricsComputer, QuantumConfig};
//! use scirs2_metrics::error::Result;
//! use scirs2_core::ndarray::Array1;
//!
//! fn compute_quantum_correlation(x: &Array1<f64>, y: &Array1<f64>) -> Result<f64> {
//! let config = QuantumConfig::default();
//! let mut quantum_computer = QuantumMetricsComputer::new(config)?;
//! quantum_computer.quantum_correlation(&x.view(), &y.view())
//! }
//! ```
// Re-export submodules
// Re-export common functionality
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ParallelConfig;
pub use ;
pub use SimdMetrics;