Skip to main content

scirs2_ndimage/biological_vision_inspired/
config.rs

1//! Configuration and Core Types for Biological Vision Inspired Processing
2//!
3//! This module contains configuration structures, models, and core data types
4//! used throughout the biological vision inspired processing system.
5
6use scirs2_core::ndarray::{Array1, Array2, Array3, Array4};
7use std::collections::{HashMap, VecDeque};
8
9/// Configuration for biological vision algorithms
10#[derive(Debug, Clone)]
11pub struct BiologicalVisionConfig {
12    /// Number of cortical layers
13    pub cortical_layers: usize,
14    /// Receptive field sizes for each layer
15    pub receptive_field_sizes: Vec<usize>,
16    /// Lateral inhibition strength
17    pub lateral_inhibition_strength: f64,
18    /// Temporal integration window
19    pub temporal_window: usize,
20    /// Attention focus radius
21    pub attention_radius: usize,
22    /// Saccade planning horizon
23    pub saccade_horizon: usize,
24    /// Color constancy adaptation rate
25    pub color_adaptation_rate: f64,
26    /// Motion prediction window
27    pub motion_prediction_window: usize,
28    /// Compound eye ommatidial count
29    pub ommatidial_count: usize,
30    /// Predictive coding error threshold
31    pub prediction_error_threshold: f64,
32}
33
34impl Default for BiologicalVisionConfig {
35    fn default() -> Self {
36        Self {
37            cortical_layers: 6,
38            receptive_field_sizes: vec![3, 5, 7, 11, 15, 21],
39            lateral_inhibition_strength: 0.5,
40            temporal_window: 10,
41            attention_radius: 50,
42            saccade_horizon: 5,
43            color_adaptation_rate: 0.1,
44            motion_prediction_window: 8,
45            ommatidial_count: 1000,
46            prediction_error_threshold: 0.3,
47        }
48    }
49}
50
51/// Hierarchical cortical layer representation
52#[derive(Debug, Clone)]
53pub struct CorticalLayer {
54    /// Layer level (V1, V2, V4, etc.)
55    pub level: usize,
56    /// Feature maps at this layer
57    pub feature_maps: Array3<f64>,
58    /// Receptive field size
59    pub receptive_field_size: usize,
60    /// Lateral connections
61    pub lateral_connections: Array2<f64>,
62    /// Top-down predictions
63    pub top_down_predictions: Array3<f64>,
64    /// Bottom-up features
65    pub bottom_upfeatures: Array3<f64>,
66    /// Prediction errors
67    pub prediction_errors: Array3<f64>,
68}
69
70/// Retinal processing structure
71#[derive(Debug, Clone)]
72pub struct RetinaModel {
73    /// Photoreceptor responses
74    pub photoreceptors: Array2<f64>,
75    /// Bipolar cells
76    pub bipolar_cells: Array2<f64>,
77    /// Horizontal cells (lateral inhibition)
78    pub horizontal_cells: Array2<f64>,
79    /// Ganglion cells (edge detection)
80    pub ganglion_cells: Array2<f64>,
81    /// Center-surround filters
82    pub center_surround_filters: Vec<Array2<f64>>,
83}
84
85/// Compound eye structure (inspired by insects)
86#[derive(Debug, Clone)]
87pub struct CompoundEyeModel {
88    /// Individual ommatidia
89    pub ommatidia: Vec<Ommatidium>,
90    /// Motion detection cells
91    pub motion_detectors: Array2<f64>,
92    /// Wide-field integration
93    pub wide_field_neurons: Array1<f64>,
94    /// Looming detection
95    pub looming_detectors: Array1<f64>,
96}
97
98/// Individual ommatidium
99#[derive(Debug, Clone)]
100pub struct Ommatidium {
101    /// Position in compound eye
102    pub position: (f64, f64),
103    /// Optical axis direction
104    pub optical_axis: (f64, f64, f64),
105    /// Photoreceptor response
106    pub response: f64,
107    /// Temporal response history
108    pub responsehistory: VecDeque<f64>,
109}
110
111/// Attention and saccade planning system
112#[derive(Debug, Clone)]
113pub struct AttentionSystem {
114    /// Current focus of attention
115    pub attention_center: (usize, usize),
116    /// Attention map (salience)
117    pub attention_map: Array2<f64>,
118    /// Saccade targets
119    pub saccade_targets: Vec<(usize, usize)>,
120    /// Inhibition of return map
121    pub inhibition_of_return: Array2<f64>,
122    /// Feature-based attention weights
123    pub feature_attention_weights: HashMap<String, f64>,
124}
125
126/// Predictive coding system
127#[derive(Debug, Clone)]
128pub struct PredictiveCodingSystem {
129    /// Prediction models for each layer
130    pub prediction_models: Vec<Array3<f64>>,
131    /// Prediction errors
132    pub prediction_errors: Vec<Array3<f64>>,
133    /// Temporal predictions
134    pub temporal_predictions: Vec<Array4<f64>>,
135    /// Confidence estimates
136    pub confidence_estimates: Vec<Array3<f64>>,
137}
138
139/// Color constancy system
140#[derive(Debug, Clone)]
141pub struct ColorConstancySystem {
142    /// Illumination estimates
143    pub illumination_estimates: Array2<(f64, f64, f64)>,
144    /// Surface reflectance estimates
145    pub surface_reflectance: Array2<(f64, f64, f64)>,
146    /// Adaptation state
147    pub adaptationstate: (f64, f64, f64),
148    /// Color memory
149    pub color_memory: Vec<(f64, f64, f64)>,
150}
151
152/// Motion tracking structure
153#[derive(Debug, Clone)]
154pub struct MotionTrack {
155    /// Object identifier
156    pub object_id: usize,
157    /// Current position
158    pub position: (f64, f64),
159    /// Velocity vector
160    pub velocity: (f64, f64),
161    /// Position history
162    pub positionhistory: VecDeque<(f64, f64)>,
163    /// Predicted future positions
164    pub predicted_positions: Vec<(f64, f64)>,
165    /// Confidence in tracking
166    pub confidence: f64,
167    /// Track age
168    pub age: usize,
169}
170
171impl CorticalLayer {
172    /// Create a new cortical layer
173    pub fn new(level: usize, height: usize, width: usize, receptive_field_size: usize) -> Self {
174        Self {
175            level,
176            feature_maps: Array3::zeros((8, height, width)), // 8 feature channels
177            receptive_field_size,
178            lateral_connections: Array2::zeros((height, width)),
179            top_down_predictions: Array3::zeros((8, height, width)),
180            bottom_upfeatures: Array3::zeros((8, height, width)),
181            prediction_errors: Array3::zeros((8, height, width)),
182        }
183    }
184}
185
186impl RetinaModel {
187    /// Create a new retina model
188    pub fn new(height: usize, width: usize) -> Self {
189        Self {
190            photoreceptors: Array2::zeros((height, width)),
191            bipolar_cells: Array2::zeros((height, width)),
192            horizontal_cells: Array2::zeros((height, width)),
193            ganglion_cells: Array2::zeros((height, width)),
194            center_surround_filters: Vec::new(),
195        }
196    }
197}
198
199impl Ommatidium {
200    /// Create a new ommatidium
201    pub fn new(position: (f64, f64), optical_axis: (f64, f64, f64)) -> Self {
202        Self {
203            position,
204            optical_axis,
205            response: 0.0,
206            responsehistory: VecDeque::new(),
207        }
208    }
209}