#bfgs #differentiable #ndarray #optimization #convex

my-bfgs

A pure Rust implementation of the BFGS optimization algorithm

3 releases

0.1.2 Feb 1, 2023
0.1.1 Apr 26, 2022
0.1.0 Apr 26, 2022

#7 in #minimizing

Download history 15/week @ 2023-11-06 11/week @ 2023-11-13 15/week @ 2023-11-20 22/week @ 2023-11-27 9/week @ 2023-12-04 12/week @ 2023-12-11 8/week @ 2023-12-18 15/week @ 2023-12-25 4/week @ 2024-01-01 9/week @ 2024-01-08 10/week @ 2024-01-15 5/week @ 2024-01-22 10/week @ 2024-01-29 12/week @ 2024-02-05 115/week @ 2024-02-12 66/week @ 2024-02-19

203 downloads per month
Used in 2 crates (via consprob-trained)

MIT/Apache

9KB
137 lines

bfgs

This package contains an implementation of BFGS, an algorithm for minimizing convex twice-differentiable functions.

BFGS is explained at a high level in the blog post introducing this package.

In this example, we minimize a 2d function:

extern crate bfgs;
extern crate ndarray;

use ndarray::{Array, Array1};

fn main() {
    let x0 = Array::from_vec(vec![8.888, 1.234]);  // Chosen arbitrarily
    let f = |x: &Array1<f64>| x.dot(x);
    let g = |x: &Array1<f64>| 2.0 * x;
    let x_min = bfgs::bfgs(x0, f, g);
    assert_eq!(x_min, Ok(Array::from_vec(vec![0.0, 0.0])));
}

This project uses cargo-make for builds; to build, run cargo make all.

License: MIT/Apache-2.0


lib.rs:

This package contains an implementation of BFGS, an algorithm for minimizing convex twice-differentiable functions.

BFGS is explained at a high level in the blog post introducing this package.

In this example, we minimize a 2d function:

extern crate my_bfgs as bfgs;
extern crate ndarray;

use ndarray::{Array, Array1};

fn main() {
    let x0 = Array::from_vec(vec![8.888, 1.234]);  // Chosen arbitrarily
    let f = |x: &Array1<f64>| x.dot(x);
    let g = |x: &Array1<f64>| 2.0 * x;
    let x_min = bfgs::bfgs(x0, f, g);
    assert_eq!(x_min, Ok(Array::from_vec(vec![0.0, 0.0])));
}

This project uses cargo-make for builds; to build, run cargo make all.

Dependencies

~1.5MB
~25K SLoC