feat+test: select=ep_waste 白费比例惩罚(罚度按当前误差缩放);单测抓到我把净位移对时间轴求和写成了对轴求和(frac 恒 0)

This commit is contained in:
cbb
2026-10-20 22:24:49 +08:00
parent d632924446
commit 078f7cd451
3 changed files with 24 additions and 5 deletions
+15 -2
View File
@@ -795,7 +795,7 @@ class TravelPenaltySelectTest(unittest.TestCase):
return (self.act.expand(B, K, 16, 6).clone(), torch.zeros(B, device=feat.device),
torch.zeros(B, 13, device=feat.device))
def run1(self, len_w):
def run1(self, len_w, select='ep_len'):
class SafeKin:
def clamp_box(self, q):
return q
@@ -811,7 +811,7 @@ class TravelPenaltySelectTest(unittest.TestCase):
patch('ml.sim.closed_loop.goal_err',
side_effect=lambda kin, q, T, R: (torch.full((q.shape[0],), 10.0), torch.zeros(q.shape[0]))):
_, per = rollout(self.StubModel(acts), SafeKin(), tasks, 'cpu', K=2, safety=True, max_sec=0.06,
return_traj=True, use_sub=False, select='ep_len', replan='empty', commit_n=2,
return_traj=True, use_sub=False, select=select, replan='empty', commit_n=2,
safety_partial=1, len_w=len_w)
return per
@@ -821,6 +821,19 @@ class TravelPenaltySelectTest(unittest.TestCase):
p1 = self.run1(1.0) # 加惩罚:行程 10.8 vs 3.6 ⇒ 选匀速那条
self.assertAlmostEqual(p1['traj'][0, 1, 0].item(), 0.225 * 1.2, places=5)
def test_waste_penalty_also_separates_them(self):
"""换成"白费比例"(1 − 同轴净位移/累计行程)也必须能分开,且罚度按当前误差缩放:
这里 goal_err 恒为 10 ⇒ 抖动条 waste≈0.78、匀速条 0 ⇒ 差 7.8×len_w 的当量。"""
p0 = self.run1(0.0, select='ep_waste')
self.assertAlmostEqual(p0['traj'][0, 1, 0].item(), 0.9 * 1.2, places=5)
p1 = self.run1(1.0, select='ep_waste')
self.assertAlmostEqual(p1['traj'][0, 1, 0].item(), 0.225 * 1.2, places=5)
def test_zero_weight_ep_waste_is_the_old_endpoint_path(self):
p0 = self.run1(0.0, select='ep_waste')
p1 = self.run1(0.0, select='endpoint')
torch.testing.assert_close(p0['traj'], p1['traj'], rtol=0, atol=0)
def test_zero_weight_is_the_old_endpoint_path(self):
"""len_w=0 且 select='ep_len' 必须与 select='endpoint' 逐位相同(不许悄悄改默认行为)"""
class SafeKin: