Bundle Classic AI algorithms: graph search, adversarial game search, optimization and tabular reinforcement learning (-lib ai)
HillClimbing
Random-restart stochastic hill climbing over a numeric state vector: each step perturbs one random coordinate and keeps strict improvements; when no improvement is found for `patience` consecutive steps the search restarts from a random point within +/- restart_range of the start. Seeded for reproducible runs.
Example
hc := HillClimbing->New(0.5, 50, 5.0, 7);
best := hc->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(step_size:Float, patience:Int, restart_range:Float, seed:Int)Parameters
| Name | Type | Description |
|---|---|---|
| step_size | Float | maximum coordinate perturbation |
| patience | Int | steps without improvement before a restart |
| restart_range | Float | restart sampling half-range around the start state |
| 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 | total climbing steps across restarts |
Return
| Type | Description |
|---|---|
| Float | best state found, or Nil on invalid input |