MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / shannon_entropy

Function shannon_entropy

codeclash/analysis/viz/cdf_command_diversity.py:51–79  ·  view source on GitHub ↗

Calculate Shannon entropy for a list of commands. Shannon entropy measures the "surprise" or information content in the distribution. - Higher entropy = more uniform distribution across command types (more diverse) - Lower entropy = some commands are much more frequent (more focuse

(command_list)

Source from the content-addressed store, hash-verified

49
50
51def shannon_entropy(command_list):
52 """
53 Calculate Shannon entropy for a list of commands.
54
55 Shannon entropy measures the "surprise" or information content in the distribution.
56 - Higher entropy = more uniform distribution across command types (more diverse)
57 - Lower entropy = some commands are much more frequent (more focused)
58 - Max entropy = log2(unique_commands) when all commands equally frequent
59
60 Args:
61 command_list: List of command strings (e.g., ['ls', 'cat', 'ls', 'grep'])
62
63 Returns:
64 Float entropy value (0 = single command type, higher = more diverse)
65 """
66 if not command_list:
67 return 0.0
68
69 # Count frequency of each command type
70 counter = Counter(command_list)
71 total = len(command_list)
72 entropy = 0.0
73
74 # Calculate Shannon entropy: -Σ(p * log2(p)) where p is probability of each command
75 for count in counter.values():
76 prob = count / total
77 entropy -= prob * math.log2(prob)
78
79 return entropy
80
81
82def extract_commands_from_trajectory(traj):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected