/rust_sls

Sequential line search in Rust

Primary LanguageRustMIT LicenseMIT

Sequential line search in Rust

Rust bindings for sequential-line-search.

Example

let target = vec![0.1f64, 0.2, 0.3, 0.4, 0.5];
let dims = target.len();
let mut sls = SLSFramework::new(dims);
for it in 0..10 {
    let a = sls.get_parameters_from_slider(0.);
    let b = sls.get_parameters_from_slider(1.);

    // Get closest point to `target` along slider

    // proj = <target-a, b-a>
    // pl   = <b-a, b-a> = |b-a|^2
    let proj : f64 = (b.iter().zip(&a).map(|(bi, ai)| bi-ai))
         .zip(target.iter().zip(&a).map(|(ti,ai)| ti-ai)).map(|(x, y)| x*y).sum();
    let pl : f64 = b.iter().zip(&a).map(|(bi, ai)| (bi-ai)*(bi-ai)).sum();

    let x = proj / pl;
    let x = x.max(0.).min(1.);

    sls.proceed_optimization(x);
}
println!("target: {:?}\nresult: {:?}", target, sls.get_x_max());

License

This project is available under the MIT License