Skip to content

Commit 989af35

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f7b8c07 commit 989af35

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

maths/entropy.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def shannon_entropy(probabilities: list[float]) -> float:
4545
raise ValueError("Probabilities cannot be negative.")
4646

4747
# Due to floating point precision, we check for closeness to 1.0
48-
if not math.isclose(sum(probabilities), 1.0, rel_tol=1e-9) and sum(probabilities) > 0:
48+
if (
49+
not math.isclose(sum(probabilities), 1.0, rel_tol=1e-9)
50+
and sum(probabilities) > 0
51+
):
4952
# Normalize if not summed to 1 but has values
5053
probabilities = [p / sum(probabilities) for p in probabilities]
5154

@@ -111,4 +114,4 @@ def analyze_text_entropy(text: str) -> dict[str, float]:
111114
entropy_stats = analyze_text_entropy(sample_text)
112115
print(f"Text: '{sample_text[:30]}...'")
113116
for level, value in entropy_stats.items():
114-
print(f"{level:>20}: {value:.4f} bits")
117+
print(f"{level:>20}: {value:.4f} bits")

0 commit comments

Comments
 (0)