scirs2_datasets/generators/
config.rs

1//! Configuration types for dataset generators
2
3use crate::error::{DatasetsError, Result};
4
5/// Missing data patterns for noise injection
6#[derive(Debug, Clone, Copy)]
7pub enum MissingPattern {
8    /// Missing Completely At Random
9    MCAR,
10    /// Missing At Random
11    MAR,
12    /// Missing Not At Random
13    MNAR,
14    /// Block missing pattern
15    Block,
16}
17
18/// Outlier types for injection
19#[derive(Debug, Clone, Copy)]
20pub enum OutlierType {
21    /// Individual point outliers
22    Point,
23    /// Context-dependent outliers
24    Contextual,
25    /// Collective outliers (groups of anomalous points)
26    Collective,
27}
28
29/// GPU-accelerated data generation configuration
30#[derive(Debug, Clone)]
31pub struct GpuConfig {
32    /// Whether to use GPU acceleration
33    pub use_gpu: bool,
34    /// GPU device index (0 for default)
35    pub device_id: usize,
36    /// Whether to use single precision (f32) instead of double (f64)
37    pub use_single_precision: bool,
38    /// Chunk size for GPU operations
39    pub chunk_size: usize,
40}
41
42impl Default for GpuConfig {
43    fn default() -> Self {
44        Self {
45            use_gpu: true,
46            device_id: 0,
47            use_single_precision: false,
48            chunk_size: 10000,
49        }
50    }
51}
52
53impl GpuConfig {
54    /// Create a new GPU configuration
55    pub fn new() -> Self {
56        Self::default()
57    }
58
59    /// Set whether to use GPU
60    pub fn with_gpu(mut self, use_gpu: bool) -> Self {
61        self.use_gpu = use_gpu;
62        self
63    }
64
65    /// Set GPU device ID
66    pub fn with_device(mut self, device_id: usize) -> Self {
67        self.device_id = device_id;
68        self
69    }
70
71    /// Set precision mode
72    pub fn with_single_precision(mut self, single_precision: bool) -> Self {
73        self.use_single_precision = single_precision;
74        self
75    }
76
77    /// Set chunk size
78    pub fn with_chunk_size(mut self, chunk_size: usize) -> Self {
79        self.chunk_size = chunk_size;
80        self
81    }
82}
83
84/// Advanced manifold configuration for complex datasets
85#[derive(Debug, Clone)]
86pub struct ManifoldConfig {
87    /// Type of manifold to generate
88    pub manifold_type: ManifoldType,
89    /// Number of samples
90    pub n_samples: usize,
91    /// Noise level
92    pub noise: f64,
93    /// Random seed
94    pub randomseed: Option<u64>,
95    /// Manifold-specific parameters
96    pub parameters: std::collections::HashMap<String, f64>,
97}
98
99/// Types of manifolds that can be generated
100#[derive(Debug, Clone)]
101pub enum ManifoldType {
102    /// S-curve manifold
103    SCurve,
104    /// Swiss roll (with optional hole)
105    SwissRoll {
106        /// Whether to create a hole in the middle
107        hole: bool,
108    },
109    /// Severed sphere
110    SeveredSphere,
111    /// Twin peaks
112    TwinPeaks,
113    /// Helix with specified turns
114    Helix {
115        /// Number of turns in the helix
116        n_turns: f64,
117    },
118    /// Intersecting manifolds
119    IntersectingManifolds,
120    /// Torus with major and minor radii
121    Torus {
122        /// Major radius of the torus
123        major_radius: f64,
124        /// Minor radius of the torus
125        minor_radius: f64,
126    },
127}
128
129impl Default for ManifoldConfig {
130    fn default() -> Self {
131        Self {
132            manifold_type: ManifoldType::SCurve,
133            n_samples: 1000,
134            noise: 0.1,
135            randomseed: None,
136            parameters: std::collections::HashMap::new(),
137        }
138    }
139}
140
141impl ManifoldConfig {
142    /// Create a new manifold configuration
143    pub fn new(manifold_type: ManifoldType) -> Self {
144        Self {
145            manifold_type,
146            ..Default::default()
147        }
148    }
149
150    /// Set number of samples
151    pub fn with_samples(mut self, n_samples: usize) -> Self {
152        self.n_samples = n_samples;
153        self
154    }
155
156    /// Set noise level
157    pub fn with_noise(mut self, noise: f64) -> Self {
158        self.noise = noise;
159        self
160    }
161
162    /// Set random seed
163    pub fn with_seed(mut self, seed: u64) -> Self {
164        self.randomseed = Some(seed);
165        self
166    }
167
168    /// Add a parameter
169    pub fn with_parameter(mut self, name: String, value: f64) -> Self {
170        self.parameters.insert(name, value);
171        self
172    }
173}