https://github.com/jonboh/gkls-rs
A Rust implementation of the GKLS function generator. GKLS allows to generate parametrized optimization problems with known local and global minima.
https://github.com/jonboh/gkls-rs
math optimization
Last synced: about 1 year ago
JSON representation
A Rust implementation of the GKLS function generator. GKLS allows to generate parametrized optimization problems with known local and global minima.
- Host: GitHub
- URL: https://github.com/jonboh/gkls-rs
- Owner: jonboh
- Created: 2023-06-17T11:38:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-24T12:36:21.000Z (over 2 years ago)
- Last Synced: 2024-04-24T23:41:48.364Z (about 2 years ago)
- Topics: math, optimization
- Language: C
- Homepage:
- Size: 318 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gkls-rs
`gkls-rs` is a pure Rust implementation of the algorithm described in
[Software for Generation of Classes of Test Functions with Known Local and Global Minima for Global Optimization](https://arxiv.org/abs/1103.2695).
Although much of the code is mostly translated from the original C implementation, in this implementation
it is possible to define independent problems without the need to modify any global state. That particular
point made the usage of the original quite unwieldy when trying to run parallel code in benchmarks.
The original implementation is located at the [ACM Collected Algorithms repository](https://netlib.org/toms/) on entry number 829.
The folder `gkls` is a copy of those contents, it is used to test the Rust implementation.
With the feature `test_cbinding` the original C implementation and test suite is built.
The test-suite compares the output of the Rust and C implementations. The output must be equivalent.
Thus, the function numbers from the original paper and subsequent studies on each function are still valid.
Here is the function from the original paper reproduced with `gkls-rs`:

The figure is generated with the binary in `examples/plot_function`.
```bash
cargo run --example plot_function --features examples
```
See `examples/single_evaluation.rs` for a simple usage example:
```rust
// Generate a problem
let problem = Problem::new(9, Options::default(), 2, 10, -1.0, 1. / 3., 2. / 3.)
.expect("Problem has to be valid");
// Evaluate the proble with the appropiate function
let x = [0.23, 0.44];
let y = problem.d_func(&x);
let dy = problem.d_gradient(&x);
println!("f({x:?})={y}");
println!("f'({x:?})={dy:?}");
```
Run the example with:
```bash
cargo run --example single_evaluation --features examples
```
You should get something like:
```
f([0.23, 0.44])=0.8938503184432863
f'([0.23, 0.44])=Some([1.8828658375478264, 0.17383184854469846])
```