scirs2_ndimage/biological_vision_inspired/
config.rs1use scirs2_core::ndarray::{Array1, Array2, Array3, Array4};
7use std::collections::{HashMap, VecDeque};
8
9#[derive(Debug, Clone)]
11pub struct BiologicalVisionConfig {
12 pub cortical_layers: usize,
14 pub receptive_field_sizes: Vec<usize>,
16 pub lateral_inhibition_strength: f64,
18 pub temporal_window: usize,
20 pub attention_radius: usize,
22 pub saccade_horizon: usize,
24 pub color_adaptation_rate: f64,
26 pub motion_prediction_window: usize,
28 pub ommatidial_count: usize,
30 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#[derive(Debug, Clone)]
53pub struct CorticalLayer {
54 pub level: usize,
56 pub feature_maps: Array3<f64>,
58 pub receptive_field_size: usize,
60 pub lateral_connections: Array2<f64>,
62 pub top_down_predictions: Array3<f64>,
64 pub bottom_upfeatures: Array3<f64>,
66 pub prediction_errors: Array3<f64>,
68}
69
70#[derive(Debug, Clone)]
72pub struct RetinaModel {
73 pub photoreceptors: Array2<f64>,
75 pub bipolar_cells: Array2<f64>,
77 pub horizontal_cells: Array2<f64>,
79 pub ganglion_cells: Array2<f64>,
81 pub center_surround_filters: Vec<Array2<f64>>,
83}
84
85#[derive(Debug, Clone)]
87pub struct CompoundEyeModel {
88 pub ommatidia: Vec<Ommatidium>,
90 pub motion_detectors: Array2<f64>,
92 pub wide_field_neurons: Array1<f64>,
94 pub looming_detectors: Array1<f64>,
96}
97
98#[derive(Debug, Clone)]
100pub struct Ommatidium {
101 pub position: (f64, f64),
103 pub optical_axis: (f64, f64, f64),
105 pub response: f64,
107 pub responsehistory: VecDeque<f64>,
109}
110
111#[derive(Debug, Clone)]
113pub struct AttentionSystem {
114 pub attention_center: (usize, usize),
116 pub attention_map: Array2<f64>,
118 pub saccade_targets: Vec<(usize, usize)>,
120 pub inhibition_of_return: Array2<f64>,
122 pub feature_attention_weights: HashMap<String, f64>,
124}
125
126#[derive(Debug, Clone)]
128pub struct PredictiveCodingSystem {
129 pub prediction_models: Vec<Array3<f64>>,
131 pub prediction_errors: Vec<Array3<f64>>,
133 pub temporal_predictions: Vec<Array4<f64>>,
135 pub confidence_estimates: Vec<Array3<f64>>,
137}
138
139#[derive(Debug, Clone)]
141pub struct ColorConstancySystem {
142 pub illumination_estimates: Array2<(f64, f64, f64)>,
144 pub surface_reflectance: Array2<(f64, f64, f64)>,
146 pub adaptationstate: (f64, f64, f64),
148 pub color_memory: Vec<(f64, f64, f64)>,
150}
151
152#[derive(Debug, Clone)]
154pub struct MotionTrack {
155 pub object_id: usize,
157 pub position: (f64, f64),
159 pub velocity: (f64, f64),
161 pub positionhistory: VecDeque<(f64, f64)>,
163 pub predicted_positions: Vec<(f64, f64)>,
165 pub confidence: f64,
167 pub age: usize,
169}
170
171impl CorticalLayer {
172 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)), 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 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 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}