rust_sls

Crates.iorust_sls
lib.rsrust_sls
version0.1.1
sourcesrc
created_at2019-06-13 03:22:35.797073
updated_at2020-10-26 13:19:47.872719
descriptionSequential Line Search for Design Optimization
homepage
repositoryhttps://github.com/mad-s/rust_sls
max_upload_size
id140749
size2,943,141
mad-s (mad-s)

documentation

README

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

Commit count: 6

cargo fmt