(
dist: &RandomParamDistribution,
rng: &mut R,
)
| 287 | } |
| 288 | |
| 289 | fn sample_distribution<R: Rng + ?Sized>( |
| 290 | dist: &RandomParamDistribution, |
| 291 | rng: &mut R, |
| 292 | ) -> Result<HyperParamValue, String> { |
| 293 | match dist { |
| 294 | RandomParamDistribution::Choice(values) => { |
| 295 | if values.is_empty() { |
| 296 | return Err("choice distribution cannot be empty".to_string()); |
| 297 | } |
| 298 | let idx = rng.gen_range(0..values.len()); |
| 299 | Ok(values[idx].clone()) |
| 300 | } |
| 301 | RandomParamDistribution::Uniform { low, high } => { |
| 302 | if !low.is_finite() || !high.is_finite() || low >= high { |
| 303 | return Err("uniform bounds must be finite and satisfy low < high".to_string()); |
| 304 | } |
| 305 | Ok(HyperParamValue::Float(rng.gen_range(*low..*high))) |
| 306 | } |
| 307 | RandomParamDistribution::LogUniform { low, high } => { |
| 308 | let v = sample_log_uniform(*low, *high, rng)?; |
| 309 | Ok(HyperParamValue::Float(v)) |
| 310 | } |
| 311 | RandomParamDistribution::IntRangeInclusive { low, high } => { |
| 312 | if low > high { |
| 313 | return Err("IntRangeInclusive requires low <= high".to_string()); |
| 314 | } |
| 315 | Ok(HyperParamValue::Int(rng.gen_range(*low..=*high))) |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | fn search_over_params<C, F>( |
| 321 | build_classifier: F, |
no test coverage detected