gsl_bfgs
Rust implementation of the BFGS algorithm built on the GNU Scientific Library(GSL)
The gsl_bfgs crate provides a pure Rust implementation of the BFGS (Broyden-Fletcher-Goldfarb-Shanno) algorithm, which is a popular method for numerical optimization, especially in unconstrained optimization problems. This implementation is derived from the GNU Scientific Library (GSL), which is written in C.
how to use?
The main entry point for using the BFGS optimization in this crate is the function gsl_bfgs::optimize. To use it, you need to implement the Callback trait for your specific target function. The Callback trait defines three essential functions that will be used by the optimizer:
eval: Evaluates the target function at a given point.grad: Computes the gradient (partial derivatives) of the target function at a given point.ndim: Returns the number of dimensions for the input vector.
Below is the example code for how to use the gsl_bfgs::optimize function:
use gsl_bfgs;
/// Struct representing the Rosenbrock function:
/// f(x, y) = (1 - x)^2 + 100 * (y - x^2)^2
;
let func = Rosenbrock;
let mut p: = vec!; // Initial guess for the minimum
let itermax = 100; // Maximum number of iterations
let toll = 1e-7; // Tolerance for convergence
/// Perform the BFGS optimization to find the local minimum.
/// The optimized result is stored in `p`.
optimize;
contact
If you encounter a bug or have suggestions to improve the code, feel free to submit a pull request.
- email: dkkim1005@gmail.com