1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2pub enum SeedRiskProfile {
3 Gaussian,
4 GaussianLocationScale,
8 GeneralizedLinear,
9 Survival,
10}
11
12impl SeedRiskProfile {
13 #[inline]
14 pub const fn anchor_rho_shift(self) -> f64 {
15 match self {
16 Self::Gaussian | Self::GaussianLocationScale => 0.0,
17 Self::GeneralizedLinear => 1.0,
18 Self::Survival => 2.0,
19 }
20 }
21
22 #[inline]
23 pub const fn baseline_centers(self) -> &'static [f64] {
24 match self {
25 Self::Gaussian | Self::GaussianLocationScale => &[0.0, -3.0, 3.0, -6.0, 6.0],
26 Self::GeneralizedLinear => &[0.0, 2.0, 4.0, -2.0],
27 Self::Survival => &[0.0, 2.0, 4.0, 6.0],
28 }
29 }
30
31 #[inline]
32 pub const fn global_shifts(self) -> &'static [f64] {
33 match self {
34 Self::Gaussian | Self::GaussianLocationScale => &[-2.0, 2.0, -4.0, 4.0],
35 Self::GeneralizedLinear => &[0.0, 2.0, 4.0, -1.0, -2.0, -4.0],
36 Self::Survival => &[0.0, 2.0, 4.0, 6.0, -2.0, -4.0],
37 }
38 }
39
40 #[inline]
41 pub const fn exploratory_amplitude(self) -> f64 {
42 match self {
43 Self::Gaussian | Self::GaussianLocationScale => 2.0,
44 Self::GeneralizedLinear => 2.5,
45 Self::Survival => 3.0,
46 }
47 }
48
49 #[inline]
50 pub const fn promotes_interior_seed_extremes(self) -> bool {
51 matches!(
65 self,
66 Self::Gaussian | Self::GaussianLocationScale | Self::GeneralizedLinear | Self::Survival
67 )
68 }
69
70 #[inline]
71 pub const fn uses_parsimonious_keep_best(self) -> bool {
72 matches!(self, Self::GeneralizedLinear | Self::Survival)
73 }
74
75 #[inline]
76 pub const fn uses_lowest_cost_keep_best(self) -> bool {
77 matches!(self, Self::Gaussian | Self::GaussianLocationScale)
78 }
79}
80
81#[derive(Clone, Copy, Debug)]
82pub struct SeedConfig {
83 pub bounds: (f64, f64),
84 pub max_seeds: usize,
85 pub seed_budget: usize,
87 pub screen_max_inner_iterations: usize,
89 pub risk_profile: SeedRiskProfile,
90 pub num_auxiliary_trailing: usize,
93 pub over_smoothing_probe_rho: Option<f64>,
95}
96
97impl Default for SeedConfig {
98 fn default() -> Self {
99 Self {
100 bounds: (-12.0, 12.0),
101 max_seeds: 12,
102 seed_budget: 2,
103 screen_max_inner_iterations: 3,
104 risk_profile: SeedRiskProfile::GeneralizedLinear,
105 num_auxiliary_trailing: 0,
106 over_smoothing_probe_rho: None,
107 }
108 }
109}
110
111#[inline]
112pub fn normalize_seed_bounds(bounds: (f64, f64)) -> (f64, f64) {
113 if bounds.0 <= bounds.1 {
114 bounds
115 } else {
116 (bounds.1, bounds.0)
117 }
118}
119
120#[inline]
121pub fn clamp_seed_rho_to_bounds(value: f64, bounds: (f64, f64)) -> f64 {
122 let (lo, hi) = normalize_seed_bounds(bounds);
123 value.clamp(lo, hi)
124}
125
126#[cfg(test)]
127mod tests {
128 use super::*;
129
130 #[test]
133 fn anchor_rho_shift_gaussian_is_zero() {
134 assert_eq!(SeedRiskProfile::Gaussian.anchor_rho_shift(), 0.0);
135 assert_eq!(
136 SeedRiskProfile::GaussianLocationScale.anchor_rho_shift(),
137 0.0
138 );
139 }
140
141 #[test]
142 fn anchor_rho_shift_generalized_linear_is_one() {
143 assert_eq!(SeedRiskProfile::GeneralizedLinear.anchor_rho_shift(), 1.0);
144 }
145
146 #[test]
147 fn anchor_rho_shift_survival_is_two() {
148 assert_eq!(SeedRiskProfile::Survival.anchor_rho_shift(), 2.0);
149 }
150
151 #[test]
154 fn promotes_interior_extremes_for_all_profiles() {
155 assert!(SeedRiskProfile::Gaussian.promotes_interior_seed_extremes());
165 assert!(SeedRiskProfile::GaussianLocationScale.promotes_interior_seed_extremes());
166 assert!(SeedRiskProfile::GeneralizedLinear.promotes_interior_seed_extremes());
167 assert!(SeedRiskProfile::Survival.promotes_interior_seed_extremes());
168 }
169
170 #[test]
173 fn parsimonious_keep_best_only_for_glm_and_survival() {
174 assert!(!SeedRiskProfile::Gaussian.uses_parsimonious_keep_best());
175 assert!(!SeedRiskProfile::GaussianLocationScale.uses_parsimonious_keep_best());
176 assert!(SeedRiskProfile::GeneralizedLinear.uses_parsimonious_keep_best());
177 assert!(SeedRiskProfile::Survival.uses_parsimonious_keep_best());
178 }
179
180 #[test]
181 fn lowest_cost_keep_best_only_for_gaussian_variants() {
182 assert!(SeedRiskProfile::Gaussian.uses_lowest_cost_keep_best());
183 assert!(SeedRiskProfile::GaussianLocationScale.uses_lowest_cost_keep_best());
184 assert!(!SeedRiskProfile::GeneralizedLinear.uses_lowest_cost_keep_best());
185 assert!(!SeedRiskProfile::Survival.uses_lowest_cost_keep_best());
186 }
187
188 #[test]
191 fn normalize_already_ordered_bounds_unchanged() {
192 assert_eq!(normalize_seed_bounds((-3.0, 5.0)), (-3.0, 5.0));
193 }
194
195 #[test]
196 fn normalize_reversed_bounds_swaps() {
197 assert_eq!(normalize_seed_bounds((5.0, -3.0)), (-3.0, 5.0));
198 }
199
200 #[test]
201 fn normalize_equal_bounds_unchanged() {
202 assert_eq!(normalize_seed_bounds((2.0, 2.0)), (2.0, 2.0));
203 }
204
205 #[test]
208 fn clamp_within_bounds_returns_value() {
209 assert_eq!(clamp_seed_rho_to_bounds(1.0, (-3.0, 5.0)), 1.0);
210 }
211
212 #[test]
213 fn clamp_below_lo_returns_lo() {
214 assert_eq!(clamp_seed_rho_to_bounds(-10.0, (-3.0, 5.0)), -3.0);
215 }
216
217 #[test]
218 fn clamp_above_hi_returns_hi() {
219 assert_eq!(clamp_seed_rho_to_bounds(100.0, (-3.0, 5.0)), 5.0);
220 }
221
222 #[test]
223 fn clamp_normalizes_reversed_bounds_before_clamping() {
224 assert_eq!(clamp_seed_rho_to_bounds(100.0, (5.0, -3.0)), 5.0);
226 }
227}