37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from guardrail_space.belief import BeliefSketch
|
|
|
|
|
|
def test_belief_pov_and_entropy_deterministic():
|
|
# deterministic seed so CI results are reproducible
|
|
sketch = BeliefSketch("obstacle_dist", num_particles=128, prior_mean=0.0, prior_std=1.0, seed=42)
|
|
|
|
# an observation far above the prior should push mass upward
|
|
sketch.update(observation=5.0, obs_std=0.5)
|
|
|
|
pov = sketch.pov(threshold=3.0, operator=">")
|
|
ent = sketch.entropy()
|
|
|
|
# After a strong observation at 5.0 most particles should be >3.0
|
|
assert pov > 0.8
|
|
|
|
# entropy should be a finite positive number
|
|
assert isinstance(ent, float)
|
|
assert ent > 0.0
|
|
|
|
|
|
def test_serialize_small_and_deterministic():
|
|
s1 = BeliefSketch("battery", num_particles=32, prior_mean=10.0, prior_std=2.0, seed=7)
|
|
s2 = BeliefSketch("battery", num_particles=32, prior_mean=10.0, prior_std=2.0, seed=7)
|
|
|
|
s1.update(9.5, obs_std=0.5)
|
|
s2.update(9.5, obs_std=0.5)
|
|
|
|
b1 = s1.serialize()
|
|
b2 = s2.serialize()
|
|
|
|
# deterministic with same seed and ops
|
|
assert b1 == b2
|
|
|
|
# compact
|
|
assert len(b1) <= 40
|