1use crate::EvaluationMetric;
7use scirs2_core::numeric::Float;
8use std::collections::HashMap;
9use std::fmt::Debug;
10use std::time::Duration;
11
12#[derive(Debug, Clone)]
14pub struct NASConfig<T: Float + Debug + Send + Sync + 'static> {
15 pub search_strategy: SearchStrategyType,
17
18 pub search_space: SearchSpaceConfig,
20
21 pub evaluation_config: EvaluationConfig<T>,
23
24 pub multi_objective_config: MultiObjectiveConfig<T>,
26
27 pub search_budget: usize,
29
30 pub early_stopping: EarlyStoppingConfig<T>,
32
33 pub progressive_search: bool,
35
36 pub population_size: usize,
38
39 pub enable_transfer_learning: bool,
41
42 pub encoding_strategy: ArchitectureEncodingStrategy,
44
45 pub enable_performance_prediction: bool,
47
48 pub parallelization_factor: usize,
50
51 pub auto_hyperparameter_tuning: bool,
53
54 pub resource_constraints: ResourceConstraints<T>,
56}
57
58#[derive(Debug, Clone)]
60pub enum SearchStrategyType {
61 Random,
63
64 Evolutionary,
66
67 ReinforcementLearning,
69
70 Differentiable,
72
73 BayesianOptimization,
75
76 Progressive,
78
79 MultiObjectiveEvolutionary,
81
82 NeuralPredictorBased,
84}
85
86#[derive(Debug, Clone)]
88pub struct SearchSpaceConfig {
89 pub components: Vec<OptimizerComponentConfig>,
91
92 pub connection_patterns: Vec<ConnectionPatternType>,
94
95 pub learning_rate_schedules: LearningRateScheduleSpace,
97
98 pub regularization_techniques: RegularizationSpace,
100
101 pub adaptive_mechanisms: AdaptiveMechanismSpace,
103
104 pub memory_constraints: MemoryConstraints,
106
107 pub computation_constraints: ComputationConstraints,
109
110 pub component_types: Vec<ComponentType>,
112
113 pub max_components: usize,
115
116 pub min_components: usize,
118
119 pub max_connections: usize,
121}
122
123#[derive(Debug, Clone)]
125pub struct OptimizerComponentConfig {
126 pub component_type: ComponentType,
128
129 pub hyperparameter_ranges: HashMap<String, ParameterRange>,
131
132 pub complexity_score: f64,
134
135 pub memory_requirement: usize,
137
138 pub computational_cost: f64,
140
141 pub compatibility_constraints: Vec<CompatibilityConstraint>,
143}
144
145#[derive(Debug, Clone, Default)]
147pub struct ArchitectureConstraints {
148 pub min_parameters: Option<usize>,
150 pub max_parameters: Option<usize>,
152 pub input_dimensions: Vec<usize>,
154 pub output_dimensions: Vec<usize>,
156 pub compatibility_rules: Vec<String>,
158}
159
160#[derive(Debug, Clone)]
162pub struct ComponentTypeConfig {
163 pub name: String,
165 pub parameters: Vec<String>,
167 pub defaults: HashMap<String, String>,
169 pub enabled: bool,
171 pub probability: f64,
173 pub hyperparameter_ranges: HashMap<String, ParameterRange>,
175 pub dependencies: Vec<String>,
177 pub component_type: ComponentType,
179 pub constraints: ArchitectureConstraints,
181}
182
183#[derive(Debug, Clone, PartialEq, Eq, Hash)]
185pub enum ComponentType {
186 GradientComputation,
188
189 Momentum,
191
192 AdaptiveLearningRate,
194
195 Regularization,
197
198 Normalization,
200
201 SecondOrder,
203
204 Preconditioning,
206
207 LearningRateScheduling,
209
210 GradientClipping,
212
213 MemoryManagement,
215
216 ConvergenceAcceleration,
218
219 SGD,
221 Adam,
222 AdamW,
223 RMSprop,
224 AdaGrad,
225 AdaDelta,
226 Nesterov,
227 LRScheduler,
228 BatchNorm,
229 Dropout,
230 LAMB,
231 LARS,
232 Lion,
233 RAdam,
234 Lookahead,
235 SAM,
236 LBFGS,
237 SparseAdam,
238 GroupedAdam,
239 MAML,
240 Reptile,
241 MetaSGD,
242 ConstantLR,
243 ExponentialLR,
244 StepLR,
245 CosineAnnealingLR,
246 OneCycleLR,
247 CyclicLR,
248 L1Regularizer,
249 L2Regularizer,
250 ElasticNetRegularizer,
251 DropoutRegularizer,
252 WeightDecay,
253 AdaptiveLR,
254 AdaptiveMomentum,
255 AdaptiveRegularization,
256 LSTMOptimizer,
257 TransformerOptimizer,
258 AttentionOptimizer,
259
260 Custom(String),
262}
263
264#[derive(Debug, Clone)]
266pub enum ParameterRange {
267 Continuous(f64, f64),
269
270 Discrete(Vec<f64>),
272
273 Integer(i32, i32),
275
276 Boolean,
278
279 Categorical(Vec<String>),
281
282 LogUniform(f64, f64),
284}
285
286#[derive(Debug, Clone)]
288pub enum ConnectionPatternType {
289 Sequential,
291
292 Parallel,
294
295 SkipConnection,
297
298 DenseConnection,
300
301 ResidualConnection,
303
304 AttentionConnection,
306
307 HighwayConnection,
309
310 SqueezeExcitationConnection,
312
313 Custom(String),
315}
316
317#[derive(Debug, Clone)]
319pub struct LearningRateScheduleSpace {
320 pub schedule_types: Vec<ScheduleType>,
322
323 pub initial_lr_range: ParameterRange,
325
326 pub schedule_parameters: HashMap<ScheduleType, HashMap<String, ParameterRange>>,
328}
329
330#[derive(Debug, Clone, PartialEq, Eq, Hash)]
332pub enum ScheduleType {
333 Constant,
334 StepDecay,
335 ExponentialDecay,
336 CosineAnnealing,
337 CyclicalLR,
338 OneCycleLR,
339 ReduceOnPlateau,
340 WarmupLinear,
341 WarmupCosine,
342 Custom(String),
343}
344
345#[derive(Debug, Clone)]
347pub struct RegularizationSpace {
348 pub techniques: Vec<RegularizationTechnique>,
350
351 pub strength_ranges: HashMap<RegularizationTechnique, ParameterRange>,
353
354 pub combination_strategies: Vec<String>,
356}
357
358#[derive(Debug, Clone, PartialEq, Eq, Hash)]
360pub enum RegularizationTechnique {
361 L1,
362 L2,
363 Dropout,
364 DropConnect,
365 BatchNormalization,
366 LayerNormalization,
367 GroupNormalization,
368 SpectralNormalization,
369 WeightDecay,
370 EarlyStopping,
371 Custom(String),
372}
373
374#[derive(Debug, Clone)]
376pub struct AdaptiveMechanismSpace {
377 pub adaptation_strategies: Vec<AdaptationStrategy>,
379
380 pub adaptation_parameters: HashMap<AdaptationStrategy, HashMap<String, ParameterRange>>,
382
383 pub adaptation_frequencies: Vec<usize>,
385}
386
387#[derive(Debug, Clone, PartialEq, Eq, Hash)]
389pub enum AdaptationStrategy {
390 PerformanceBased,
391 GradientBased,
392 LossBased,
393 TimeBased,
394 HybridAdaptation,
395 Custom(String),
396}
397
398#[derive(Debug, Clone)]
400pub struct MemoryConstraints {
401 pub max_memory_bytes: usize,
403
404 pub component_memory_limits: HashMap<ComponentType, usize>,
406
407 pub enable_memory_optimization: bool,
409
410 pub allocation_strategy: MemoryAllocationStrategy,
412}
413
414#[derive(Debug, Clone)]
416pub enum MemoryAllocationStrategy {
417 Static,
418 Dynamic,
419 Adaptive,
420 Lazy,
421}
422
423#[derive(Debug, Clone)]
425pub struct ComputationConstraints {
426 pub max_computational_cost: f64,
428
429 pub component_cost_limits: HashMap<ComponentType, f64>,
431
432 pub enable_computation_optimization: bool,
434
435 pub parallelization_constraints: ParallelizationConstraints,
437}
438
439#[derive(Debug, Clone)]
441pub struct ParallelizationConstraints {
442 pub max_workers: usize,
444
445 pub min_batch_size: usize,
447
448 pub enable_simd: bool,
450
451 pub enable_gpu: bool,
453}
454
455#[derive(Debug, Clone)]
457pub struct CompatibilityConstraint {
458 pub constraint_type: CompatibilityType,
460
461 pub target_components: Vec<ComponentType>,
463
464 pub condition: ConstraintCondition,
466}
467
468#[derive(Debug, Clone)]
470pub enum CompatibilityType {
471 Requires,
473
474 Excludes,
476
477 Conditional,
479
480 VersionRequirement,
482
483 ParameterConstraint,
485
486 Custom(String),
488}
489
490#[derive(Debug, Clone)]
492pub enum ConstraintCondition {
493 Always,
495
496 Never,
498
499 ParameterCondition(ParameterCondition),
501
502 ArchitectureCondition(String),
504
505 Custom(String),
507}
508
509#[derive(Debug, Clone)]
511pub enum ParameterCondition {
512 Equals(String, f64),
514
515 GreaterThan(String, f64),
517
518 LessThan(String, f64),
520
521 InRange(String, f64, f64),
523
524 InSet(String, Vec<f64>),
526
527 BooleanExpression(String),
529}
530
531#[derive(Debug, Clone)]
533pub struct EvaluationConfig<T: Float + Debug + Send + Sync + 'static> {
534 pub metrics: Vec<EvaluationMetric>,
536
537 pub benchmark_datasets: Vec<BenchmarkDataset>,
539
540 pub evaluation_budget: EvaluationBudget,
542
543 pub statistical_testing: StatisticalTestingConfig,
545
546 pub cross_validation_folds: usize,
548
549 pub enable_early_stopping: bool,
551
552 pub parallelization_factor: usize,
554
555 pub problem_domains: Vec<ProblemDomain>,
557
558 pub resource_limits: HashMap<ResourceType, T>,
560}
561
562#[derive(Debug, Clone)]
564pub enum ProblemDomain {
565 Classification,
566 Regression,
567 Reinforcement,
568 GenerativeModeling,
569 SequenceModeling,
570 ComputerVision,
571 NaturalLanguageProcessing,
572 TimeSeriesForecasting,
573 Custom(String),
574}
575
576#[derive(Debug, Clone, PartialEq, Eq, Hash)]
578pub enum ResourceType {
579 Memory,
580 CPUTime,
581 GPUTime,
582 NetworkBandwidth,
583 StorageSpace,
584}
585
586#[derive(Debug, Clone)]
588pub struct BenchmarkDataset {
589 pub name: String,
591
592 pub path: String,
594
595 pub characteristics: DatasetCharacteristics,
597
598 pub problem_type: ProblemType,
600
601 pub weight: f64,
603
604 pub enable_augmentation: bool,
606}
607
608#[derive(Debug, Clone)]
610pub struct DatasetCharacteristics {
611 pub num_samples: usize,
613
614 pub num_features: usize,
616
617 pub num_classes: Option<usize>,
619
620 pub size_category: DatasetSizeCategory,
622
623 pub correlation_structure: CorrelationStructure,
625
626 pub noise_level: f64,
628
629 pub imbalance_ratio: Option<f64>,
631}
632
633#[derive(Debug, Clone)]
635pub enum ProblemType {
636 BinaryClassification,
637 MultiClassClassification,
638 Regression,
639 MultiTaskLearning,
640 MetaLearning,
641 TransferLearning,
642 FewShotLearning,
643 Custom(String),
644}
645
646#[derive(Debug, Clone)]
648pub enum DatasetSizeCategory {
649 Small, Medium, Large, VeryLarge, }
654
655#[derive(Debug, Clone)]
657pub enum CorrelationStructure {
658 Independent,
659 LowCorrelation,
660 ModerateCorrelation,
661 HighCorrelation,
662 BlockStructure,
663 Hierarchical,
664}
665
666#[derive(Debug, Clone)]
668pub struct EvaluationBudget {
669 pub max_time_per_architecture: Duration,
671
672 pub max_epochs: usize,
674
675 pub max_function_evaluations: usize,
677
678 pub early_stopping_patience: usize,
680
681 pub resource_allocation: ResourceAllocation,
683}
684
685#[derive(Debug, Clone)]
687pub struct ResourceAllocation {
688 pub cpu_cores: usize,
690
691 pub memory_gb: f64,
693
694 pub gpu_devices: usize,
696
697 pub storage_gb: f64,
699}
700
701#[derive(Debug, Clone)]
703pub struct StatisticalTestingConfig {
704 pub significance_level: f64,
706
707 pub test_type: StatisticalTestType,
709
710 pub multiple_comparison_correction: MultipleComparisonCorrection,
712
713 pub min_effect_size: f64,
715
716 pub bootstrap_samples: usize,
718}
719
720#[derive(Debug, Clone)]
722pub enum StatisticalTestType {
723 TTest,
724 WilcoxonRankSum,
725 KruskalWallis,
726 FriedmanTest,
727 Bootstrap,
728}
729
730#[derive(Debug, Clone)]
732pub enum MultipleComparisonCorrection {
733 None,
734 Bonferroni,
735 BenjaminiHochberg,
736 BenjaminiYekutieli,
737 Holm,
738}
739
740#[derive(Debug, Clone)]
742pub struct MultiObjectiveConfig<T: Float + Debug + Send + Sync + 'static> {
743 pub objectives: Vec<ObjectiveConfig<T>>,
745
746 pub algorithm: MultiObjectiveAlgorithm,
748
749 pub user_preferences: Option<UserPreferences<T>>,
758
759 pub diversity_strategy: DiversityStrategy,
761
762 pub constraint_handling: ConstraintHandlingMethod,
771}
772
773#[derive(Debug, Clone)]
775pub struct ObjectiveConfig<T: Float + Debug + Send + Sync + 'static> {
776 pub name: String,
778
779 pub objective_type: ObjectiveType,
781
782 pub direction: OptimizationDirection,
784
785 pub weight: T,
787
788 pub priority: ObjectivePriority,
790
791 pub normalization_bounds: Option<(T, T)>,
793}
794
795#[derive(Debug, Clone)]
797pub enum ObjectiveType {
798 Accuracy,
799 Loss,
800 TrainingTime,
801 InferenceTime,
802 MemoryUsage,
803 EnergyConsumption,
804 ModelSize,
805 Robustness,
806 Fairness,
807 Performance,
808 Efficiency,
809 Interpretability,
810 Privacy,
811 Sustainability,
812 Cost,
813 Custom(String),
814}
815
816#[derive(Debug, Clone)]
818pub enum OptimizationDirection {
819 Minimize,
820 Maximize,
821}
822
823#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
825pub enum ObjectivePriority {
826 Low,
827 Medium,
828 High,
829 Critical,
830}
831
832#[derive(Debug, Clone)]
834pub enum MultiObjectiveAlgorithm {
835 NSGA2,
836 NSGA3,
837 MOEAD,
838 SPEA2,
839 PAES,
840 WeightedSum,
841 EpsilonConstraint,
842 GoalProgramming,
843 Custom(String),
844}
845
846#[derive(Debug, Clone)]
848pub struct UserPreferences<T: Float + Debug + Send + Sync + 'static> {
849 pub preference_type: PreferenceType<T>,
851
852 pub reference_point: Option<Vec<T>>,
854
855 pub aspiration_levels: Option<Vec<T>>,
857
858 pub reservation_levels: Option<Vec<T>>,
860}
861
862#[derive(Debug, Clone)]
864pub enum PreferenceType<T: Float + Debug + Send + Sync + 'static> {
865 WeightVector(Vec<T>),
866 ReferencePoint(Vec<T>),
867 GoalVector(Vec<T>),
868 RankingOrder(Vec<usize>),
869 PairwiseComparison(Vec<(usize, usize)>),
870}
871
872#[derive(Debug, Clone)]
874pub enum DiversityStrategy {
875 Crowding,
876 Sharing,
877 Clearing,
878 Clustering,
879 Novelty,
880 Custom(String),
881}
882
883#[derive(Debug, Clone)]
885pub enum ConstraintHandlingMethod {
886 PenaltyFunction,
887 DeathPenalty,
888 Repair,
889 Decoder,
890 PreserveFeasibility,
891 Custom(String),
892}
893
894#[derive(Debug, Clone)]
896pub struct EarlyStoppingConfig<T: Float + Debug + Send + Sync + 'static> {
897 pub enabled: bool,
899
900 pub patience: usize,
902
903 pub min_improvement: T,
905
906 pub convergence_strategy: ConvergenceDetectionStrategy,
908
909 pub min_generations: usize,
911
912 pub metric: EvaluationMetric,
914
915 pub target_performance: Option<T>,
917
918 pub convergence_detection: ConvergenceDetectionStrategy,
920}
921
922#[derive(Debug, Clone)]
924pub enum ConvergenceDetectionStrategy {
925 BestScore,
926 AverageScore,
927 PopulationDiversity,
928 ParetoFrontStability,
929 NoImprovement,
930 Custom(String),
931}
932
933#[derive(Debug, Clone)]
935pub enum ArchitectureEncodingStrategy {
936 Direct,
938
939 Graph,
941
942 String,
944
945 Binary,
947
948 RealValued,
950
951 Hierarchical,
953
954 Neural,
956
957 Hybrid,
959
960 Custom(String),
962}
963
964#[derive(Debug, Clone)]
966pub struct ResourceConstraints<T: Float + Debug + Send + Sync + 'static> {
967 pub hardware_resources: HardwareResources,
969
970 pub time_constraints: TimeConstraints,
972
973 pub energy_constraints: Option<T>,
975
976 pub cost_constraints: Option<T>,
978
979 pub violation_handling: ResourceViolationHandling,
981
982 pub max_memory_gb: T,
984
985 pub max_computation_hours: T,
987
988 pub max_energy_kwh: T,
990
991 pub max_cost_usd: T,
993
994 pub enable_monitoring: bool,
996}
997
998#[derive(Debug, Clone)]
1000pub struct HardwareResources {
1001 pub max_memory_gb: f64,
1003
1004 pub max_cpu_cores: usize,
1006
1007 pub max_gpu_devices: usize,
1009
1010 pub max_storage_gb: f64,
1012
1013 pub max_network_bandwidth: f64,
1015
1016 pub enable_cloud_scaling: bool,
1018
1019 pub cloud_budget: Option<f64>,
1021
1022 pub cpu_cores: usize,
1024
1025 pub ram_gb: u32,
1027
1028 pub num_gpus: usize,
1030
1031 pub gpu_memory_gb: u32,
1033
1034 pub storage_gb: u32,
1036
1037 pub network_bandwidth_mbps: f32,
1039}
1040
1041#[derive(Debug, Clone)]
1043pub struct TimeConstraints {
1044 pub max_search_time: Duration,
1046
1047 pub max_evaluation_time: Duration,
1049
1050 pub search_deadline: Option<std::time::Instant>,
1052
1053 pub budget_allocation: TimeBudgetAllocation,
1055}
1056
1057#[derive(Debug, Clone)]
1059pub enum TimeBudgetAllocation {
1060 Uniform,
1061 AdaptiveByComplexity,
1062 AdaptiveByPerformance,
1063 PriorityBased,
1064 Custom(String),
1065}
1066
1067#[derive(Debug, Clone)]
1069pub enum ResourceViolationHandling {
1070 Abort,
1072
1073 Skip,
1075
1076 ScaleDown,
1078
1079 Approximate,
1081
1082 Dynamic,
1084
1085 Penalty,
1087
1088 Custom(String),
1090}
1091
1092impl<T: Float + Debug + Send + Sync + 'static> Default for NASConfig<T> {
1094 fn default() -> Self {
1095 Self {
1096 search_strategy: SearchStrategyType::Evolutionary,
1097 search_space: SearchSpaceConfig::default(),
1098 evaluation_config: EvaluationConfig::default(),
1099 multi_objective_config: MultiObjectiveConfig::default(),
1100 search_budget: 100,
1101 early_stopping: EarlyStoppingConfig::default(),
1102 progressive_search: false,
1103 population_size: 20,
1104 enable_transfer_learning: false,
1105 encoding_strategy: ArchitectureEncodingStrategy::Graph,
1106 enable_performance_prediction: false,
1107 parallelization_factor: 1,
1108 auto_hyperparameter_tuning: false,
1109 resource_constraints: ResourceConstraints::default(),
1110 }
1111 }
1112}
1113
1114impl Default for SearchSpaceConfig {
1115 fn default() -> Self {
1116 Self {
1117 components: Vec::new(),
1118 connection_patterns: vec![
1119 ConnectionPatternType::Sequential,
1120 ConnectionPatternType::Parallel,
1121 ConnectionPatternType::SkipConnection,
1122 ],
1123 learning_rate_schedules: LearningRateScheduleSpace::default(),
1124 regularization_techniques: RegularizationSpace::default(),
1125 adaptive_mechanisms: AdaptiveMechanismSpace::default(),
1126 memory_constraints: MemoryConstraints::default(),
1127 computation_constraints: ComputationConstraints::default(),
1128 component_types: vec![ComponentType::SGD, ComponentType::Adam],
1129 max_components: 10,
1130 min_components: 1,
1131 max_connections: 20,
1132 }
1133 }
1134}
1135
1136impl Default for LearningRateScheduleSpace {
1137 fn default() -> Self {
1138 Self {
1139 schedule_types: vec![
1140 ScheduleType::Constant,
1141 ScheduleType::StepDecay,
1142 ScheduleType::ExponentialDecay,
1143 ScheduleType::CosineAnnealing,
1144 ],
1145 initial_lr_range: ParameterRange::LogUniform(1e-5, 1e-1),
1146 schedule_parameters: HashMap::new(),
1147 }
1148 }
1149}
1150
1151impl Default for RegularizationSpace {
1152 fn default() -> Self {
1153 Self {
1154 techniques: vec![
1155 RegularizationTechnique::L1,
1156 RegularizationTechnique::L2,
1157 RegularizationTechnique::Dropout,
1158 RegularizationTechnique::WeightDecay,
1159 ],
1160 strength_ranges: HashMap::new(),
1161 combination_strategies: Vec::new(),
1162 }
1163 }
1164}
1165
1166impl Default for AdaptiveMechanismSpace {
1167 fn default() -> Self {
1168 Self {
1169 adaptation_strategies: vec![
1170 AdaptationStrategy::PerformanceBased,
1171 AdaptationStrategy::GradientBased,
1172 AdaptationStrategy::LossBased,
1173 ],
1174 adaptation_parameters: HashMap::new(),
1175 adaptation_frequencies: vec![1, 5, 10, 25, 50, 100],
1176 }
1177 }
1178}
1179
1180impl Default for MemoryConstraints {
1181 fn default() -> Self {
1182 Self {
1183 max_memory_bytes: 32 * 1024 * 1024 * 1024, component_memory_limits: HashMap::new(),
1185 enable_memory_optimization: true,
1186 allocation_strategy: MemoryAllocationStrategy::Dynamic,
1187 }
1188 }
1189}
1190
1191impl Default for ComputationConstraints {
1192 fn default() -> Self {
1193 Self {
1194 max_computational_cost: 1000.0,
1195 component_cost_limits: HashMap::new(),
1196 enable_computation_optimization: true,
1197 parallelization_constraints: ParallelizationConstraints::default(),
1198 }
1199 }
1200}
1201
1202impl Default for ParallelizationConstraints {
1203 fn default() -> Self {
1204 Self {
1205 max_workers: num_cpus::get(),
1206 min_batch_size: 32,
1207 enable_simd: true,
1208 enable_gpu: true,
1209 }
1210 }
1211}
1212
1213impl<T: Float + Debug + Send + Sync + 'static> Default for EvaluationConfig<T> {
1214 fn default() -> Self {
1215 Self {
1216 metrics: vec![EvaluationMetric::Accuracy, EvaluationMetric::TrainingTime],
1217 benchmark_datasets: Vec::new(),
1218 evaluation_budget: EvaluationBudget::default(),
1219 statistical_testing: StatisticalTestingConfig::default(),
1220 cross_validation_folds: 5,
1221 enable_early_stopping: true,
1222 parallelization_factor: 1,
1223 problem_domains: vec![ProblemDomain::Classification],
1224 resource_limits: HashMap::new(),
1225 }
1226 }
1227}
1228
1229impl Default for EvaluationBudget {
1230 fn default() -> Self {
1231 Self {
1232 max_time_per_architecture: Duration::from_secs(300),
1233 max_epochs: 100,
1234 max_function_evaluations: 1000,
1235 early_stopping_patience: 10,
1236 resource_allocation: ResourceAllocation::default(),
1237 }
1238 }
1239}
1240
1241impl Default for ResourceAllocation {
1242 fn default() -> Self {
1243 Self {
1244 cpu_cores: 4,
1245 memory_gb: 8.0,
1246 gpu_devices: 1,
1247 storage_gb: 10.0,
1248 }
1249 }
1250}
1251
1252impl Default for StatisticalTestingConfig {
1253 fn default() -> Self {
1254 Self {
1255 significance_level: 0.05,
1256 test_type: StatisticalTestType::TTest,
1257 multiple_comparison_correction: MultipleComparisonCorrection::BenjaminiHochberg,
1258 min_effect_size: 0.1,
1259 bootstrap_samples: 1000,
1260 }
1261 }
1262}
1263
1264impl<T: Float + Debug + Send + Sync + 'static> Default for MultiObjectiveConfig<T> {
1265 fn default() -> Self {
1266 Self {
1267 objectives: Vec::new(),
1268 algorithm: MultiObjectiveAlgorithm::NSGA2,
1269 user_preferences: None,
1270 diversity_strategy: DiversityStrategy::Crowding,
1271 constraint_handling: ConstraintHandlingMethod::PenaltyFunction,
1272 }
1273 }
1274}
1275
1276impl<T: Float + Debug + Send + Sync + 'static> Default for EarlyStoppingConfig<T> {
1277 fn default() -> Self {
1278 Self {
1279 enabled: true,
1280 patience: 20,
1281 min_improvement: scirs2_core::numeric::NumCast::from(0.001)
1282 .unwrap_or_else(|| T::zero()),
1283 convergence_strategy: ConvergenceDetectionStrategy::BestScore,
1284 min_generations: 10,
1285 metric: EvaluationMetric::Accuracy,
1286 target_performance: None,
1287 convergence_detection: ConvergenceDetectionStrategy::NoImprovement,
1288 }
1289 }
1290}
1291
1292impl<T: Float + Debug + Send + Sync + 'static> Default for ResourceConstraints<T> {
1293 fn default() -> Self {
1294 Self {
1295 hardware_resources: HardwareResources::default(),
1296 time_constraints: TimeConstraints::default(),
1297 energy_constraints: None,
1298 cost_constraints: None,
1299 violation_handling: ResourceViolationHandling::Skip,
1300 max_memory_gb: scirs2_core::numeric::NumCast::from(32.0).unwrap_or_else(|| T::zero()),
1301 max_computation_hours: scirs2_core::numeric::NumCast::from(24.0)
1302 .unwrap_or_else(|| T::zero()),
1303 max_energy_kwh: scirs2_core::numeric::NumCast::from(100.0).unwrap_or_else(|| T::zero()),
1304 max_cost_usd: scirs2_core::numeric::NumCast::from(1000.0).unwrap_or_else(|| T::zero()),
1305 enable_monitoring: true,
1306 }
1307 }
1308}
1309
1310impl Default for HardwareResources {
1311 fn default() -> Self {
1312 Self {
1313 max_memory_gb: 32.0,
1314 max_cpu_cores: num_cpus::get(),
1315 max_gpu_devices: 4,
1316 max_storage_gb: 100.0,
1317 max_network_bandwidth: 1000.0, enable_cloud_scaling: false,
1319 cloud_budget: None,
1320 cpu_cores: num_cpus::get(),
1321 ram_gb: 32,
1322 num_gpus: 1,
1323 gpu_memory_gb: 8,
1324 storage_gb: 100,
1325 network_bandwidth_mbps: 1000.0,
1326 }
1327 }
1328}
1329
1330impl Default for TimeConstraints {
1331 fn default() -> Self {
1332 Self {
1333 max_search_time: Duration::from_secs(3600), max_evaluation_time: Duration::from_secs(300), search_deadline: None,
1336 budget_allocation: TimeBudgetAllocation::Uniform,
1337 }
1338 }
1339}
1340
1341#[cfg(test)]
1342mod tests {
1343 use super::*;
1344
1345 #[test]
1346 fn test_nas_config_default() {
1347 let config = NASConfig::<f32>::default();
1348 assert_eq!(config.search_budget, 100);
1349 assert_eq!(config.population_size, 20);
1350 assert!(!config.progressive_search);
1351 }
1352
1353 #[test]
1354 fn test_search_space_config_default() {
1355 let config = SearchSpaceConfig::default();
1356 assert!(!config.connection_patterns.is_empty());
1357 assert_eq!(config.connection_patterns.len(), 3);
1358 }
1359
1360 #[test]
1361 fn test_parameter_range_variants() {
1362 let continuous = ParameterRange::Continuous(0.0, 1.0);
1363 let discrete = ParameterRange::Discrete(vec![0.1, 0.5, 0.9]);
1364 let integer = ParameterRange::Integer(1, 10);
1365
1366 match continuous {
1367 ParameterRange::Continuous(min, max) => {
1368 assert_eq!(min, 0.0);
1369 assert_eq!(max, 1.0);
1370 }
1371 _ => panic!("Expected continuous range"),
1372 }
1373
1374 match discrete {
1375 ParameterRange::Discrete(values) => {
1376 assert_eq!(values.len(), 3);
1377 }
1378 _ => panic!("Expected discrete range"),
1379 }
1380
1381 match integer {
1382 ParameterRange::Integer(min, max) => {
1383 assert_eq!(min, 1);
1384 assert_eq!(max, 10);
1385 }
1386 _ => panic!("Expected integer range"),
1387 }
1388 }
1389}