Skip to main content

scirs2_ndimage/ai_driven_adaptive_processing/
learning.rs

1//! Learning Components for AI-Driven Adaptive Processing
2//!
3//! This module contains neural networks, learning algorithms, and training components
4//! for the AI-driven adaptive processing system.
5
6use scirs2_core::ndarray::{Array1, Array2, Array3};
7use std::collections::{HashMap, VecDeque};
8
9use super::config::{AlgorithmType, ImagePattern, PatternType};
10
11/// Neural Model for AI-driven processing
12#[derive(Debug, Clone)]
13pub struct NeuralModel {
14    /// Network weights
15    pub weights: Array2<f64>,
16    /// Network biases
17    pub biases: Array1<f64>,
18    /// Model architecture metadata
19    pub architecture: String,
20}
21
22/// Processing Experience (for reinforcement learning)
23#[derive(Debug, Clone)]
24pub struct ProcessingExperience {
25    /// Input image characteristics
26    pub inputfeatures: Array1<f64>,
27    /// Processing action taken
28    pub action: ProcessingAction,
29    /// Quality reward achieved
30    pub reward: f64,
31    /// Performance metrics
32    pub performance: PerformanceMetrics,
33    /// Next state features
34    pub nextfeatures: Array1<f64>,
35    /// Context information
36    pub context: String,
37}
38
39/// Processing Action (for reinforcement learning)
40#[derive(Debug, Clone)]
41pub struct ProcessingAction {
42    /// Primary algorithm to use
43    pub primary_algorithm: AlgorithmType,
44    /// Secondary algorithms (if any)
45    pub secondary_algorithms: Vec<AlgorithmType>,
46    /// Parameter modifications
47    pub parameter_adjustments: HashMap<String, f64>,
48    /// Processing order
49    pub processing_order: Vec<usize>,
50}
51
52/// Performance Metrics
53#[derive(Debug, Clone)]
54pub struct PerformanceMetrics {
55    /// Processing speed (pixels per second)
56    pub speed: f64,
57    /// Quality score (0-1)
58    pub quality: f64,
59    /// Memory usage (MB)
60    pub memory_usage: f64,
61    /// Energy consumption (estimated)
62    pub energy_consumption: f64,
63    /// User satisfaction (if available)
64    pub user_satisfaction: Option<f64>,
65}
66
67/// Continual Learning State
68#[derive(Debug, Clone)]
69pub struct ContinualLearningState {
70    /// Task-specific knowledge
71    pub task_knowledge: Vec<TaskKnowledge>,
72    /// Catastrophic forgetting prevention
73    pub forgetting_prevention: ForgettingPreventionState,
74    /// Meta-learning parameters
75    pub meta_learning_params: Array1<f64>,
76    /// Adaptation history
77    pub adaptationhistory: Vec<AdaptationRecord>,
78}
79
80/// Task Knowledge
81#[derive(Debug, Clone)]
82pub struct TaskKnowledge {
83    /// Task identifier
84    pub task_id: String,
85    /// Task-specific parameters
86    pub parameters: Array1<f64>,
87    /// Importance weights
88    pub importance_weights: Array1<f64>,
89    /// Performance on this task
90    pub task_performance: f64,
91}
92
93/// Forgetting Prevention State
94#[derive(Debug, Clone)]
95pub struct ForgettingPreventionState {
96    /// Elastic weight consolidation parameters
97    pub ewc_params: Array1<f64>,
98    /// Fisher information matrix
99    pub fisher_information: Array2<f64>,
100    /// Important parameter mask
101    pub importance_mask: Array1<bool>,
102    /// Memory strength
103    pub memory_strength: f64,
104}
105
106/// Adaptation Record
107#[derive(Debug, Clone)]
108pub struct AdaptationRecord {
109    /// Timestamp
110    pub timestamp: u64,
111    /// Adaptation type
112    pub adaptation_type: String,
113    /// Parameters changed
114    pub parameters_changed: Vec<String>,
115    /// Performance improvement
116    pub improvement: f64,
117}
118
119/// Transfer Learning Model
120#[derive(Debug, Clone)]
121pub struct TransferLearningModel {
122    /// Source domain
123    pub source_domain: String,
124    /// Target domain
125    pub target_domain: String,
126    /// Transfer weights
127    pub transfer_weights: Array2<f64>,
128    /// Transfer effectiveness
129    pub effectiveness: f64,
130    /// Number of successful transfers
131    pub transfer_count: usize,
132}
133
134/// Few-Shot Learning Entry
135#[derive(Debug, Clone)]
136pub struct FewShotLearningEntry {
137    /// Few-shot examples
138    pub examples: Vec<Array1<f64>>,
139    /// Associated labels/strategies
140    pub labels: Vec<String>,
141    /// Model adaptation parameters
142    pub adaptation_params: Array1<f64>,
143    /// Learning progress
144    pub learning_progress: f64,
145}
146
147/// Explanation Tracker
148#[derive(Debug, Clone)]
149pub struct ExplanationTracker {
150    /// Decision explanations
151    pub decision_explanations: VecDeque<String>,
152    /// Feature importance scores
153    pub feature_importance: HashMap<String, f64>,
154    /// Processing justifications
155    pub justifications: HashMap<String, String>,
156    /// Confidence scores
157    pub confidence_scores: HashMap<String, f64>,
158}
159
160/// Prediction Model
161#[derive(Debug, Clone)]
162pub struct PredictionModel {
163    /// Model weights
164    pub weights: Array2<f64>,
165    /// Model type
166    pub model_type: String,
167    /// Prediction accuracy
168    pub accuracy: f64,
169    /// Training epochs
170    pub epochs_trained: usize,
171}