diff --git a/src/core/base.rs b/src/core/base.rs index 3eeb98e..7524fbc 100644 --- a/src/core/base.rs +++ b/src/core/base.rs @@ -51,7 +51,11 @@ pub trait Sample { impl Sample for f32 { fn sample_any(rng: &mut Rng) -> Self { - rng.f32() + // Sampling from the whole range is likely not desired. Choosing + // sqrt(MAX) as an arbitrary bound. + let max = f32::MAX.sqrt(); + let min = -max; + rng.f32_range(min..=max) } fn sample_uniform(lower: Self, upper: Self, rng: &mut Rng) -> Self { @@ -65,7 +69,11 @@ impl Sample for f32 { impl Sample for f64 { fn sample_any(rng: &mut Rng) -> Self { - rng.f64() + // Sampling from the whole range is likely not desired. Choosing + // cbrt(MAX) as an arbitrary bound. + let max = f64::MAX.cbrt(); + let min = -max; + rng.f64_range(min..=max) } fn sample_uniform(lower: Self, upper: Self, rng: &mut Rng) -> Self { diff --git a/src/solver/lipo.rs b/src/solver/lipo.rs index d45de35..0c92c54 100644 --- a/src/solver/lipo.rs +++ b/src/solver/lipo.rs @@ -433,7 +433,10 @@ mod tests { let n = 2; let f = Sphere::new(n); - let dom = f.domain(); + // We are going to run LIPO without any local optimization and "any + // potential minimizer" strategy. In such a setting, it would be + // impossible for LIPO to find good points in the unconstrained domain. + let dom = (0..n).map(|_| (-1.0, 1.0)).collect(); let eps = convert(1e-3); let rng = Rng::with_seed(3); let mut options = LipoOptions::default(); @@ -443,7 +446,7 @@ mod tests { for x in f.initials() { let optimizer = Lipo::with_options(&f, &dom, options.clone(), rng.clone()); - optimize(&f, &dom, optimizer, x, convert(0.0), 250, eps).unwrap(); + optimize(&f, &dom, optimizer, x, convert(0.0), 1000, eps).unwrap(); } } }