A pure Rust implementation of the classic Moré, Garbow, and Hillstrom (MGH) collection of test functions for unconstrained optimization algorithms.
This crate provides a standard suite of benchmark problems, essential for developers and researchers who need to test, validate, and compare the performance of optimization algorithms. The implementations are based on the original Fortran package and the definitions in the seminal paper:
Moré, J. J., Garbow, B. S., & Hillstrom, K. E. (1981). Testing Unconstrained Optimization Software. ACM Transactions on Mathematical Software (TOMS), 7(1), 17–41. https://dl.acm.org/doi/pdf/10.1145/355934.355936
The library is organized into three main structs:
-
MGH: Evaluates the objective functions. Most functions are formulated as a sum of squares,$F(x) = \sum_{i=1}^{m} f_i(x)^2$ . All methods inMGHreturn a scalarf64. -
MGHInit: Provides the standard initial starting points ($x_0$ ) for each test function, as specified in the MGH paper. -
MGHMin: Provides known solution vectors ($x^*$ ) for functions where the global minimum is documented.
Add the crate to your Cargo.toml file:
[dependencies]
mgh = "0.1.0"Functions with fixed
use mgh::{MGH, MGHInit, MGHMin};
// 1. Get the standard starting point (n=3)
let x0 = MGHInit::gaussian();
// 2. Evaluate the objective function
let value = MGH::gaussian(&x0);
println!("Value at x0: {}", value);
// 3. (Optional) Verify at the known minimum
let x_min = MGHMin::gaussian();
let min_value = MGH::gaussian(&x_min);
assert!(min_value < 1e-10);Functions where
use mgh::{MGH, MGHInit, MGHMin};
let n = 10; // Must be even for Extended Rosenbrock
let x0 = MGHInit::extended_rosenbrock(n);
let value = MGH::extended_rosenbrock(&x0);
let x_min = MGHMin::extended_rosenbrock(n);
let min_value = MGH::extended_rosenbrock(&x_min);
assert_eq!(min_value, 0.0);Functions requiring an explicit MGH::aux(m).
use mgh::{MGH, MGHInit};
let m = 20; // Number of residuals
let x0 = MGHInit::biggs_exp6();
// Use .aux(m) to specify the number of residuals
let value = MGH::aux(m).biggs_exp6(&x0);The tables below list all available test functions and their properties.
These use simple static methods like MGH::gaussian(&x).
| Function | Initial Vector | Solution Vector | ||
|---|---|---|---|---|
bard |
3 | 15 | ✅ | ✅ |
beale |
2 | 3 | ✅ | ✅ |
brown_badly_scaled |
2 | 3 | ✅ | ✅ |
freudenstein_and_roth |
2 | 2 | ✅ | ✅ |
gaussian |
3 | 15 | ✅ | ✅ |
hellical_valley |
3 | 3 | ✅ | ✅ |
kowalik_and_osborne |
4 | 11 | ✅ | ❌ |
meyer |
3 | 16 | ✅ | ❌ |
osborne_1 |
5 | 33 | ✅ | ❌ |
osborne_2 |
11 | 65 | ✅ | ❌ |
powell_badly_scaled |
2 | 2 | ✅ | ✅ |
powell_singular |
4 | 4 | ✅ | ✅ |
rosenbrock |
2 | 2 | ✅ | ✅ |
wood |
4 | 6 | ✅ | ✅ |
These use static methods but MGHInit and MGHMin require an n argument.
| Function | Initial Vector | Solution Vector | |
|---|---|---|---|
brown_almost_linear |
✅ | ✅ | |
broyden_banded |
✅ | ❌ | |
broyden_tridiagonal |
✅ | ❌ | |
discrete_boundary_value |
✅ | ❌ | |
discrete_integral_equation |
✅ | ❌ | |
extended_powell_singular |
|
✅ | ✅ |
extended_rosenbrock |
|
✅ | ✅ |
penalty1 |
✅ | ❌ | |
penalty2 |
✅ | ❌ | |
trigonometric |
✅ | ❌ | |
variably_dimensioned |
✅ | ✅ | |
watson |
31 ( |
✅ | ❌ |
These require MGH::aux(m) to specify the number of residuals.
| Function | Dimension | Initial Vector | Solution Vector |
|---|---|---|---|
biggs_exp6 |
✅ | ✅ | |
box_3d |
✅ | ✅ | |
brown_and_dennis |
✅ | ✅ | |
gulf_research_and_development |
✅ | ✅ | |
jennrich_and_sampson |
✅ | ✅ | |
chebyquad |
Variable |
✅ | ❌ |
linear_full_rank |
Variable |
✅ | ✅ |
linear_rank_1 |
Variable |
✅ | ❌ |
linear_rank_1_zero |
Variable |
✅ | ❌ |
- MIT license (LICENSE-MIT)
Contributions are welcome! Feel free to open an issue or submit a pull request.