Function simple_optimization::grid_search [−][src]
pub fn grid_search<A: 'static + Send + Sync, T: 'static + Copy + Send + Sync + Default + SampleUniform + PartialOrd + AddAssign + Sub<Output = T> + Div<Output = T> + FromPrimitive, const N: usize>(
ranges: [Range<T>; N],
f: fn(_: &[T; N], _: Option<Arc<A>>) -> f64,
evaluation_data: Option<Arc<A>>,
polling: Option<u64>,
early_exit_minimum: Option<f64>,
points: [u32; N]
) -> [T; N]
Expand description
Evaluate all combinations of values from the 3 values where:
- Value 1 covers
10
values at equal intervals from0..10
(0,1,2,3,4,5,6,7,8,9
). - Value 2 covers
11
values at equal intervals from5..15
. - Value 3 covers
12
values at equal intervals from10..20
.
Printing progress every 10ms
and exiting early if a value is found which is less than or equal to 15.
.
use std::sync::Arc; fn simple_function(list: &[f64; 3], _: Option<Arc<()>>) -> f64 { list.iter().sum() } let best = simple_optimization::grid_search( [0f64..10f64, 5f64..15f64, 10f64..20f64], // Value ranges. simple_function, // Evaluation function. None, // No additional evaluation data. Some(10), // Print progress every `10ms`. Some(15.), // Exit early if `15.` or less is reached. // Take `10` samples along range `0` (`0..10`), `11` along range `1` (`5..15`) // and `12` along range `2` (`10..20`). // In total taking `10*11*12=1320` samples. [10,11,12], ); assert_eq!(simple_function(&best, None), 15.);