geno_lewm.planning.cem¶
cem
¶
Pure-Python CEM solver core for RFC-0008 planning.
The predictor-backed planner and CLI still need runtime integration and
benchmark evidence. This module provides the deterministic search loop
over existing RelEdit samplers so downstream integrations can bind a
real rollout/evaluation function without importing optional ML runtimes.
PlanningConfig
dataclass
¶
PlanningConfig(horizon: int = 5, n_iterations: int = 5, n_samples: int = 1024, n_elite: int = 64, cost_weight: float = 0.0, stopping_eps: float = 0.05, patience: int = 2, seed: int | None = None, smoothing: float = _DEFAULT_SMOOTHING)
CEM search configuration for a fixed-horizon edit sequence.
CandidateEvaluation
dataclass
¶
Evaluation returned by a caller-provided rollout/scoring function.
CEMIterationLog
dataclass
¶
CEMIterationLog(iteration: int, best_distance: float, best_cost: float, best_objective: float, elite_mean_distance: float, elite_mean_objective: float, n_candidates: int)
Summary statistics for one CEM iteration.
PlanningResult
dataclass
¶
PlanningResult(best_edits: tuple[RelEdit, ...], best_distance: float, best_cost: float, best_objective: float, best_predicted_state: Any | None, n_evaluations: int, iterations: tuple[CEMIterationLog, ...], elapsed_seconds: float, stopped_reason: str)
Best edit sequence and reproducibility trace from a CEM run.
n_predictor_calls
property
¶
Compatibility alias for the final predictor-backed API shape.
plan
¶
plan(evaluate: Callable[[Sequence[RelEdit]], float | CandidateEvaluation], sampler: ActionSampler, *, config: PlanningConfig | None = None, cost_fn: Callable[[Sequence[RelEdit]], float] | None = None) -> PlanningResult
Run CEM over valid RelEdit sequences from sampler.
evaluate is the integration boundary: it receives a candidate edit
sequence and returns either a non-negative distance or a
:class:CandidateEvaluation with optional predicted-state payload.
The objective minimized by CEM is distance + cost_weight * cost.
Source code in geno_lewm/planning/cem.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
l2_distance
¶
Return Euclidean distance between two finite numeric vectors.
Source code in geno_lewm/planning/cem.py
cosine_distance
¶
Return 1 - cosine_similarity for two non-zero vectors.
Source code in geno_lewm/planning/cem.py
region_distance
¶
region_distance(predicted: Iterable[float], target: Iterable[float], indices: Iterable[int]) -> float
Return L2 distance restricted to explicit vector indices.
Source code in geno_lewm/planning/cem.py
projection_distance
¶
projection_distance(predicted: Iterable[float], target: Iterable[float], projection: Iterable[Iterable[float]]) -> float
Return L2 distance after applying a row-major linear projection.