Crates.io | rust_sls |
lib.rs | rust_sls |
version | 0.1.1 |
source | src |
created_at | 2019-06-13 03:22:35.797073 |
updated_at | 2020-10-26 13:19:47.872719 |
description | Sequential Line Search for Design Optimization |
homepage | |
repository | https://github.com/mad-s/rust_sls |
max_upload_size | |
id | 140749 |
size | 2,943,141 |
Rust bindings for sequential-line-search.
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());
This project is available under the MIT License