File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments