Step Size Module¶
StepSizeEstimator ¶
Estimates the optimal percentage step size for basin-hopping sampling.
The optimal step size is defined as the one that produces an escape rate
closest to a target X (default 0.5), meaning ~ X * 100% of perturbations lead to
a different local optimum.
The search uses a decimal refinement approach, progressively narrowing the step size to the configured precision.
Computational cost
_compute_escape_rate is called once per tested step size. Each call runs
n_samples baseline minimizations and n_samples * n_perturbations
perturbed minimizations (defaults: 100 + 3000 minimizations per step size).
Since multiple step sizes are evaluated during refinement
(search_precision dependent), total minimizations can become large for
expensive objective functions. For expensive objectives, start by reducing
n_samples and/or n_perturbations, then increase them once a reasonable
step-size range is identified.
Example
import numpy as np estimator = StepSizeEstimator() result = estimator.estimate(problem, [(-5, 5)] * 2) print(f"Step size: {result.step_size}, escape rate: {result.escape_rate:.3f}")
Source code in src/lonkit/continuous/step_size.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
estimate ¶
Estimate the optimal step size for basin-hopping sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[ndarray], float]
|
Objective function to minimize (f: R^n -> R). |
required |
domain
|
list[tuple[float, float]]
|
List of (lower, upper) bounds per dimension. |
required |
Returns:
| Type | Description |
|---|---|
StepSizeResult
|
StepSizeResult with the estimated step size, achieved escape rate, and error. |
Source code in src/lonkit/continuous/step_size.py
StepSizeEstimatorConfig
dataclass
¶
Configuration for step size estimation.
Attributes:
| Name | Type | Description |
|---|---|---|
n_samples |
int
|
Number of random initial points to evaluate. Default: |
n_perturbations |
int
|
Number of perturbations per sample point. Default: |
target_escape_rate |
float
|
Target escape rate to find (0.5 = 50% of perturbations escape). Default: |
search_precision |
int
|
Decimal digits of precision for step size search.
The algorithm refines by dividing the increment by 10 each iteration,
so |
coordinate_precision |
int | None
|
Decimal precision for coordinate rounding and hashing.
Solutions rounded to this precision are considered identical.
Use |
minimizer_method |
str | Callable | None
|
Minimization method passed to |
minimizer_options |
dict | None
|
Solver-specific options passed as the |
bounded |
bool
|
Whether to enforce domain bounds during perturbation. Default: |
seed |
int | None
|
Random seed for reproducibility. Default: |
Source code in src/lonkit/continuous/step_size.py
StepSizeResult
dataclass
¶
Result of step size estimation.
Attributes:
| Name | Type | Description |
|---|---|---|
step_size |
float
|
Estimated optimal step size (percentage of domain range). |
escape_rate |
float
|
Achieved escape rate at this step size. |
error |
float
|
Absolute difference between achieved and target escape rate. |