exp+test: #30 机制落库——select=pre 的打分步长做成参数 pre_h(h=4/8 两臂排队)
pre_h=0 保持"0=commit_n"的轮次46 口径逐位不变;pre_h>0 按绝对步数取 fut 的该步终点误差。 新增两条可手算的期望值:夹具交叉点 h=4 选候选0(0.343 vs 0.20)、h=12 选候选1(0.114 vs 0.60)、 h=16 必须与 endpoint 同选;再加一条不变式 pre_h=0 与 pre_h=commit_n 的轨迹逐位相同。 51 项测试绿;ast 枚举确认新局部名没有遮蔽任何 rollout 形参(上一轮 nmax 那类事故的自查)。 判读规则已预注册,写在 ml/runs/_r48_horizon.sh 顶部。
This commit is contained in:
+16
-2
@@ -987,7 +987,7 @@ class PreHorizonTest(unittest.TestCase):
|
||||
def gaps(self, q, cap):
|
||||
return {'gm': torch.ones(q.shape[0], 49)}
|
||||
|
||||
def run1(self, select, commit_n=2):
|
||||
def run1(self, select, commit_n=2, pre_h=0):
|
||||
# 候选0:前 2 步各 +0.2(前缀 0.4),随后 14 步 −0.4/14 ⇒ 地平线末端回到 0
|
||||
# 候选1:16 步各 +0.05 ⇒ 前缀只有 0.1,但地平线末端 0.8
|
||||
c0 = [0.2, 0.2] + [-(0.4 / 14.0)] * 14
|
||||
@@ -1000,7 +1000,7 @@ class PreHorizonTest(unittest.TestCase):
|
||||
patch('ml.sim.closed_loop.goal_err', side_effect=err):
|
||||
_, per = rollout(self.StubModel(acts), self.NearKin(), [{'q0': [0] * 6, 'T': [1, 0, 0]}], 'cpu',
|
||||
K=2, safety=False, max_sec=0.04, return_traj=True, use_sub=False,
|
||||
select=select, replan='empty', commit_n=commit_n)
|
||||
select=select, replan='empty', commit_n=commit_n, pre_h=pre_h)
|
||||
return per
|
||||
|
||||
def test_pre_and_endpoint_pick_opposite(self):
|
||||
@@ -1010,6 +1010,20 @@ class PreHorizonTest(unittest.TestCase):
|
||||
self.assertAlmostEqual(float(p_pre['traj'][0, 1, 0]), 0.2 * 1.2, places=5) # 前缀 0.4 ⇒ 选候选0
|
||||
self.assertNotAlmostEqual(float(p_end['traj'][0, 1, 0]), float(p_pre['traj'][0, 1, 0]), places=3)
|
||||
|
||||
def test_pre_h_moves_the_pick_back_at_the_crossover(self):
|
||||
"""#30 的曲线靠这个参数才量得动。期望值按夹具手算(单位=act 增量之和,STEP=1.2):
|
||||
候选0 累计 = 0.4 − max(0,h−2)·0.4/14,候选1 累计 = 0.05h ⇒
|
||||
h=4:0.3429 vs 0.20 ⇒ 选 0;h=12:0.1143 vs 0.60 ⇒ 选 1;h=16:0 vs 0.8 ⇒ 选 1。"""
|
||||
for h, want in ((4, 0.2 * 1.2), (12, 0.05 * 1.2), (16, 0.05 * 1.2)):
|
||||
p = self.run1('pre', pre_h=h)
|
||||
self.assertAlmostEqual(float(p['traj'][0, 1, 0]), want, places=5, msg='h=%d' % h)
|
||||
|
||||
def test_pre_h_zero_means_commit_n(self):
|
||||
"""默认(pre_h=0)必须与显式 pre_h=commit_n 逐位相同,否则"0=前缀"这句是空话。"""
|
||||
a = self.run1('pre', commit_n=2, pre_h=0)
|
||||
b = self.run1('pre', commit_n=2, pre_h=2)
|
||||
torch.testing.assert_close(a['traj'], b['traj'], rtol=0, atol=0)
|
||||
|
||||
def test_pre_equals_endpoint_when_commit_is_the_whole_horizon(self):
|
||||
"""不变式:commit_n=16 = 整条地平线 ⇒ pre 的索引落到末端,必须与 endpoint 选同一条。"""
|
||||
p = self.run1('pre', commit_n=16)
|
||||
|
||||
Reference in New Issue
Block a user