#optimization #line-search #bindings #bayesian

rust_sls

Sequential Line Search for Design Optimization

2 releases

0.1.1 Oct 26, 2020
0.1.0 Jun 13, 2019

#516 in Science

23 downloads per month

MIT license

2MB
38K SLoC

C 21K SLoC // 0.3% comments FORTRAN Legacy 7K SLoC // 0.4% comments C++ 3.5K SLoC // 0.1% comments SWIG 2.5K SLoC // 0.2% comments Python 2.5K SLoC // 0.3% comments Objective-C 603 SLoC F# 181 SLoC // 0.0% comments Rust 157 SLoC // 0.0% comments Shell 66 SLoC // 0.2% comments Scheme 33 SLoC Forge Config 9 SLoC // 0.2% comments

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


lib.rs:

Rust Bindings for Sequential Line Search.

Sequential Line Search is a generic human-in-the-loop optimization algorithm that optimizes for the user's preference, by repeatedly asking them to select their favorite on a slider.

The [SLSFramework] type holds the state of the algorithm, look there for the available methods.

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());

Dependencies

~1–2MB
~39K SLoC