114514
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
"""兼容入口:本地域随机化参数包装。
|
||||
|
||||
当前真实随机化在 mcm26b.hrl.curriculum.make_scene 内完成;这里只暴露
|
||||
ProblemConfig 的显式替换助手,便于 Optuna/消融在实验配置中记录随机化范围。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
from random import Random
|
||||
|
||||
from mcm26b.config import ProblemConfig
|
||||
|
||||
|
||||
def randomize_problem_config(base: ProblemConfig, *, seed: int,
|
||||
bearing_error_half_deg: float | None = None,
|
||||
r_eff_range: tuple[float, float] | None = None
|
||||
) -> ProblemConfig:
|
||||
"""返回带域随机化标量的新配置;不修改全局默认配置。"""
|
||||
rng = Random(seed)
|
||||
field = base.field
|
||||
if bearing_error_half_deg is None:
|
||||
bearing_error_half_deg = field.bearing_error_half_deg
|
||||
if r_eff_range is not None:
|
||||
lo, hi = r_eff_range
|
||||
if not (0 <= lo <= hi):
|
||||
raise ValueError("r_eff_range 必须为递增非负区间")
|
||||
return dataclasses.replace(base, field=dataclasses.replace(
|
||||
field, bearing_error_half_deg=float(bearing_error_half_deg)))
|
||||
|
||||
|
||||
__all__ = ["randomize_problem_config"]
|
||||
Reference in New Issue
Block a user