Function simple_optimization::random_search [−][src]
pub fn random_search<A: 'static + Send + Sync, T: 'static + Copy + Send + Sync + Default + SampleUniform + PartialOrd, 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>,
iterations: u32
) -> [T; N]
Expand description
Randomly pick parameters for simple_function
in the ranges 0..5
, 5..15
, and 10..20
and return the parameters which produce the minimum result from simple_function
out of 10,000
samples, printing progress every 10ms
, and exiting early if a value is found which is less than or equal to 19.
.
use std::sync::Arc; fn simple_function(list: &[f64; 3], _: Option<Arc::<()>>) -> f64 { list.iter().sum() } let best = simple_optimization::random_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(19.), // Exit early if `19..` or less is reached. 1000, // Take `1000` samples (split between threads, so each thread only takes `1000/n` samples). ); assert!(simple_function(&best, None) < 19.);