MCPcopy Create free account
hub / github.com/Open-Quant/openquant / sample_distribution

Function sample_distribution

crates/openquant/src/hyperparameter_tuning.rs:289–318  ·  view source on GitHub ↗
(
    dist: &RandomParamDistribution,
    rng: &mut R,
)

Source from the content-addressed store, hash-verified

287}
288
289fn 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
320fn search_over_params<C, F>(
321 build_classifier: F,

Callers 1

randomized_searchFunction · 0.85

Calls 3

sample_log_uniformFunction · 0.85
is_emptyMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected