yes fuking shit
This commit is contained in:
+58
-1
@@ -13,7 +13,7 @@ from dataclasses import replace
|
||||
from random import Random
|
||||
|
||||
from mcm26b.config import ProblemConfig
|
||||
from mcm26b.particles import ChannelParticles, angular_gap
|
||||
from mcm26b.particles import ChannelParticles, angular_gap, as_sample_array
|
||||
from mcm26b.protocol.rules import DIRECTION, NEAR, NO_SIGNAL
|
||||
from mcm26b.planner.seven import seven_points
|
||||
|
||||
@@ -169,3 +169,60 @@ class QueryPrimitiveTests(unittest.TestCase):
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class VectorizedScoringParityTests(unittest.TestCase):
|
||||
"""numpy 快路径与纯 Python 路径必须逐位同语义(方案 §P0-4)。
|
||||
|
||||
评分只用于选点,不参与安全证明;但两条路径若给出不同排序,会导致
|
||||
同一动作日志在不同环境下不可复现,因此必须对齐。
|
||||
"""
|
||||
|
||||
def _fixture(self):
|
||||
config = ProblemConfig()
|
||||
particles = ChannelParticles(config)
|
||||
rng = Random(20260912)
|
||||
subsample = [(rng.uniform(-1800, 1800), rng.uniform(-1800, 1800))
|
||||
for _ in range(64)]
|
||||
representatives = subsample[::8]
|
||||
return particles, subsample, representatives
|
||||
|
||||
def test_expected_survival_matches(self):
|
||||
particles, subsample, representatives = self._fixture()
|
||||
for point in ((0.0, 0.0), (700.0, -300.0), (-1200.0, 900.0)):
|
||||
fast = particles.expected_survival(point, as_sample_array(subsample),
|
||||
as_sample_array(representatives))
|
||||
slow = particles.expected_survival(point, subsample, representatives)
|
||||
self.assertAlmostEqual(fast, slow, places=9)
|
||||
|
||||
def test_expected_posterior_radius_matches(self):
|
||||
particles, subsample, representatives = self._fixture()
|
||||
for point in ((0.0, 0.0), (700.0, -300.0), (-1200.0, 900.0)):
|
||||
fast = particles.expected_posterior_radius(
|
||||
point, as_sample_array(subsample),
|
||||
as_sample_array(representatives))
|
||||
slow = particles.expected_posterior_radius(
|
||||
point, subsample, representatives)
|
||||
self.assertAlmostEqual(fast, slow, places=9)
|
||||
|
||||
def test_fraction_within_and_branch_radius_match(self):
|
||||
particles, subsample, _ = self._fixture()
|
||||
array = as_sample_array(subsample)
|
||||
for radius in (100.0, 1000.0, 1500.0):
|
||||
self.assertAlmostEqual(
|
||||
particles.fraction_within(array, (10.0, 20.0), radius),
|
||||
particles.fraction_within(subsample, (10.0, 20.0), radius),
|
||||
places=12)
|
||||
self.assertAlmostEqual(particles._branch_radius(array),
|
||||
particles._branch_radius(subsample), places=9)
|
||||
|
||||
def test_empty_samples_are_safe(self):
|
||||
particles, _, _ = self._fixture()
|
||||
self.assertEqual(particles.expected_survival((0.0, 0.0), [], []), 0.0)
|
||||
self.assertEqual(
|
||||
particles.expected_posterior_radius(
|
||||
(0.0, 0.0), as_sample_array([]), as_sample_array([])), 0.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user