Skip to main content

Crate math_audio_test_functions

Crate math_audio_test_functions 

Source
Expand description

§Optimization Test Functions Library

A comprehensive collection of 56+ test functions for optimization algorithm benchmarking and validation, organized into logical modules for easy navigation and maintenance.

§Function Categories

Plots per function

§Unimodal Functions (Single Global Optimum)

Perfect for testing convergence speed and precision:

  • sphere, rosenbrock, powell, dixons_price
  • zakharov, booth, matyas, sum_squares
  • elliptic, cigar, tablet, discus (ill-conditioned)
  • ridge, sharp_ridge, brown, exponential

§Multimodal Functions (Multiple Local Minima)

Test global search and exploration capabilities:

  • ackley, rastrigin, griewank, schwefel
  • hartman_3d, hartman_4d, hartman_6d
  • michalewicz, alpine_n1, alpine_n2
  • branin, goldstein_price, six_hump_camel
  • eggholder, holder_table, cross_in_tray

§Constrained Functions

For constrained optimization algorithms:

  • keanes_bump_objective with constraints
  • rosenbrock_disk_constraint
  • binh_korn_* with multiple constraints
  • mishras_bird_* functions

§Composite & Modern Functions

Hybrid and recent competition functions:

  • expanded_griewank_rosenbrock
  • xin_she_yang_n1, xin_she_yang_n2, etc.
  • happycat, katsuura, vincent
  • gramacy_lee_2012, forrester_2008

§Usage Examples

§Basic Function Evaluation

use ndarray::Array1;
use math_audio_test_functions::*;

// Evaluate sphere function
let x = Array1::from_vec(vec![1.0, 2.0]);
let result = sphere(&x); // Returns 5.0 (1² + 2²)

// Evaluate Rosenbrock function
let x = Array1::from_vec(vec![1.0, 1.0]);
let result = rosenbrock(&x); // Returns 0.0 (global minimum)

§Function Metadata and Bounds

use math_audio_test_functions::{get_function_metadata, get_function_bounds, get_function_bounds_2d};
// Get all function metadata
let metadata = get_function_metadata();
println!("Available functions: {}", metadata.len());

// Get bounds for a specific function
let bounds = get_function_bounds("ackley").unwrap();
println!("Ackley bounds: {:?}", bounds);

// Get 2D bounds array (for compatibility)
let bounds_2d = get_function_bounds_2d("sphere", (-5.0, 5.0));

§Working with Different Categories

use ndarray::Array1;
use math_audio_test_functions::*;

let x = Array1::from_vec(vec![1.0, 1.0]);
// Unimodal functions (good for convergence testing)
let result1 = elliptic(&x);    // Ill-conditioned
let result2 = rosenbrock(&x);  // Valley-shaped

// Multimodal functions (good for global search testing)
let result3 = ackley(&x);      // Highly multimodal
let result4 = rastrigin(&x);   // Many local minima

// Modern benchmarks
let result5 = happycat(&x);    // Recent CEC function
let result6 = katsuura(&x);    // Fractal-like landscape

§Function Properties

§Difficulty Levels

  • Easy: sphere, booth, matyas - Good for initial testing
  • Medium: rosenbrock, ackley, griewank - Standard benchmarks
  • Hard: schwefel, eggholder, katsuura - Challenging landscapes
  • Extreme: holder_table, cross_in_tray - Very difficult optimization

§Dimensionality Support

  • 1D: gramacy_lee_2012, forrester_2008
  • 2D Fixed: branin, goldstein_price, six_hump_camel
  • N-Dimensional: sphere, rosenbrock, ackley, rastrigin
  • High-D Specific: elliptic, bent_cigar, katsuura

§Special Properties

  • Ill-conditioned: elliptic, cigar, tablet, discus
  • Separable: sphere, sum_squares, alpine_n1
  • Non-separable: rosenbrock, ackley, griewank
  • Discontinuous: step, de_jong_step2
  • Constrained: keanes_bump_*, binh_korn_*

§Aliases And Near-Duplicates

Some names are kept for compatibility with common benchmark catalogs rather than to imply distinct landscapes:

  • step and de_jong_step2 use the same step formula.
  • tablet and discus are the same ill-conditioned quadratic form.
  • quadratic is equivalent to sphere.
  • rosenbrock_objective is the 2D Rosenbrock objective used with constrained Rosenbrock examples.
  • levi13 / levy_n13 and zakharov2 / zakharov are catalog aliases.

§Benchmarking Guide

§Algorithm Testing Workflow

  1. Start Simple: Test on sphere and rosenbrock
  2. Add Multimodality: Try ackley and rastrigin
  3. Test Scalability: Use N-dimensional functions
  4. Challenge Mode: schwefel, eggholder, katsuura
  5. Constraints: keanes_bump_* for constrained algorithms

§Performance Metrics

  • Convergence Speed: Unimodal functions
  • Global Search: Multimodal functions
  • Precision: Functions with known exact minima
  • Robustness: Ill-conditioned and noisy functions
  • Scalability: High-dimensional variants

§Build & Test

# Build the library
cargo build --release

# Run all tests
cargo test --release

# Test specific examples
cargo run --example test_new_sfu_functions
cargo run --example test_additional_functions

# Check code quality
cargo check
cargo clippy
cargo fmt

§Architecture

The library is organized into modular components:

src/
├── lib.rs                    # Main library with utilities and metadata
└── functions/
    ├── mod.rs               # Module exports and organization
    └── *.rs                 # 1 file per function

§References

Re-exports§

pub use functions::*;

Modules§

functions
Test function implementations organized by category

Structs§

FunctionMetadata
Metadata for a test function including bounds, constraints, and other properties

Functions§

create_bounds
Create bounds matrix for optimization (2 x n matrix) bounds[[0, i]] = lower bound, bounds[[1, i]] = upper bound
get_function_bounds
Helper function to get bounds for a specific function from metadata Returns None if function is not found in metadata
get_function_bounds_2d
Helper function to get bounds as a 2D array for optimization (compatible with existing tests) Returns default bounds if function is not found
get_function_bounds_vec
Helper function to get bounds as a Vec for optimization (compatible with recorded tests) Returns default bounds if function is not found
get_function_metadata
Get metadata for all available test functions (explicit definitions)