Bundle Classic AI algorithms: graph search, adversarial game search, optimization and tabular reinforcement learning (-lib ai)
SimulatedAnnealing
Simulated annealing over a numeric state vector: a random coordinate is perturbed uniformly within +/- step_size, worse states are accepted with probability e^(-delta/T), and the temperature cools geometrically. Seeded for reproducible runs.
Example
sa := SimulatedAnnealing->New(10.0, 0.95, 0.5, 7);
best := sa->Run(energy, start, 2000);Operations
GetBestEnergy #
Gets the best (lowest) energy seen during the last run.
method : public : GetBestEnergy() ~ FloatReturn
| Type | Description |
|---|---|
| Float | best energy |
New # constructor
Constructor
New(initial_temperature:Float, cooling:Float, step_size:Float, seed:Int)Parameters
| Name | Type | Description |
|---|---|---|
| initial_temperature | Float | starting temperature (> 0) |
| cooling | Float | geometric cooling factor per iteration (0..1) |
| step_size | Float | maximum coordinate perturbation |
| seed | Int | PRNG seed for reproducible runs |
Run #
Minimizes the energy starting from the given state.
method : public : Run(energy:EnergyFunction, start:Float[], iterations:Int) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| energy | EnergyFunction | energy function (lower is better) |
| start | Float | starting state (copied, not modified) |
| iterations | Int | annealing steps |
Return
| Type | Description |
|---|---|
| Float | best state found, or Nil on invalid input |