2 releases
0.1.1 | Oct 26, 2020 |
---|---|
0.1.0 | Jun 13, 2019 |
#639 in Science
2MB
38K
SLoC
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–2.1MB
~40K SLoC