24 lines
874 B
Python
24 lines
874 B
Python
from __future__ import annotations
|
|
|
|
import math
|
|
|
|
from synaptopus.analysis import analyze_sequence, first_order_conditional_entropy, shannon_entropy
|
|
|
|
|
|
def test_shannon_entropy_is_zero_for_constant_sequence() -> None:
|
|
assert shannon_entropy((1, 1, 1, 1)) == 0.0
|
|
|
|
|
|
def test_first_order_conditional_entropy_is_zero_for_deterministic_transitions() -> None:
|
|
assert first_order_conditional_entropy((0, 1, 0, 1, 0, 1)) == 0.0
|
|
|
|
|
|
def test_analyze_sequence_reports_expected_bounds() -> None:
|
|
analysis = analyze_sequence((0, 1, 0, 1), alphabet_size=2)
|
|
assert analysis.item_count == 4
|
|
assert math.isclose(analysis.unigram_entropy_bits, 1.0)
|
|
assert math.isclose(analysis.conditional_entropy_bits, 0.0)
|
|
assert math.isclose(analysis.normalized_entropy, 1.0)
|
|
assert math.isclose(analysis.predictability, 1.0)
|
|
assert math.isclose(analysis.redundancy, 0.0)
|