#optimization #annealing #simulated #global #interface #schedule #status

simulated_annealing

An interface for global function optimization using simulated annealing

4 releases

0.2.1 Apr 13, 2023
0.2.0 Sep 17, 2022
0.1.1 Sep 13, 2022
0.1.0 Sep 13, 2022

#1358 in Math

Custom license

21KB
276 lines

Description

This crate provides an implementation of the simulated annealing algorithm for approximating the global minimum of a given function.

Read the documentation for more information.

To build the documentation with KaTeX support, run:

cargo doc
RUSTDOCFLAGS="--html-in-header assets/katex-header.html" cargo doc --no-deps --open

Git mirrors:


lib.rs:

This crate provides an implementation of the simulated annealing algorithm for approximating the global minimum of a given function.

Choose the temperatures and the annealing schedule wisely: this is your way of controlling the quality of the search and how long you will have to wait. Note that the minimum temperature must be reachable.

References:

Example:

use anyhow::{Context, Result};
use rand_xoshiro::rand_core::SeedableRng;
use simulated_annealing::{Bounds, NeighbourMethod, Point, Schedule, Status, APF, SA};

// Define the objective function
fn f(p: &Point<f64, 1>) -> Result<f64> {
    let x = p[0];
    Ok(x.ln() * (x.sin() + x.cos()))
}
// Get the minimum (and the corresponding point)
let (m, p) = SA {
    // Objective function
    f,
    // Initial point
    p_0: &[2.],
    // Initial temperature
    t_0: 100_000.0,
    // Minimum temperature
    t_min: 1.0,
    // Bounds of the parameter space
    bounds: &[1.0..27.8],
    // Acceptance probability function
    apf: &APF::Metropolis,
    // Method of getting a random neighbour
    neighbour: &NeighbourMethod::Normal { sd: 5. },
    // Annealing schedule
    schedule: &Schedule::Fast,
    // Status function
    status: &mut Status::Periodic { nk: 1000 },
    // Random number generator
    rng: &mut rand_xoshiro::Xoshiro256PlusPlus::seed_from_u64(1),
}
.findmin().with_context(|| "Couldn't find the global minimum")?;

Dependencies

~2MB
~39K SLoC