Copyright | (c) Matthew Peddie 2015 |
---|---|
License | GPL |
Maintainer | Alberto Ruiz |
Stability | provisional |
Safe Haskell | None |
Language | Haskell98 |
Simulated annealing routines.
https://www.gnu.org/software/gsl/manual/html_node/Simulated-Annealing.html#Simulated-Annealing
Here is a translation of the simple example given in the GSL manual:
import Numeric.GSL.SimulatedAnnealing import Numeric.LinearAlgebra.HMatrix main = print $ simanSolve 0 1 exampleParams 15.5 exampleE exampleM exampleS (Just show) exampleParams = SimulatedAnnealingParams 200 1000 1.0 1.0 0.008 1.003 2.0e-6 exampleE x = exp (-(x - 1)**2) * sin (8 * x) exampleM x y = abs $ x - y exampleS rands stepSize current = (rands ! 0) * 2 * stepSize - stepSize + current
The manual states:
The first example, in one dimensional Cartesian space, sets up an energy function which is a damped sine wave; this has many local minima, but only one global minimum, somewhere between 1.0 and 1.5. The initial guess given is 15.5, which is several local minima away from the global minimum.
This global minimum is around 1.36.
- simanSolve :: Int -> Int -> SimulatedAnnealingParams -> a -> (a -> Double) -> (a -> a -> Double) -> (Vector Double -> Double -> a -> a) -> Maybe (a -> String) -> a
- data SimulatedAnnealingParams = SimulatedAnnealingParams {}
Searching for minima
:: Int | Seed for the random number generator |
-> Int |
|
-> SimulatedAnnealingParams | Parameters to configure the solver |
-> a | Initial configuration |
-> (a -> Double) | Energy functional |
-> (a -> a -> Double) | Metric definition |
-> (Vector Double -> Double -> a -> a) | Stepping function |
-> Maybe (a -> String) | Optional printing function |
-> a | Best configuration the solver has found |
Calling
simanSolve seed nrand params x0 e m step print
performs a simulated annealing search through a given space. So
that any configuration type may be used, the space is specified by
providing the functions e
(the energy functional) and m
(the
metric definition). x0
is the initial configuration of the
system. The simulated annealing steps are generated using the
user-provided function step
, which should randomly construct a
new system configuration.
If Nothing
is passed instead of a printing function, no
incremental output will be generated. Otherwise, the GSL-formatted
output, including the configuration description the user function
generates, will be printed to stdout.
Each time the step function is called, it is supplied with a random
vector containing nrand
Double
values, uniformly distributed in
[0, 1)
. It should use these values to generate its new
configuration.
Configuring the annealing process
data SimulatedAnnealingParams Source
SimulatedAnnealingParams
is a translation of the
gsl_siman_params_t
structure documented in
the GSL manual,
which controls the simulated annealing algorithm.
The annealing process is parameterized by the Boltzmann distribution and the cooling schedule. For more details, see the relevant section of the manual.
SimulatedAnnealingParams | |
|